-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Martin Davis <[email protected]>
- Loading branch information
Showing
10 changed files
with
973 additions
and
7 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
modules/app/src/main/java/org/locationtech/jtstest/function/HullFunctions.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,83 @@ | ||
/* | ||
* Copyright (c) 2016 Vivid Solutions. | ||
* | ||
* 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.jtstest.function; | ||
|
||
import org.locationtech.jts.algorithm.hull.ConcaveHull; | ||
import org.locationtech.jts.algorithm.hull.PolygonHull; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jtstest.geomfunction.Metadata; | ||
|
||
public class HullFunctions { | ||
public static Geometry convexHull(Geometry g) { return g.convexHull(); } | ||
|
||
public static Geometry concaveHullByLen(Geometry geom, | ||
@Metadata(title="Length") | ||
double maxLen) { | ||
return ConcaveHull.concaveHullByLength(geom, maxLen); | ||
} | ||
|
||
public static Geometry concaveHullWithHolesByLen(Geometry geom, | ||
@Metadata(title="Length") | ||
double maxLen) { | ||
return ConcaveHull.concaveHullByLength(geom, maxLen, true); | ||
} | ||
|
||
public static Geometry concaveHullByLenRatio(Geometry geom, | ||
@Metadata(title="Length Ratio") | ||
double maxLen) { | ||
return ConcaveHull.concaveHullByLengthRatio(geom, maxLen); | ||
} | ||
|
||
public static Geometry concaveHullWithHolesByLenRatio(Geometry geom, | ||
@Metadata(title="Length Ratio") | ||
double maxLen) { | ||
return ConcaveHull.concaveHullByLengthRatio(geom, maxLen, true); | ||
} | ||
|
||
public static double concaveHullLenGuess(Geometry geom) { | ||
return ConcaveHull.uniformGridEdgeLength(geom); | ||
} | ||
|
||
/** | ||
* A concaveness measure defined in terms of the perimeter length | ||
* relative to the convex hull perimeter. | ||
* <pre> | ||
* C = ( P(geom) - P(CH) ) / P(CH) | ||
* </pre> | ||
* Concaveness values are >= 0. | ||
* A convex polygon has C = 0. | ||
* A higher concaveness indicates a more concave polygon. | ||
* <p> | ||
* Originally defined by Park & Oh, 2012. | ||
* | ||
* @param geom a polygonal geometry | ||
* @return the concaveness measure of the geometry | ||
*/ | ||
public static double concaveness(Geometry geom) { | ||
double convexLen = geom.convexHull().getLength(); | ||
return (geom.getLength() - convexLen) / convexLen; | ||
} | ||
|
||
public static Geometry polygonHull(Geometry geom, | ||
@Metadata(title="Vertex Frac") | ||
double vertexFrac) { | ||
return PolygonHull.hull(geom, vertexFrac); | ||
} | ||
|
||
public static Geometry polygonHullByArea(Geometry geom, | ||
@Metadata(title="Area Delta Ratio") | ||
double areaFrac) { | ||
return PolygonHull.hullByAreaDelta(geom, areaFrac); | ||
} | ||
|
||
|
||
} |
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
100 changes: 100 additions & 0 deletions
100
modules/core/src/main/java/org/locationtech/jts/algorithm/hull/LinkedRing.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,100 @@ | ||
/* | ||
* Copyright (c) 2021 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.algorithm.hull; | ||
|
||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.CoordinateList; | ||
|
||
class LinkedRing { | ||
|
||
private static final int NO_COORD_INDEX = -1; | ||
|
||
private final Coordinate[] coord; | ||
private int[] next = null; | ||
private int[] prev = null; | ||
private int size; | ||
|
||
public LinkedRing(Coordinate[] pts) { | ||
coord = pts; | ||
size = pts.length - 1; | ||
next = createNextLinks(size); | ||
prev = createPrevLinks(size); | ||
} | ||
|
||
private static int[] createNextLinks(int size) { | ||
int[] next = new int[size]; | ||
for (int i = 0; i < size; i++) { | ||
next[i] = i + 1; | ||
} | ||
next[size - 1] = 0; | ||
return next; | ||
} | ||
|
||
private static int[] createPrevLinks(int size) { | ||
int[] prev = new int[size]; | ||
for (int i = 0; i < size; i++) { | ||
prev[i] = i - 1; | ||
} | ||
prev[0] = size - 1; | ||
return prev; | ||
} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
|
||
public int next(int i) { | ||
return next[i]; | ||
} | ||
|
||
public int prev(int i) { | ||
return prev[i]; | ||
} | ||
|
||
public Coordinate getCoordinate(int index) { | ||
return coord[index]; | ||
} | ||
|
||
public Coordinate prevCoordinate(int index) { | ||
return coord[prev(index)]; | ||
} | ||
|
||
public Coordinate nextCoordinate(int index) { | ||
return coord[next(index)]; | ||
} | ||
|
||
public boolean hasCoordinate(int index) { | ||
return index >= 0 && index < prev.length | ||
&& prev[index] != NO_COORD_INDEX; | ||
} | ||
|
||
public void remove(int index) { | ||
int iprev = prev[index]; | ||
int inext = next[index]; | ||
next[iprev] = inext; | ||
prev[inext] = iprev; | ||
prev[index] = NO_COORD_INDEX; | ||
next[index] = NO_COORD_INDEX; | ||
size--; | ||
} | ||
|
||
public Coordinate[] getCoordinates() { | ||
CoordinateList coords = new CoordinateList(); | ||
for (int i = 0; i < coord.length - 1; i++) { | ||
if (prev[i] != NO_COORD_INDEX) { | ||
coords.add(coord[i].copy(), false); | ||
} | ||
} | ||
coords.closeRing(); | ||
return coords.toCoordinateArray(); | ||
} | ||
} |
Oops, something went wrong.