Java Code Examples for com.vividsolutions.jts.geom.Envelope#intersects()
The following examples show how to use
com.vividsolutions.jts.geom.Envelope#intersects() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileExecuter.java From gama with GNU General Public License v3.0 | 6 votes |
@Override Rectangle2D executeOn(final IScope scope, final IGraphics g, final DrawingData data) throws GamaRuntimeException { final GamaFile file = constImg == null ? (GamaFile) item.value(scope) : constImg; if (file == null) { return null; } final FileDrawingAttributes attributes = computeAttributes(scope, data, file instanceof GamaImageFile, file instanceof GamaGisFile, g.is2D()); // XXX EXPERIMENTAL See Issue #1521 if (GamaPreferences.Displays.DISPLAY_ONLY_VISIBLE.getValue() && /* !GAMA.isInHeadLessMode() */ !scope.getExperiment().isHeadless()) { final Scaling3D size = attributes.getSize(); if (size != null) { // if a size is provided final Envelope3D expected = Envelope3D.of((ILocation) attributes.getLocation()); expected.expandBy(size.getX() / 2, size.getY() / 2); final Envelope visible = g.getVisibleRegion(); if (visible != null) { if (!visible.intersects(expected)) { return null; } } } // XXX EXPERIMENTAL } return g.drawFile(file, attributes); }
Example 2
Source File: QuadtreeCorrectTest.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private List getOverlapping(List items, Envelope searchEnv) { List result = new ArrayList(); for (int i = 0; i < items.size(); i++) { Envelope env = (Envelope) items.get(i); if (env.intersects(searchEnv)) result.add(env); } return result; }
Example 3
Source File: EnvelopeList.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public List query(Envelope searchEnv) { List result = new ArrayList(); for (Iterator i = envList.iterator(); i.hasNext(); ) { Envelope env = (Envelope) i.next(); if (env.intersects(searchEnv)) result.add(env); } return result; }
Example 4
Source File: ShapeExecuter.java From gama with GNU General Public License v3.0 | 4 votes |
@Override Rectangle2D executeOn(final IScope scope, final IGraphics gr, final DrawingData data) throws GamaRuntimeException { final IShape shape = constantShape == null ? asGeometry(scope, item.value(scope), false) : constantShape; if (shape == null) { return null; } final DrawingAttributes attributes = computeAttributes(scope, data, shape); Geometry gg = shape.getInnerGeometry(); if (gg == null) { return null; } final ICoordinates ic = getContourCoordinates(gg); ic.ensureClockwiseness(); // If the graphics is 2D, we pre-translate and pre-rotate the geometry if (gr.is2D()) { ic.getCenter(center); rotate(gg, center, attributes.getRotation()); final GamaPoint location = attributes.getLocation(); if (location != null) { if (gg.getNumPoints() == 1) { gg = GEOMETRY_FACTORY.createPoint(location); } else { translate(gg, center, location); } } gg.geometryChanged(); } if (hasArrows) { final Geometry withArrows = addArrows(scope, gg, !attributes.isEmpty()); if (withArrows != gg) { gg = withArrows; attributes.setType(IShape.Type.NULL); } } final Geometry withTorus = addToroidalParts(scope, gg); if (withTorus != gg) { gg = withTorus; attributes.setType(IShape.Type.NULL); } // XXX EXPERIMENTAL See Issue #1521 if (GamaPreferences.Displays.DISPLAY_ONLY_VISIBLE.getValue() && !scope.getExperiment().isHeadless()) { final Envelope3D e = shape.getEnvelope(); try { final Envelope visible = gr.getVisibleRegion(); if (visible != null) { if (!visible.intersects(e)) { return null; } // XXX EXPERIMENTAL } } finally { e.dispose(); } } // The textures are computed as well in advance addTextures(scope, attributes); // And we ask the IGraphics object to draw the shape return gr.drawShape(gg, attributes); }
Example 5
Source File: CGAlgorithms.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
/** * Computes the distance from a line segment AB to a line segment CD * * Note: NON-ROBUST! * * @param A * a point of one line * @param B * the second point of (must be different to A) * @param C * one point of the line * @param D * another point of the line (must be different to A) */ public static double distanceLineLine(Coordinate A, Coordinate B, Coordinate C, Coordinate D) { // check for zero-length segments if (A.equals(B)) return distancePointLine(A, C, D); if (C.equals(D)) return distancePointLine(D, A, B); // AB and CD are line segments /* * from comp.graphics.algo * * Solving the above for r and s yields * * (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy) * r = ----------------------------- (eqn 1) * (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx) * * (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay) * s = ----------------------------- (eqn 2) * (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx) * * Let P be the position vector of the * intersection point, then * P=A+r(B-A) or * Px=Ax+r(Bx-Ax) * Py=Ay+r(By-Ay) * By examining the values of r & s, you can also determine some other limiting * conditions: * If 0<=r<=1 & 0<=s<=1, intersection exists * r<0 or r>1 or s<0 or s>1 line segments do not intersect * If the denominator in eqn 1 is zero, AB & CD are parallel * If the numerator in eqn 1 is also zero, AB & CD are collinear. */ boolean noIntersection = false; if (! Envelope.intersects(A, B, C, D)) { noIntersection = true; } else { double denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x); if (denom == 0) { noIntersection = true; } else { double r_num = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y); double s_num = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y); double s = s_num / denom; double r = r_num / denom; if ((r < 0) || (r > 1) || (s < 0) || (s > 1)) { noIntersection = true; } } } if (noIntersection) { return MathUtil.min( distancePointLine(A, C, D), distancePointLine(B, C, D), distancePointLine(C, A, B), distancePointLine(D, A, B)); } // segments intersect return 0.0; }