Commit 81be0b1d authored by Riegel's avatar Riegel
Browse files

Merge branch 'dev_GUI' into 'dev'

Open source release of CityDoctorGUI and other extensions.

See merge request !6
parents 12d96d95 5a4d0a74
Pipeline #10056 passed with stage
in 1 minute and 6 seconds
......@@ -29,7 +29,7 @@ import org.xml.sax.SAXParseException;
public class GMLValidationHandler implements ErrorHandler {
private static final Logger logger = LogManager.getLogger(GMLValidationHandler.class);
private List<String> messages = new ArrayList<>();
private final List<String> messages = new ArrayList<>();
@Override
public void error(SAXParseException exception) {
......
......@@ -58,11 +58,11 @@ import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
public class SurfaceMapper extends ObjectWalker {
private List<BoundarySurface> surfaces = new ArrayList<>();
private Map<String, ConcretePolygon> polygonMap;
private List<ResolvableReference> references;
private Map<Vertex, Vertex> vertexMap;
private ParserConfiguration config;
private final List<BoundarySurface> surfaces = new ArrayList<>();
private final Map<String, ConcretePolygon> polygonMap;
private final List<ResolvableReference> references;
private final Map<Vertex, Vertex> vertexMap;
private final ParserConfiguration config;
public SurfaceMapper(Map<String, ConcretePolygon> polygonMap, List<ResolvableReference> references,
Map<Vertex, Vertex> vertexMap, ParserConfiguration config) {
......
......@@ -20,33 +20,9 @@ package de.hft.stuttgart.citydoctor2.math;
/**
* Result of a distance calculation between two points
*
* @author Matthias Betz
*
* @author Matthias Betz
*/
public class DistanceResult {
private Vector3d point1;
private Vector3d point2;
private double distance;
public DistanceResult(Vector3d point1, Vector3d point2, double distance) {
super();
this.point1 = point1;
this.point2 = point2;
this.distance = distance;
}
public Vector3d getPoint1() {
return point1;
}
public Vector3d getPoint2() {
return point2;
}
public double getDistance() {
return distance;
}
public record DistanceResult(Vector3d point1, Vector3d point2, double distance) {
}
......@@ -29,8 +29,8 @@ public class Edge2d {
private static final double EPSILON = 0.0000001;
private static final double ONE_MINUS_EPSILON = 1 - EPSILON;
private ProjectedVector2d a;
private ProjectedVector2d b;
private final ProjectedVector2d a;
private final ProjectedVector2d b;
public Edge2d(ProjectedVector2d a, ProjectedVector2d b) {
this.a = a;
......@@ -150,11 +150,8 @@ public class Edge2d {
} else if (!a.equals(other.a))
return false;
if (b == null) {
if (other.b != null)
return false;
} else if (!b.equals(other.b))
return false;
return true;
}
return other.b == null;
} else return b.equals(other.b);
}
}
......@@ -20,31 +20,14 @@ package de.hft.stuttgart.citydoctor2.math;
/**
* Result of an intersection calculation
*
* @author Matthias Betz
*
* @author Matthias Betz
*/
public class IntersectionPoint2d {
private Line2d line;
private double scalar;
public IntersectionPoint2d(Line2d line, double scalar) {
super();
this.line = line;
this.scalar = scalar;
}
public record IntersectionPoint2d(Line2d line, double scalar) {
public Vector2d getIntersectionPoint() {
return line.getPoint().plus(line.getDirection().mult(scalar));
}
public Line2d getLine() {
return line;
return line.point().plus(line.direction().mult(scalar));
}
public double getScalar() {
return scalar;
}
}
......@@ -24,22 +24,6 @@ package de.hft.stuttgart.citydoctor2.math;
* @author Matthias Betz
*
*/
public class Line2d {
private Vector2d p;
private Vector2d dir;
public Line2d(Vector2d p, Vector2d dir) {
this.p = p;
this.dir = dir;
}
public Vector2d getPoint() {
return p;
}
public Vector2d getDirection() {
return dir;
}
public record Line2d(Vector2d point, Vector2d direction) {
}
......@@ -20,37 +20,13 @@ package de.hft.stuttgart.citydoctor2.math;
/**
* A line described by a point and a direction
*
* @author Matthias Betz
*
* @author Matthias Betz
*/
public class Line3d {
public record Line3d(Vector3d point, Vector3d direction) {
public static final double EPSILON = 0.00001;
private Vector3d point;
private Vector3d direction;
public Line3d(Vector3d point, Vector3d direction) {
super();
this.point = point;
this.direction = direction;
}
/**
* @return the point
*/
public Vector3d getPoint() {
return point;
}
/**
* @return the direction
*/
public Vector3d getDirection() {
return direction;
}
public double distanceToPoint(Vector3d v) {
double x = v.getX() - point.getX();
double y = v.getY() - point.getY();
......
......@@ -28,7 +28,7 @@ import java.util.Arrays;
*/
public class Matrix3x3d {
private double[][] values;
private final double[][] values;
/**
* Identity matrix
......@@ -123,10 +123,9 @@ public class Matrix3x3d {
*/
public Matrix3x3d transpose() {
Matrix3x3d x = new Matrix3x3d();
double[][] copyValues = x.values;
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
copyValues[j][i] = values[i][j];
x.values[j][i] = values[i][j];
}
}
return x;
......
......@@ -32,7 +32,7 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
*/
public class MovedRing {
private List<Vector3d> vertices;
private final List<Vector3d> vertices;
private LinearRing original;
public static MovedRing ofRing(LinearRing ring, Vector3d movedBy) {
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.math;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
......@@ -35,13 +36,14 @@ import de.hft.stuttgart.citydoctor2.math.PlaneSegmentIntersection.Type;
*/
public class Plane implements Serializable {
@Serial
private static final long serialVersionUID = 1602547402497943364L;
private static final double EPSILON = 0.0001;
private UnitVector3d normal;
private Vector3d point;
private double d;
private final UnitVector3d normal;
private final Vector3d point;
private final double d;
/**
* Constructs a new plane from a normal vector and a reference point.
......@@ -51,12 +53,14 @@ public class Plane implements Serializable {
*/
public Plane(Vector3d normal, Vector3d p) {
point = p;
this.normal = normal.normalize();
d = this.normal.dot(point);
if (d < 0) {
this.normal = this.normal.invert();
d = -d;
UnitVector3d normalVector = normal.normalize();
double dot = normalVector.dot(point);
if (dot < 0) {
normalVector = normalVector.invert();
dot = -dot;
}
this.d = dot;
this.normal = normalVector;
}
public PlaneSegmentIntersection intersects(Segment3d s) {
......@@ -89,9 +93,7 @@ public class Plane implements Serializable {
// intersection in segment
// calculate intersection point
Vector3d intersection = s.getPointA().plus(dir.mult(si));
PlaneSegmentIntersection psi = new PlaneSegmentIntersection(Type.INTERSECTION_POINT);
psi.setPoint(intersection);
return psi;
return new PlaneSegmentIntersection(Type.INTERSECTION_POINT, intersection);
}
/**
......
......@@ -30,21 +30,28 @@ public class PlaneSegmentIntersection {
NO_INTERSECTION, IN_PLANE, INTERSECTION_POINT
}
private Type type;
private Vector3d point;
private final Type type;
private final Vector3d point;
public PlaneSegmentIntersection(Type type) {
public PlaneSegmentIntersection(Type type, Vector3d point) {
super();
this.type = type;
this.point = point;
}
public PlaneSegmentIntersection(Type type){
if (type == Type.INTERSECTION_POINT){
throw new IllegalStateException("Tried creating a PlaneSegmentIntersection of type INTERSECTION_POINT" +
"without an intersection-point vector");
}
this.type = type;
this.point = null;
}
public Vector3d getPoint() {
return point;
}
public void setPoint(Vector3d point) {
this.point = point;
}
public Type getType() {
return type;
......
......@@ -33,8 +33,8 @@ import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
*/
public class Polygon2d {
private Ring2d exterior;
private List<Ring2d> innerRings;
private final Ring2d exterior;
private final List<Ring2d> innerRings;
public static Polygon2d withProjection(Polygon poly) {
ProjectionAxis axis = ProjectionAxis.of(poly);
......
......@@ -37,7 +37,7 @@ public class ProjectionAxis {
private static final String DIVISOR_IS_0 = "Divisor is 0";
private int[] axis;
private final int[] axis;
public static ProjectionAxis of(Polygon p) {
return getProjectionAxis(p.calculateNormal());
......@@ -134,7 +134,7 @@ public class ProjectionAxis {
double x = (d - b * y - c * z) / a;
return new Vertex(x, y, z);
} else {
throw new IllegalStateException("Unknown axis: " + axis);
throw new IllegalStateException("Unknown axis: " + Arrays.toString(axis));
}
}
......
......@@ -33,8 +33,8 @@ public class Ray {
public static final double EPSILON = 0.0001;
private Vector3d origin;
private UnitVector3d direction;
private final Vector3d origin;
private final UnitVector3d direction;
public Ray(Vector3d origin, Vector3d direction) {
this.origin = origin;
......
......@@ -32,8 +32,8 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
*/
public class Ring2d {
private List<Vector2d> ringVertices;
private LinearRing original;
private final List<Vector2d> ringVertices;
private final LinearRing original;
public static Ring2d of(MovedRing movedRing) {
return of(movedRing, ProjectionAxis.of(movedRing));
......
......@@ -21,15 +21,15 @@ package de.hft.stuttgart.citydoctor2.math;
/**
* This class represents a line from a point to another point, it can be used to
* calculate the intersection of two edges
*
*
* @author Matthias Betz
*
*/
public class Segment2d {
private static final double EPSILON = 0.01;
private Vector2d p1;
private Vector2d p2;
private final Vector2d p1;
private final Vector2d p2;
public Segment2d(Vector2d p1, Vector2d p2) {
this.p1 = p1;
......@@ -51,7 +51,7 @@ public class Segment2d {
double numeratora = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
double numeratorb = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
if (Math.abs(denominator) < EPSILON) {
denominator = 0.0;
}
......@@ -71,7 +71,7 @@ public class Segment2d {
return ua > EPSILON && ua < (1 - EPSILON) && ub > EPSILON && ub < (1 - EPSILON);
}
}
public boolean intersectsWithoutColinearity(Segment2d other) {
double x1 = p1.getX();
double x2 = p2.getX();
......@@ -89,7 +89,7 @@ public class Segment2d {
if (Math.abs(denominator) < EPSILON) {
denominator = 0.0;
}
if (denominator == 0) {
// both numerators == 0 means, lines are coincident, otherwise parallel
// parallel lines are not intersecting
......@@ -103,7 +103,7 @@ public class Segment2d {
}
}
public Vector2d intersectionPoint(Segment2d other) {
IntersectionPoint2d inter = calculateIntersection(other);
if (inter == null) {
......@@ -111,7 +111,7 @@ public class Segment2d {
}
return inter.getIntersectionPoint();
}
public IntersectionPoint2d calculateIntersection(Segment2d other) {
double x1 = p1.getX();
double x2 = p2.getX();
......@@ -122,14 +122,14 @@ public class Segment2d {
double y2 = p2.getY();
double y3 = other.getP1().getY();
double y4 = other.getP2().getY();
double a1 = x2 - x1;
double b1 = x4 - x3;
double c1 = x3 - x1;
double a2 = y2 - y1;
double b2 = y4 - y3;
double c2 = y3 - y1;
double detA = b1 * a2 - a1 * b2;
double detA1 = b1 * c2 - c1 * b2;
double detA2 = a1 * c2 - c1 * a2;
......@@ -143,15 +143,13 @@ public class Segment2d {
if (containsPoint(other.p2)) {
return new IntersectionPoint2d(new Line2d(other.p2, new Vector2d()), 0);
}
return null;
} else {
// parallel
return null;
}
}
}
// parallel
return null;
}
double s = detA1 / detA;
double t = detA2 / detA;
if (s < 0 || s > 1 || t < 0 || t > 1) {
// intersection on line but not on segment
return null;
......@@ -160,7 +158,7 @@ public class Segment2d {
Vector2d start = new Vector2d(x1, y1);
return new IntersectionPoint2d(new Line2d(start, dir), s);
}
public boolean containsPoint(Vector2d p) {
double xDir = p2.getX() - p1.getX();
if (xDir == 0) {
......
......@@ -18,16 +18,18 @@
*/
package de.hft.stuttgart.citydoctor2.math;
import java.io.Serial;
import java.io.Serializable;
/**
* A bounded line between two points
*
*
* @author Matthias Betz
*
*/
public class Segment3d implements Serializable {
@Serial
private static final long serialVersionUID = -506306945169934099L;
private static final double PRECISION = 0.00000001;
......@@ -44,12 +46,12 @@ public class Segment3d implements Serializable {
/**
* calculates the distance from this segment to the other segment
*
*
* @param otherSeg the other segment
* @return the distance
*/
public double getDistance(Segment3d otherSeg) {
return getDistanceResult(otherSeg).getDistance();
return getDistanceResult(otherSeg).distance();
}
public DistanceResult getDistanceResult(Segment3d other) {
......
......@@ -20,15 +20,15 @@ package de.hft.stuttgart.citydoctor2.math;
/**
* A two dimensional triangle
*
*
* @author Matthias Betz
*
*/
public class Triangle2d {
private Vector2d p1;
private Vector2d p2;
private Vector2d p3;
private final Vector2d p1;
private final Vector2d p2;
private final Vector2d p3;
private static final double EPSILON = 0;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.math;
import java.io.Serial;
import java.io.Serializable;
import de.hft.stuttgart.citydoctor2.tesselation.TesselatedPolygon;
......@@ -30,12 +31,13 @@ import de.hft.stuttgart.citydoctor2.tesselation.TesselatedPolygon;
*/
public class Triangle3d implements Serializable {
@Serial
private static final long serialVersionUID = -6907333357794272435L;
private static final double EPSILON = 0.0001;
private Vector3d p1;
private Vector3d p2;
private Vector3d p3;
private final Vector3d p1;
private final Vector3d p2;
private final Vector3d p3;
private TesselatedPolygon partOf;
......@@ -154,8 +156,7 @@ public class Triangle3d implements Serializable {
Vector3d a = p1;
Vector3d b = p2;
Vector3d c = p3;
Vector3d p = point;
return sameSide(p, a, b, c) && sameSide(p, b, a, c) && sameSide(p, c, a, b);
return sameSide(point, a, b, c) && sameSide(point, b, a, c) && sameSide(point, c, a, b);
}
private boolean sameSide(Vector3d p1, Vector3d p2, Vector3d a, Vector3d b) {
......@@ -248,14 +249,9 @@ public class Triangle3d implements Serializable {
return false;
}
if (p3 == null) {
if (other.p3 != null) {
return false;
}
} else if (!p3.equals(other.p3)) {
return false;
}
return true;
}
return other.p3 == null;
} else return p3.equals(other.p3);
}
@Override
public String toString() {
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.math;
import java.io.Serial;
import java.util.Arrays;
/**
......@@ -29,6 +30,7 @@ public class UnitVector3d extends Vector3d {
private static final String UNIT_VECTOR_IS_IMMUTABLE = "Unit vector is immutable";
@Serial
private static final long serialVersionUID = -374685263673211587L;
public static final UnitVector3d X_AXIS = new UnitVector3d(1, 0, 0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment