| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.index.strtree; |
| 14 |
|
| 15 |
import org.locationtech.jts.util.Assert; |
| 16 |
|
| 17 |
/** |
| 18 |
* A contiguous portion of 1D-space. Used internally by SIRtree. |
| 19 |
* @see SIRtree |
| 20 |
* |
| 21 |
* @version 1.7 |
| 22 |
*/ |
| 23 |
public class Interval { |
| 24 |
|
| 25 |
public Interval(Interval other) { |
| 26 |
this(other.min, other.max); |
| 27 |
} |
| 28 |
|
| 29 |
public Interval(double min, double max) { |
| 30 |
Assert.isTrue(min <= max); |
| 31 |
this.min = min; |
| 32 |
this.max = max; |
| 33 |
} |
| 34 |
|
| 35 |
private double min; |
| 36 |
private double max; |
| 37 |
|
| 38 |
public double getCentre() { return (min+max)/2; } |
| 39 |
|
| 40 |
/** |
| 41 |
* @return this |
| 42 |
*/ |
| 43 |
public Interval expandToInclude(Interval other) { |
| 44 |
max = Math.max(max, other.max); |
| 45 |
min = Math.min(min, other.min); |
| 46 |
return this; |
| 47 |
} |
| 48 |
|
| 49 |
public boolean intersects(Interval other) { |
| 50 |
return !(other.min > max || other.max < min); |
| 51 |
} |
| 52 |
public boolean equals(Object o) { |
| 53 |
if (! (o instanceof Interval)) { return false; } |
| 54 |
Interval other = (Interval) o; |
| 55 |
return min == other.min && max == other.max; |
| 56 |
} |
| 57 |
} |
| 58 |
|