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