Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 1c5e5874 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

construct a new module called geometry and extracting the classes from the utils module.

parent 35ebbaa9
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>vadere</artifactId>
<groupId>org.vadere</groupId>
<version>0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>VadereGeometry</name>
<artifactId>geometry</artifactId>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>tests</testSourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>testResources</directory>
</testResource>
<testResource>
<directory>tests</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<!-- Use JaCoCo's Java agents to record coverage data by using on-the-fly class file instrumentation. -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<output>file</output>
<destFile>${project.build.directory}/coverage-data/jacoco-unit-tests.coverage</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- Use JaCoCo agent output to create coverage reports in CSV, HTML and XML format. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-data/jacoco-unit-tests.coverage</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/coverage-reports</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Maven Surefire is used to execute unit tests. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<enableAssertions>true</enableAssertions>
<excludes>
<exclude></exclude>
</excludes>
<failIfNoTests>false</failIfNoTests>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>com.googlecode.mavennatives</groupId>
<artifactId>maven-nativedependencies-plugin</artifactId>
<version>0.0.5</version>
<executions>
<execution>
<id>unpacknatives</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- generated by lwjgl -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<lwjgl.version>3.1.2</lwjgl.version>
</properties>
<!-- end generated by lwjgl -->
<dependencies>
<!-- utility methods i.e. StopWatch -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r05</version>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
<!-- generated by lwjgl -->
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opencl</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
<classifier>${lwjgl.natives}</classifier>
<scope>runtime</scope>
</dependency>
</dependencies>
<!-- end generated by lwjgl -->
<profiles>
<profile>
<id>lwjgl-natives-linux</id>
<activation>
<os><family>unix</family></os>
</activation>
<properties>
<lwjgl.natives>natives-linux</lwjgl.natives>
</properties>
</profile>
<profile>
<id>lwjgl-natives-macos</id>
<activation>
<os><family>mac</family></os>
</activation>
<properties>
<lwjgl.natives>natives-macos</lwjgl.natives>
</properties>
</profile>
<profile>
<id>lwjgl-natives-windows</id>
<activation>
<os><family>windows</family></os>
</activation>
<properties>
<lwjgl.natives>natives-windows</lwjgl.natives>
</properties>
</profile>
</profiles>
</project>
\ No newline at end of file
package org.vadere.util.geometry;
package org.vadere.geometry;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.geometry.shapes.VPoint;
/**
* VPoint with implementation of the comparable interface.
......@@ -30,8 +30,8 @@ public class ComparablePoint extends VPoint implements
*/
@Override
public int compareTo(ComparablePoint p) {
if (Math.abs(this.x - p.x) < GeometryUtils.DOUBLE_EPS) {
if (Math.abs(this.y - p.y) < GeometryUtils.DOUBLE_EPS) {
if (Math.abs(this.x - p.x) < Utils.DOUBLE_EPS) {
if (Math.abs(this.y - p.y) < Utils.DOUBLE_EPS) {
return 0;
} else {
if (this.y > p.y) {
......
package org.vadere.util.geometry;
package org.vadere.geometry;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VLine;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.geometry.shapes.IPoint;
import org.vadere.geometry.shapes.VLine;
import org.vadere.geometry.shapes.VPoint;
import java.awt.geom.Line2D;
import java.util.Iterator;
......
package org.vadere.util.geometry;
package org.vadere.geometry;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VLine;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.geometry.mesh.inter.IPointConstructor;
import org.vadere.geometry.shapes.IPoint;
import org.vadere.geometry.shapes.VLine;
import org.vadere.geometry.shapes.VShape;
import org.vadere.geometry.mesh.inter.IPointConstructor;
import java.awt.geom.PathIterator;
import java.util.Collection;
......
package org.vadere.util.math;
package org.vadere.geometry;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.geometry.mesh.triangulation.adaptive.DistanceFunction;
import org.vadere.geometry.shapes.IPoint;
import org.vadere.geometry.shapes.VRectangle;
import org.vadere.geometry.shapes.VShape;
import org.vadere.geometry.mesh.triangulation.adaptive.DistanceFunction;
import java.util.ArrayList;
import java.util.Collection;
......
package org.vadere.util.geometry;
package org.vadere.geometry;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.geometry.shapes.VPoint;
public class IndexedPoint extends VPoint {
/**
......
package org.vadere.util.geometry;
package org.vadere.geometry;
public enum ShapeType {
CIRCLE, POLYGON, RECTANGLE, RING
......
package org.vadere.util.math;
package org.vadere.geometry;
import org.apache.commons.lang3.tuple.Pair;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import org.vadere.geometry.shapes.IPoint;
import org.vadere.geometry.shapes.VPoint;
import org.vadere.geometry.shapes.VRectangle;
/**
* @author Benedikt Zoennchen
......
package org.vadere.util.geometry;
package org.vadere.geometry;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VLine;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.mesh.inter.IPointConstructor;
import org.vadere.geometry.shapes.IPoint;
import org.vadere.geometry.shapes.VLine;
import org.vadere.geometry.shapes.VPoint;
import org.vadere.geometry.mesh.inter.IPointConstructor;
import java.util.ArrayList;
import java.util.Iterator;
......
package org.vadere.geometry;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Random;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.vadere.geometry.shapes.IPoint;
import org.vadere.geometry.shapes.VCircle;
import org.vadere.geometry.shapes.VLine;
import org.vadere.geometry.shapes.VPoint;
import org.vadere.geometry.shapes.VPolygon;
import org.vadere.geometry.shapes.VRectangle;
import org.vadere.geometry.shapes.VShape;
import org.vadere.geometry.shapes.VTriangle;
import static org.vadere.geometry.Utils.Orientation.CCW;
import static org.vadere.geometry.Utils.Orientation.COLLINEAR;
import static org.vadere.geometry.Utils.Orientation.CW;
public class Utils {
enum Orientation {
CCW,
CW,
COLLINEAR;
}
/**
* Constant for comparison of double values. Everything below this is
* considered equal.
*/
public static final double DOUBLE_EPS = 1e-8;
public static final Logger log = LogManager.getLogger(Utils.class);
/**
* Interpolates between start and end with the given factor.
*/
public static VPoint interpolate(VPoint start, VPoint end, double factor) {
VPoint result = new VPoint(start.x + factor * (end.x - start.x),
start.y + factor * (end.y - start.y));
return result;
}
public static double derterminant2D(double x1, double y1, double x2, double y2) {
return x1 * y2 - y1 * x2;
}
//http://mathworld.wolfram.com/Line-LineIntersection.html
public static VPoint intersectionPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
double a = derterminant2D(x1, x2, y1, y2);
double b = derterminant2D(x3, x4, y3, y4);
double c = derterminant2D(x1-x2, x3 - x4, y1 - y2, y3 - y4);
double x = derterminant2D(a, b, x1 - x2, x3 - x4) / c;
double y = derterminant2D(a, b, y1 - y2, y3 - y4) / c;
return new VPoint(x,y);
}
public static VPoint getCentroid(@NotNull final List<? extends IPoint> polygon){
double area = areaOfPolygon(polygon);
double xValue = 0;
double yValue = 0;
assert polygon.size() > 2;
int j = 0;
for (int i = 0; i < polygon.size(); i++) {
if(i < polygon.size() - 1) {
j = i + 1;
}
else {
j = 0;
}
xValue += (polygon.get(i).getX() + polygon.get(j).getX())
* (polygon.get(i).getX() * polygon.get(j).getY()
- polygon.get(i).getY() * polygon.get(j).getX());
yValue += (polygon.get(i).getY() + polygon.get(j).getY())
* (polygon.get(i).getX() * polygon.get(j).getY()
- polygon.get(i).getY() * polygon.get(j).getX());
}
xValue /= (6 * area);
yValue /= (6 * area);
if(xValue == Double.NaN || yValue == Double.NaN || area == 0 || area == Double.NaN) {
throw new IllegalArgumentException("invalid point list");
}
return new VPoint(xValue, yValue);
}
public static boolean collectionContains(
Collection<? extends VShape> collection, VPoint point) {
for (VShape shape : collection) {
if (shape.contains(point)) {
return true;
}
}
return false;
}
public static VPoint getCircumcenter(final IPoint p1, final IPoint p2, final IPoint p3) {
double d = 2 * (p1.getX() * (p2.getY() - p3.getY()) + p2.getX() * (p3.getY() - p1.getY()) + p3.getX() * (p1.getY() - p2.getY()));
double x = ((p1.getX() * p1.getX() + p1.getY() * p1.getY()) * (p2.getY() - p3.getY())
+ (p2.getX() * p2.getX() + p2.getY() * p2.getY()) * (p3.getY() - p1.getY())
+ (p3.getX() * p3.getX() + p3.getY() * p3.getY()) * (p1.getY() - p2.getY())) / d;
double y = ((p1.getX() * p1.getX() + p1.getY() * p1.getY()) * (p3.getX() - p2.getX())
+ (p2.getX() * p2.getX() + p2.getY() * p2.getY()) * (p1.getX() - p3.getX())
+ (p3.getX() * p3.getX() + p3.getY() * p3.getY()) * (p2.getX() - p1.getX())) / d;
return new VPoint(x,y);
}
public static boolean isInCircumscribedCycle(final IPoint p1, final IPoint p2, final IPoint p3, final IPoint point) {
VPoint circumcenter = getCircumcenter(p1, p2, p3);
return circumcenter.distance(point) < circumcenter.distance(p1);
}
/**
* Generates a set of points which are positioned inside a disc segment. The points are placed equidistant on one or multiple circles
* with the center at the center of the disc and the radius <= the radius of the disc.
*
* @param random a random number generator which will only be used if varyDirection is true.
* @param varyDirection if true the generated points will be rotated by a random offset
* @param circle the circle defining the disc (containing the points)
* @param numberOfCircles the number of circles
* @param numberOfPointsOfLargestCircle the number of points of the most outer circle
* @param anchorAngle start angle of the segment
* @param angle anchorAngle + angle = end angle of the segment
* @return a set of points which are positioned inside a disc segment
*/
public static List<VPoint> getDiscDiscretizationPoints(
@NotNull final Random random,
final boolean varyDirection,
@NotNull final VCircle circle,
final int numberOfCircles,
final int numberOfPointsOfLargestCircle,
final double anchorAngle,
final double angle) {
double randOffset = varyDirection ? random.nextDouble() : 0;
List<VPoint> reachablePositions = new ArrayList<>();
// iterate through all circles
for (int j = 1; j <= numberOfCircles; j++) {
double circleOfGrid = circle.getRadius() * j / numberOfCircles;
int numberOfGridPoints = (int) Math.ceil(circleOfGrid / circle.getRadius() * numberOfPointsOfLargestCircle);
// reduce number of grid points proportional to the constraint of direction
if (angle < 2 * Math.PI) {
numberOfGridPoints = (int) Math.ceil(numberOfGridPoints * angle / (2 * Math.PI));
}
double angleDelta = angle / numberOfGridPoints;
// iterate through all angles and compute absolute positions of grid points
for (int i = 0; i < numberOfGridPoints; i++) {
double x = circleOfGrid * Math.cos(anchorAngle + angleDelta * (randOffset + i)) + circle.getCenter().getX();
double y = circleOfGrid * Math.sin(anchorAngle + angleDelta * (randOffset + i)) + circle.getCenter().getY();
VPoint tmpPos = new VPoint(x, y);
reachablePositions.add(tmpPos);
}
}
return reachablePositions;
}
/**
* Computes the point on the line segment that is closest to the given point
* point. from:
* http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line
*
* @param point
* the point to which the counterpart should be computed
* @param line
* line representing the segment
* @return the point on the line that is closest to p
*/
public static VPoint closestToSegment(VLine line, IPoint point) {
if (new VPoint((Point2D.Double) line.getP1()).equals(point)) {
return new VPoint(line.x1, line.y1);
}
VPoint a2p = new VPoint(point.getX() - line.x1, point.getY() - line.y1);
VPoint a2b = new VPoint(line.x2 - line.x1, line.y2 - line.y1);
double distAB = a2b.x * a2b.x + a2b.y * a2b.y;
double a2p_dot_a2b = a2p.x * a2b.x + a2p.y * a2b.y;
// normalize t to [0,1] to stay on the line segment
double t = Math.min(1, Math.max(0, a2p_dot_a2b / distAB));
return new VPoint(line.x1 + a2b.x * t, line.y1 + a2b.y * t);
}
/**
* Computes area (it maybe a negative area) of the parallelogram defined by p, q, r.
*
* @param pX x-coordinate of p
* @param pY y-coordinate of p
* @param qX x-coordinate of q
* @param qY y-coordinate of q
* @param rX x-coordinate of r
* @param rY y-coordinate of r
* @return
*/
public static double ccw(final double qX, final double qY, final double pX, final double pY, final double rX, final double rY) {
return -((qX - pX) * (rY - pY) - (rX - pX) * (qY - pY));
}
/**
* Computes area (it maybe a negative area) of the parallelogram defined by p, q, r.
*
* @param pX x-coordinate of p
* @param pY y-coordinate of p
* @param qX x-coordinate of q
* @param qY y-coordinate of q
* @param rX x-coordinate of r
* @param rY y-coordinate of r
* @return
*/
public static double ccwRobust(final double qX, final double qY, final double pX, final double pY, final double rX, final double rY) {
double result = -((qX - pX) * (rY - pY) - (rX - pX) * (qY - pY));
if(Math.abs(result) <= DOUBLE_EPS) {
return 0.0;
}
else {
return result;
}
}
/**
*
* @param x1
* @param y1
* @param x2
* @param y2
* @param xq
* @param yq
* @return
*/
public static boolean isRightOf(final double x1, final double y1, final double x2, final double y2, final double xq, final double yq) {
return isCW(x1, y1, x2, y2, xq, yq);
}
/**
* Returns true if q is right of the oriented-line defined by (p1, p2).
* @param p1
* @param p2
* @param q
* @return true if q is right of the oriented-line defined by (p1, p2), false otherwise
*/
public static boolean isRightOf(final IPoint p1, final IPoint p2, final IPoint q) {
return isRightOf(p1, p2, q.getX(), q.getY());
}
/**
* Returns true if q is left of the oriented-line defined by (p1, p2).
*
* @param p1
* @param p2
* @param q
* @return true if q is left of the oriented-line defined by (p1, p2), false otherwise
*/
public static boolean isLeftOf(final IPoint p1, final IPoint p2, final IPoint q) {
return isLeftOf(p1, p2, q.getX(), q.getY());
}
/**
*
* @param p1
* @param p2
* @param x
* @param y
* @return
*/