Class Interval

 1  
 2 /*
 3  * Copyright (c) 2016 Vivid Solutions.
 4  *
 5  * All rights reserved. This program and the accompanying materials
 6  * are made available under the terms of the Eclipse Public License 2.0
 7  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 9  * and the Eclipse Distribution License is available at
10  *
11  * http://www.eclipse.org/org/documents/edl-v10.php.
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