Class GeometryGraphOperation

 1  
 2  
 3 /*
 4  * Copyright (c) 2016 Vivid Solutions.
 5  *
 6  * All rights reserved. This program and the accompanying materials
 7  * are made available under the terms of the Eclipse Public License 2.0
 8  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 9  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
10  * and the Eclipse Distribution License is available at
11  *
12  * http://www.eclipse.org/org/documents/edl-v10.php.
13  */
14 package org.locationtech.jts.operation;
15  
16 import org.locationtech.jts.algorithm.BoundaryNodeRule;
17 import org.locationtech.jts.algorithm.LineIntersector;
18 import org.locationtech.jts.algorithm.RobustLineIntersector;
19 import org.locationtech.jts.geom.Geometry;
20 import org.locationtech.jts.geom.PrecisionModel;
21 import org.locationtech.jts.geomgraph.GeometryGraph;
22  
23 /**
24  * The base class for operations that require {@link GeometryGraph}s.
25  *
26  * @version 1.7
27  */
28 public class GeometryGraphOperation
29 {
30   protected final LineIntersector li = new RobustLineIntersector();
31   protected PrecisionModel resultPrecisionModel;
32  
33   /**
34    * The operation args into an array so they can be accessed by index
35    */
36   protected GeometryGraph[] arg;  // the arg(s) of the operation
37  
38   public GeometryGraphOperation(Geometry g0, Geometry g1)
39   {
40     this(g0, g1,
41          BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE
42 //         BoundaryNodeRule.ENDPOINT_BOUNDARY_RULE
43          );
44   }
45  
46   public GeometryGraphOperation(Geometry g0, Geometry g1, BoundaryNodeRule boundaryNodeRule)
47   {
48     // use the most precise model for the result
49     if (g0.getPrecisionModel().compareTo(g1.getPrecisionModel()) >= 0)
50       setComputationPrecision(g0.getPrecisionModel());
51     else
52       setComputationPrecision(g1.getPrecisionModel());
53  
54     arg = new GeometryGraph[2];
55     arg[0] = new GeometryGraph(0, g0, boundaryNodeRule);
56     arg[1] = new GeometryGraph(1, g1, boundaryNodeRule);
57   }
58  
59   public GeometryGraphOperation(Geometry g0) {
60     setComputationPrecision(g0.getPrecisionModel());
61  
62     arg = new GeometryGraph[1];
63     arg[0] = new GeometryGraph(0, g0);;
64   }
65  
66   public Geometry getArgGeometry(int i) { return arg[i].getGeometry(); }
67  
68   protected void setComputationPrecision(PrecisionModel pm)
69   {
70     resultPrecisionModel = pm;
71     li.setPrecisionModel(resultPrecisionModel);
72   }
73 }
74