forked from locationtech/jts
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CoveragePolygonValidator section optimization
- Loading branch information
Showing
3 changed files
with
137 additions
and
58 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
modules/core/src/main/java/org/locationtech/jts/coverage/CoveragePolygon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2022 Martin Davis. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* and Eclipse Distribution License v. 1.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
package org.locationtech.jts.coverage; | ||
|
||
import org.locationtech.jts.algorithm.locate.IndexedPointInAreaLocator; | ||
import org.locationtech.jts.algorithm.locate.PointOnGeometryLocator; | ||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.Envelope; | ||
import org.locationtech.jts.geom.Location; | ||
import org.locationtech.jts.geom.Polygon; | ||
|
||
class CoveragePolygon { | ||
|
||
private Polygon polygon; | ||
private Envelope polyEnv; | ||
IndexedPointInAreaLocator locator; | ||
|
||
public CoveragePolygon(Polygon poly) { | ||
this.polygon = poly; | ||
polyEnv = polygon.getEnvelopeInternal(); | ||
} | ||
|
||
public boolean intersects(Envelope env) { | ||
//-- test intersection explicitly to avoid expensive null check | ||
//return polyEnv.intersects(env); | ||
return ! (env.getMinX() > polyEnv.getMaxX() | ||
|| env.getMaxX() < polyEnv.getMinX() | ||
|| env.getMinY() > polyEnv.getMaxY() | ||
|| env.getMaxY() < polyEnv.getMinY()); | ||
} | ||
|
||
public boolean contains(Coordinate p) { | ||
//-- test intersection explicitly to avoid expensive null check | ||
if (! intersects(p)) | ||
return false; | ||
PointOnGeometryLocator pia = getLocator(); | ||
return Location.INTERIOR == pia.locate(p); | ||
} | ||
|
||
private boolean intersects(Coordinate p) { | ||
return ! (p.x > polyEnv.getMaxX() || | ||
p.x < polyEnv.getMinX() || | ||
p.y > polyEnv.getMaxY() || | ||
p.y < polyEnv.getMinY()); | ||
} | ||
|
||
private PointOnGeometryLocator getLocator() { | ||
if (locator == null) { | ||
locator = new IndexedPointInAreaLocator(polygon); | ||
} | ||
return locator; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters