Class SweepLineSegment

 1  
 2  
 3  
 4 /*
 5  * Copyright (c) 2016 Vivid Solutions.
 6  *
 7  * All rights reserved. This program and the accompanying materials
 8  * are made available under the terms of the Eclipse Public License 2.0
 9  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
10  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
11  * and the Eclipse Distribution License is available at
12  *
13  * http://www.eclipse.org/org/documents/edl-v10.php.
14  */
15 package org.locationtech.jts.geomgraph.index;
16  
17 import org.locationtech.jts.geom.Coordinate;
18 import org.locationtech.jts.geomgraph.Edge;
19  
20  
21 /**
22  * @version 1.7
23  */
24 public class SweepLineSegment {
25  
26   Edge edge;
27   Coordinate[] pts;
28   int ptIndex;
29  
30   public SweepLineSegment(Edge edge,  int ptIndex) {
31     this.edge = edge;
32     this.ptIndex = ptIndex;
33     pts = edge.getCoordinates();
34   }
35  
36   public double getMinX()
37   {
38     double x1 = pts[ptIndex].x;
39     double x2 = pts[ptIndex + 1].x;
40     return x1 < x2 ? x1 : x2;
41   }
42   public double getMaxX()
43   {
44     double x1 = pts[ptIndex].x;
45     double x2 = pts[ptIndex + 1].x;
46     return x1 > x2 ? x1 : x2;
47   }
48   public void computeIntersections(SweepLineSegment ss, SegmentIntersector si)
49   {
50     si.addIntersections(edge, ptIndex, ss.edge, ss.ptIndex);
51   }
52  
53 }
54