Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concave hull #427

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-lab</artifactId>
<version>1.17.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,4 @@ public static double pointToLinePerpendicular(Coordinate p,

return Math.abs(s) * Math.sqrt(len2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public double maximumDistance()
* The boundables are either composites or leaves.
* If either is composite, the distance is computed as the minimum distance
* between the bounds.
* If both are leaves, the distance is computed by {@link #itemDistance(ItemBoundable, ItemBoundable)}.
* If both are leaves, the distance is computed by {@link ItemDistance#distance(ItemBoundable, ItemBoundable)}.
*
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* using to query a single index tree,
* the distance metric is <i>anti-reflexive</i>.
* That is, if the two arguments are the same Geometry object,
* the distance returned is {@link Double.MAX_VALUE}.
* the distance returned is {@link Double#MAX_VALUE}.
*
* @author Martin Davis
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.locationtech.jts.geom.Coordinate;

import junit.textui.TestRunner;
import org.locationtech.jts.geom.Envelope;
import test.jts.GeometryTestCase;

public class DistanceTest extends GeometryTestCase {
Expand Down Expand Up @@ -44,4 +45,5 @@ public void testDistanceLineLineDisjointCollinear() {
new Coordinate(0,0), new Coordinate(9.9, 1.4),
new Coordinate(11.88, 1.68), new Coordinate(21.78, 3.08)), 0.000001);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
/*
* Copyright (c) 2019 Felix Obermaier.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.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-v10.html
* and the Eclipse Distribution License is available at
*
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.locationtech.jts.algorithm;

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;

/**
* Functions to compute squared distances between basic geometric structures.
* Squared distances are useful if only the relative value is of interest, i.e. is
* point {@code p1} closer to the point {@code p0} than {@code p2}.
*
* To compute the <i>squared distance</i> is faster than computing the real distance
* because there is no call to {@link Math#sqrt(double)} involved.
*
* @author Felix Obermaier
* @since 1.17
*
*/
public class DistanceSquared {

/**
* Computes the squared distance from a point {@code p0} to a point {@code p1}
*
* Note: NON-ROBUST!
*
* @param p0
* a point
* @param p1
* another point
*
* @return the squared distance from {@code p0} to {@code p1}
*/
public static double pointToPoint(Coordinate p0, Coordinate p1) {
double dx = p1.x - p0.x;
double dy = p1.y - p0.y;

return dx*dx + dy*dy;
}

/**
* Computes the squared distance from a point {@code p} to a line segment |{@code A}{@code B}|
*
* Note: NON-ROBUST!
*
* @param p
* the point to compute the distance for
* @param A
* point A of the segment AB
* @param B
* point B of the segment AB
*
* @return the squared distance from p to line segment AB
*/
public static double pointToSegment(Coordinate p, Coordinate A, Coordinate B) {

double x = A.x;
double y = A.y;
double dx = B.x - x;
double dy = B.y - y;

if (dx != 0 || dy != 0) {

double t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);

if (t > 1) {
x = B.x;
y = B.y;

} else if (t > 0) {
x += dx * t;
y += dy * t;
}
}

dx = p.x - x;
dy = p.y - y;

return dx * dx + dy * dy;
}

/**
* Computes the squared distance from a point to a sequence of line segments.
*
* @param p
* a point
* @param line
* a sequence of contiguous line segments defined by their vertices
*
* @return the minimum squared distance between the point and the line segments
*/
public static double pointToSegmentString(Coordinate p, Coordinate[] line)
{
if (line.length == 0)
throw new IllegalArgumentException(
"Line array must contain at least one vertex");
// this handles the case of length = 1
double minDistance = pointToPoint(p, line[0]);
for (int i = 0; i < line.length - 1; i++) {
double dist = pointToSegment(p, line[i], line[i + 1]);
if (dist < minDistance) {
minDistance = dist;
}
}
return minDistance;
}

/**
* Computes the squared distance from a line segment |{@code A}{@code B}| to
* a line segment |{@code C}{@code D}|
*
* Note: NON-ROBUST!
*
* @param A
* point A of the segment AB
* @param B
* point B of the segment AB
* @param C
* point C of the segment CD
* @param D
* point D of the segment CD
*/
public static double segmentToSegment(Coordinate A, Coordinate B, Coordinate C, Coordinate D) {
return segmentToSegment(A.x, A.y, B.x, B.y, C.x, C.y, D.x, D.y);
}

/**
* Computes the squared distance from a line segment |{@code A}{@code B}| to
* a line segment |{@code C}{@code D}|
*
* Note: NON-ROBUST!
*
* @param ax
* the x-ordinate of point A of the segment AB
* @param ay
* the y-ordinate of point A of the segment AB
* @param bx
* the x-ordinate of point B of the segment AB
* @param by
* the y-ordinate of point B of the segment AB
* @param cx
* the x-ordinate of point C of the segment CD
* @param cy
* the y-ordinate of point C of the segment CD
* @param dx
* the x-ordinate of point D of the segment CD
* @param dy
* the y-ordinate of point D of the segment CD

* Direct port of code provided by Dan Sunday
* <a href="http://geomalgorithms.com/a07-_distance.html"/>
*/
private static double segmentToSegment(double ax, double ay, double bx, double by,
double cx, double cy, double dx, double dy) {
double ux = bx - ax;
double uy = by - ay;
double vx = dx - cx;
double vy = dy - cy;
double wx = ax - cx;
double wy = ay - cy;
double a = ux * ux + uy * uy;
double b = ux * vx + uy * vy;
double c = vx * vx + vy * vy;
double d = ux * wx + uy * wy;
double e = vx * wx + vy * wy;
double D = a * c - b * b;

double sc, sN, tc, tN;
double sD = D;
double tD = D;

if (D == 0) {
sN = 0;
sD = 1;
tN = e;
tD = c;
} else {
sN = b * e - c * d;
tN = a * e - b * d;
if (sN < 0) {
sN = 0;
tN = e;
tD = c;
} else if (sN > sD) {
sN = sD;
tN = e + b;
tD = c;
}
}

if (tN < 0.0) {
tN = 0.0;
if (-d < 0.0) sN = 0.0;
else if (-d > a) sN = sD;
else {
sN = -d;
sD = a;
}
} else if (tN > tD) {
tN = tD;
if ((-d + b) < 0.0) sN = 0;
else if (-d + b > a) sN = sD;
else {
sN = -d + b;
sD = a;
}
}

sc = sN == 0 ? 0 : sN / sD;
tc = tN == 0 ? 0 : tN / tD;

double lcx = (1 - sc) * ax + sc * bx;
double lcy = (1 - sc) * ay + sc * by;
double lcx2 = (1 - tc) * cx + tc * dx;
double lcy2 = (1 - tc) * cy + tc * dy;
double ldx = lcx2 - lcx;
double ldy = lcy2 - lcy;

return ldx * ldx + ldy * ldy;
}

/**
* Computes the squared distance between the segment {@code A}{@code B} and the
* { @link Envelope } {@code bounds}
*
* Note: NON-ROBUST!
*
* @param A the starting point of the segment
* @param B the end point of the segment
* @param bounds the bounds
* @return the distance between AB and the envelope.
*/
public static double segmentToEnvelope(Coordinate A, Coordinate B, Envelope bounds) {
if (bounds.contains(A) || bounds.contains(B))
return 0;
double d1 = segmentToSegment(A.x, A.y, B.x, B.y, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMinY());
if (d1 == 0) return 0;
double d2 = segmentToSegment(A.x, A.y, B.x, B.y, bounds.getMinX(), bounds.getMinY(), bounds.getMinX(), bounds.getMaxY());
if (d2 == 0) return 0;
double d3 = segmentToSegment(A.x, A.y, B.x, B.y, bounds.getMaxX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY());
if (d3 == 0) return 0;
double d4 = segmentToSegment(A.x, A.y, B.x, B.y, bounds.getMinX(), bounds.getMaxY(), bounds.getMaxX(), bounds.getMaxY());
if (d4 == 0) return 0;

return Math.min(Math.min(d1, d2), Math.min(d3, d4));
}
}

This file was deleted.

Loading