Commit 1745865f authored by Riegel's avatar Riegel
Browse files

Code cleaning Ref #69

parent 5a6f4b46
......@@ -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());
......
......@@ -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));
......
......@@ -28,8 +28,8 @@ package de.hft.stuttgart.citydoctor2.math;
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;
......@@ -143,12 +143,10 @@ public class Segment2d {
if (containsPoint(other.p2)) {
return new IntersectionPoint2d(new Line2d(other.p2, new Vector2d()), 0);
}
return null;
} else {
}
// parallel
return null;
}
}
double s = detA1 / detA;
double t = detA2 / detA;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.math;
import java.io.Serial;
import java.io.Serializable;
/**
......@@ -28,6 +29,7 @@ import java.io.Serializable;
*/
public class Segment3d implements Serializable {
@Serial
private static final long serialVersionUID = -506306945169934099L;
private static final double PRECISION = 0.00000001;
......
......@@ -26,9 +26,9 @@ package de.hft.stuttgart.citydoctor2.math;
*/
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,13 +249,8 @@ 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
......
......@@ -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);
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.math;
import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
......@@ -29,6 +30,7 @@ import java.util.Arrays;
*/
public class Vector3d implements Serializable {
@Serial
private static final long serialVersionUID = 3495650092142761365L;
private static final Vector3d ORIGIN = new Vector3d();
......
......@@ -44,7 +44,7 @@ public class CycleNode {
private boolean visited = false;
private Set<CycleNode> children;
private final Set<CycleNode> children;
public CycleNode(LinearRing value) {
children = new HashSet<>();
......@@ -92,7 +92,7 @@ public class CycleNode {
if (lowlink == index) {
List<LinearRing> comps = new LinkedList<>();
CycleNode w = null;
CycleNode w;
do {
w = s.pop();
w.onStack = false;
......
......@@ -35,7 +35,7 @@ public class KDTree {
private static final int K = 3;
private Vertex location;
private int axis;
private final int axis;
private KDTree left;
private KDTree right;
......
......@@ -38,21 +38,14 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
*/
public class PolygonGraph {
private Map<Polygon, PolygonNode> nodeMap;
private final Map<Polygon, PolygonNode> nodeMap;
public PolygonGraph() {
nodeMap = new HashMap<>();
}
private PolygonNode createOrGetNode(Polygon p) {
PolygonNode node = nodeMap.get(p);
if (node != null) {
return node;
} else {
node = new PolygonNode(p);
nodeMap.put(p, node);
return node;
}
return nodeMap.computeIfAbsent(p, PolygonNode::new);
}
public void addPolygonConnectionsFromVertex(Vertex v, Geometry geom) {
......@@ -92,7 +85,7 @@ public class PolygonGraph {
List<List<Polygon>> components = new ArrayList<>();
for (PolygonNode node : nodeMap.values()) {
if (!node.visited()) {
if (node.isUnvisited()) {
List<Polygon> component = new ArrayList<>();
Deque<PolygonNode> stack = new LinkedList<>();
stack.push(node);
......@@ -109,7 +102,7 @@ public class PolygonGraph {
node.setVisited(true);
component.add(node.getContent());
for (PolygonNode child : node.getChildren()) {
if (!child.visited()) {
if (child.isUnvisited()) {
child.setVisited(true);
stack.push(child);
}
......
......@@ -31,8 +31,8 @@ import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
*/
public class PolygonNode {
private Polygon content;
private Set<PolygonNode> children;
private final Polygon content;
private final Set<PolygonNode> children;
private boolean visited = false;
public PolygonNode(Polygon p) {
......@@ -56,8 +56,8 @@ public class PolygonNode {
this.visited = b;
}
public boolean visited() {
return visited;
public boolean isUnvisited() {
return !visited;
}
/*
......@@ -88,12 +88,8 @@ public class PolygonNode {
return false;
PolygonNode other = (PolygonNode) obj;
if (content == null) {
if (other.content != null)
return false;
} else if (!content.equals(other.content)) {
return false;
}
return true;
return other.content == null;
} else return content.equals(other.content);
}
@Override
......
......@@ -18,6 +18,8 @@
*/
package de.hft.stuttgart.citydoctor2.parser;
import java.io.Serial;
/**
* Exception when something went wrong while parsing the CityGML file.
*
......@@ -26,6 +28,7 @@ package de.hft.stuttgart.citydoctor2.parser;
*/
public class CityGmlParseException extends Exception {
@Serial
private static final long serialVersionUID = 8602390540552748135L;
public CityGmlParseException() {
......
......@@ -501,20 +501,14 @@ public class CityGmlParser {
Matcher mURN = P_URN.matcher(srsName);
// NOTE: Could use a HashMap if the switch/case becomes too long.
if (mURN.find()) {
switch (mURN.group(1)) {
case "DE_DHDN_3GK2":
return CRS_FACTORY.createFromName("EPSG:31466");
case "DE_DHDN_3GK3":
return CRS_FACTORY.createFromName("EPSG:31467");
case "DE_DHDN_3GK4":
return CRS_FACTORY.createFromName("EPSG:31468");
case "DE_DHDN_3GK5":
return CRS_FACTORY.createFromName("EPSG:31469");
case "ETRS89_UTM32":
return CRS_FACTORY.createFromName("EPSG:25832");
default:
return null;
}
return switch (mURN.group(1)) {
case "DE_DHDN_3GK2" -> CRS_FACTORY.createFromName("EPSG:31466");
case "DE_DHDN_3GK3" -> CRS_FACTORY.createFromName("EPSG:31467");
case "DE_DHDN_3GK4" -> CRS_FACTORY.createFromName("EPSG:31468");
case "DE_DHDN_3GK5" -> CRS_FACTORY.createFromName("EPSG:31469");
case "ETRS89_UTM32" -> CRS_FACTORY.createFromName("EPSG:25832");
default -> null;
};
}
if (srsName.equals("http://www.opengis.net/def/crs/EPSG/0/6697")) {
return CRS_FACTORY.createFromParameters("EPSG:6697", "+proj=longlat +ellps=GRS80 +no_defs +axis=neu");
......
......@@ -20,6 +20,8 @@ package de.hft.stuttgart.citydoctor2.parser;
import org.xml.sax.SAXException;
import java.io.Serial;
/**
* To stop the SAXParser from further parsing when the relevant section has
* already been found.
......@@ -29,6 +31,7 @@ import org.xml.sax.SAXException;
*/
public class EnvelopeFoundException extends SAXException {
@Serial
private static final long serialVersionUID = -9188617211115043815L;
public EnvelopeFoundException() {
......
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