Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NegativeArraySizeException for planar meshes #35

Open
K-Meech opened this issue Jun 18, 2024 · 0 comments
Open

NegativeArraySizeException for planar meshes #35

K-Meech opened this issue Jun 18, 2024 · 0 comments

Comments

@K-Meech
Copy link

K-Meech commented Jun 18, 2024

Adding a mesh representing a plane that is aligned to the x, y or z axis can cause NegativeArraySizeException. For example:

Image3DUniverse universe = new Image3DUniverse();

// Mesh of a plane perpendicular to the z axis
float length = 1000;
float zpos = -100;
ArrayList<Point3f> triangles = new ArrayList<>();
triangles.add(new Point3f(-length/2, length/2, zpos));
triangles.add(new Point3f(length/2, length/2, zpos));
triangles.add(new Point3f(-length/2, -length/2, zpos));
triangles.add(new Point3f(length/2, length/2, zpos));
triangles.add(new Point3f(-length/2, -length/2, zpos));
triangles.add(new Point3f(length/2, -length/2, zpos));

CustomTriangleMesh mesh = new CustomTriangleMesh( triangles );
universe.addCustomMesh( mesh, "test-plane" );

universe.show();

results in:

Exception in thread "main" java.lang.NegativeArraySizeException
	at ij3d.shapes.BoundingBox.makeLine(BoundingBox.java:209)
	at ij3d.shapes.BoundingBox.<init>(BoundingBox.java:122)
	at ij3d.shapes.BoundingBox.<init>(BoundingBox.java:54)
	at ij3d.shapes.BoundingBox.<init>(BoundingBox.java:50)
	at ij3d.ContentInstant.display(ContentInstant.java:236)
	at ij3d.ContentCreator.createContent(ContentCreator.java:132)
	at ij3d.ContentCreator.createContent(ContentCreator.java:119)
	at ij3d.Image3DUniverse.createContent(Image3DUniverse.java:1175)
	at ij3d.Image3DUniverse.addCustomMesh(Image3DUniverse.java:1143)
	at develop.MinimalPlaneError.main(MinimalPlaneError.java:27)

This is an issue with drawing the BoundingBox, where it tries to draw lines that have a length of zero. This can result in n inside makeLine becoming negative.

I'd be happy to submit a PR with small changes to BoundingBox to account for this edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant