Commit bed38f6d authored by Numanoglu's avatar Numanoglu
Browse files

redundant null-checks popped and constructor with create()-design

parent 0c03ab39
Pipeline #12429 failed with stage
in 111 minutes and 46 seconds
...@@ -11,33 +11,34 @@ public class SweepEdge { ...@@ -11,33 +11,34 @@ public class SweepEdge {
private Edge outgoingEdge; private Edge outgoingEdge;
private Vector3d referencePoint; private Vector3d referencePoint;
private UnitVector3d direction; private UnitVector3d direction;
private boolean valid = false;
public SweepEdge(Edge outgoingEdge, Vertex sweepVertex, double minSweepEdgeLength) { public static SweepEdge create(Edge outgoingEdge, Vertex sweepVertex, double minSweepEdgeLength) {
if (outgoingEdge == null || sweepVertex == null) { if (outgoingEdge == null || sweepVertex == null) {
return; throw new IllegalArgumentException("outgoingEdge and sweepVertex must not be null");
}
if (minSweepEdgeLength <= 0) {
throw new IllegalArgumentException("minSweepEdgeLength must be positive");
} }
Vertex referencePoint = outgoingEdge.getOppositeVertex(sweepVertex); Vertex referencePoint = outgoingEdge.getOppositeVertex(sweepVertex);
if (referencePoint == null) { if (referencePoint == null) {
return; return null;
} }
Vector3d edgeVector = sweepVertex.minus(referencePoint); Vector3d edgeVector = sweepVertex.minus(referencePoint);
if (edgeVector.getLength() < minSweepEdgeLength) { if (edgeVector.getLength() < minSweepEdgeLength) {
return; return null;
} }
this.outgoingEdge = outgoingEdge; return new SweepEdge(outgoingEdge, referencePoint, edgeVector.normalize());
this.referencePoint = referencePoint;
this.direction = edgeVector.normalize();
this.valid = true;
} }
public boolean valid() { private SweepEdge(Edge outgoingEdge, Vector3d referencePoint, UnitVector3d direction) {
return valid; this.outgoingEdge = outgoingEdge;
this.referencePoint = referencePoint;
this.direction = direction;
} }
public Vector3d intersection(Plane plane, double minLinePlaneAngleRatio) { public Vector3d intersection(Plane plane, double minLinePlaneAngleRatio) {
...@@ -53,7 +54,7 @@ public class SweepEdge { ...@@ -53,7 +54,7 @@ public class SweepEdge {
public boolean hasIntersectionPoint(Plane plane, double minLinePlaneAngleRatio) { public boolean hasIntersectionPoint(Plane plane, double minLinePlaneAngleRatio) {
if (!valid || plane == null) { if (plane == null) {
return false; return false;
} }
...@@ -80,7 +81,7 @@ public class SweepEdge { ...@@ -80,7 +81,7 @@ public class SweepEdge {
public boolean isSweepableEdge(Vector3d intersectionPoint, double eps) { public boolean isSweepableEdge(Vector3d intersectionPoint, double eps) {
if (!valid || intersectionPoint == null) { if (intersectionPoint == null) {
return false; return false;
} }
......
...@@ -61,7 +61,7 @@ public class SweepUtilities { ...@@ -61,7 +61,7 @@ public class SweepUtilities {
public boolean calculate() { public boolean calculate() {
if (sweepVertices == null || targetPlane == null) { if (sweepVertices == null) {
return false; return false;
} }
......
...@@ -29,18 +29,21 @@ public class SweepVertex { ...@@ -29,18 +29,21 @@ public class SweepVertex {
private Vertex sweepVertex; private Vertex sweepVertex;
private Vector3d newPoint; private Vector3d newPoint;
private List<Edge> outgoingEdges = new LinkedList<>();// TODO ?ist diese Zuweisung stabil? private List<Edge> outgoingEdges = new LinkedList<>();
public SweepVertex(Vertex v) { public SweepVertex(Vertex v) {
if (v == null) {
throw new IllegalArgumentException("sweepVertex must not be null");
}
sweepVertex = v; sweepVertex = v;
} }
public void collectOutgoingEdges(Polygon errorPoly, double minSweepEdgeLength) { public void collectOutgoingEdges(Polygon errorPoly, double minSweepEdgeLength) {
outgoingEdges.clear(); outgoingEdges.clear();
if (errorPoly == null || sweepVertex == null) { if (errorPoly == null) {
logger.error("Cannot collect outgoing edges: polygon or vertex is null"); logger.error("Cannot collect outgoing edges: polygon is null");
status = SweepVertexStatus.ERROR; status = SweepVertexStatus.ERROR;
return; return;
} }
...@@ -70,7 +73,7 @@ public class SweepVertex { ...@@ -70,7 +73,7 @@ public class SweepVertex {
public void initStatus (Plane targetPlane, double maxPointPlaneDistance) { public void initStatus (Plane targetPlane, double maxPointPlaneDistance) {
if (targetPlane == null || sweepVertex == null) { if (targetPlane == null) {
status = SweepVertexStatus.ERROR; status = SweepVertexStatus.ERROR;
return; return;
} }
...@@ -119,7 +122,7 @@ public class SweepVertex { ...@@ -119,7 +122,7 @@ public class SweepVertex {
newPoint = null; newPoint = null;
if (targetPlane == null || sweepVertex == null) { if (targetPlane == null) {
status = SweepVertexStatus.ERROR; status = SweepVertexStatus.ERROR;
return; return;
} }
...@@ -136,7 +139,7 @@ public class SweepVertex { ...@@ -136,7 +139,7 @@ public class SweepVertex {
return; return;
case SWEEP: case SWEEP:
if (outgoingEdges == null || outgoingEdges.size() != 1) { if (outgoingEdges.size() != 1) {
status = SweepVertexStatus.ERROR; status = SweepVertexStatus.ERROR;
return; return;
} }
...@@ -147,8 +150,8 @@ public class SweepVertex { ...@@ -147,8 +150,8 @@ public class SweepVertex {
return; return;
} }
SweepEdge sweepEdge = new SweepEdge(outgoingEdge, sweepVertex, minSweepEdgeLength); SweepEdge sweepEdge = SweepEdge.create(outgoingEdge, sweepVertex, minSweepEdgeLength);
if (!sweepEdge.valid()) { if (sweepEdge == null) {
status = SweepVertexStatus.ERROR; status = SweepVertexStatus.ERROR;
return; return;
} }
...@@ -181,7 +184,7 @@ public class SweepVertex { ...@@ -181,7 +184,7 @@ public class SweepVertex {
return; return;
} }
if (sweepVertex == null || newPoint == null) { if (newPoint == null) {
status = SweepVertexStatus.ERROR; status = SweepVertexStatus.ERROR;
return; return;
} }
......
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