Skip to content

Commit

Permalink
Adding checks for valid lists of points
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Harrington committed May 31, 2024
1 parent aa49a7c commit 6acd3c6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/main/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/Face.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public void computeCentroid (Point3d centroid)
public void computeNormal (Vector3d normal, double minArea)
{
computeNormal(normal);
if(Math.abs(area)<Double.MIN_VALUE) {
throw new NumberFormatException("The computed area of this triangle is too small: "+area);
}
// if(Math.abs(area)<Double.MIN_VALUE) {
// throw new NumberFormatException("The computed area of this triangle is too small: "+area);
// }

if (area < minArea)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ public Point3d (double x, double y, double z)
{
set (x, y, z);
}
@Override
public int hashCode() {
int offset = 1000;
long xHash = Math.round(x*offset);
long yHash = Math.round(y*offset);
long zHash = Math.round(z*offset);
long combined = xHash +yHash+zHash;
return (int)combined;
}
}
76 changes: 43 additions & 33 deletions src/main/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/QuickHull3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,21 +592,29 @@ public void build (Point3d[] points)
* than four or greater then the length of <code>points</code>, or the
* points appear to be coincident, colinear, or coplanar.
*/
public void build (Point3d[] points, int nump)
throws IllegalArgumentException
{
if (nump < 4)
{ throw new IllegalArgumentException (
"Less than four input points specified");
}
if (points.length < nump)
{ throw new IllegalArgumentException (
"Point array too small for specified number of points");
}
initBuffers (nump);
setPoints (points, nump);
buildHull ();
}
public void build(Point3d[] points, int nump) throws IllegalArgumentException {
if (nump < 4) {
throw new IllegalArgumentException("Less than four input points specified");
}
if (points.length < nump) {
throw new IllegalArgumentException("Point array too small for specified number of points");
}
HashSet<Point3d> set = new HashSet<Point3d>();
for(int i=0;i<points.length;i++) {
set.add(points[i]);
}
if(set.size()!=nump) {
nump=set.size();
points=new Point3d[nump];
Object[] array = set.toArray();
for(int i=0;i<points.length;i++) {
points[i]=(Point3d)array[i];
}
}
initBuffers(nump);
setPoints(points, nump);
buildHull();
}

/**
* Triangulates any non-triangular hull faces. In some cases, due to
Expand Down Expand Up @@ -1353,24 +1361,26 @@ protected void addNewFaces (
HalfEdge hedgeSidePrev = null;
HalfEdge hedgeSideBegin = null;

for (Iterator it=horizon.iterator(); it.hasNext(); )
{ HalfEdge horizonHe = (HalfEdge)it.next();
HalfEdge hedgeSide = addAdjoiningFace (eyeVtx, horizonHe);
if (debug)
{ System.out.println (
"new face: " + hedgeSide.face.getVertexString());
}
if (hedgeSidePrev != null)
{ hedgeSide.next.setOpposite (hedgeSidePrev);
}
else
{ hedgeSideBegin = hedgeSide;
}
newFaces.add (hedgeSide.getFace());
hedgeSidePrev = hedgeSide;
}
hedgeSideBegin.next.setOpposite (hedgeSidePrev);
}
for (Iterator it = horizon.iterator(); it.hasNext();) {
try {
HalfEdge horizonHe = (HalfEdge) it.next();
HalfEdge hedgeSide = addAdjoiningFace(eyeVtx, horizonHe);
if (debug) {
System.out.println("new face: " + hedgeSide.face.getVertexString());
}
if (hedgeSidePrev != null) {
hedgeSide.next.setOpposite(hedgeSidePrev);
} else {
hedgeSideBegin = hedgeSide;
}
newFaces.add(hedgeSide.getFace());
hedgeSidePrev = hedgeSide;
}catch(Throwable t) {
t.printStackTrace();
}
}
hedgeSideBegin.next.setOpposite(hedgeSidePrev);
}

/**
* Next point to add.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,6 @@ public String toString()
{
return x + " " + y + " " + z;
}


}

0 comments on commit 6acd3c6

Please sign in to comment.