2 * Description: provide a bound, and the corresponding operations
4 * Author Create/Modi Note
5 * Xiaofeng Xie Oct. 9, 2002
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * Please acknowledge the author(s) if you use this code in any way.
20 package net
.adaptivebox
.global
;
22 public class BasicBound
{
23 public static final double MINDOUBLE
= -1e308
;
24 public static final double MAXDOUBLE
= 1e308
;
26 public double minValue
= MINDOUBLE
;
27 public double maxValue
= MAXDOUBLE
;
32 public BasicBound(double min
, double max
) {
33 minValue
= Math
.min(min
, max
);
34 maxValue
= Math
.max(min
, max
);
37 public double getLength() {
38 return Math
.abs(maxValue
- minValue
);
41 public double boundAdjust(double value
) {
42 if (value
> maxValue
) {
44 } else if (value
< minValue
) {
50 public double annulusAdjust(double value
) {
51 if (value
> maxValue
) {
52 double extendsLen
= (value
- maxValue
) % getLength();
53 value
= minValue
+ extendsLen
;
54 } else if (value
< minValue
) {
55 double extendsLen
= (minValue
- value
) % getLength();
56 value
= maxValue
- extendsLen
;
61 public double getRandomValue() {
62 return RandomGenerator
.doubleRangeRandom(minValue
, maxValue
);