├── .classpath ├── .gitignore ├── .idea ├── .gitignore ├── misc.xml ├── modules.xml └── vcs.xml ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.core.runtime.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.jdt.ui.prefs ├── LICENSE ├── README.md ├── build.smooth ├── doc ├── addingSolids.stl ├── addingWithOutsideAlignment.stl ├── addingWithOutsideAlignmentAndMargin.stl ├── addingWithShift.stl ├── clonedStepFormingStairs.stl ├── convexHull.stl ├── cuboidWithRoundedCorners.stl ├── cylinderWithManySegments.stl ├── intersectingSolids.stl ├── prismWithRegularPolygonAsBase.stl ├── rotated.stl ├── simpleCuboid.stl ├── simpleCylinder.stl ├── subtractingSolids.stl ├── subtractingWithAlignment.stl └── subtractingWithTwoAlignments.stl ├── jsolid.iml ├── lib ├── hamcrest-core-1.3-sources.jar ├── hamcrest-core-1.3.jar ├── hamcrest-library-1.3-sources.jar ├── hamcrest-library-1.3.jar ├── junit-4.12-sources.jar ├── junit-4.12.jar ├── testory-1.4.0.jar └── vecmath-1.3.1.jar ├── notice ├── CSG_js.txt ├── ImageJ_Fiji.txt ├── JCSG.txt ├── Poly2Tri.txt └── vecmath.txt └── src ├── doc ├── Examples.java ├── ReadmeGenerator.java └── introduction.md ├── java ├── com │ └── perunlabs │ │ └── jsolid │ │ ├── Config.java │ │ ├── JSolid.java │ │ ├── d1 │ │ ├── Anchor1.java │ │ ├── Angle.java │ │ └── Range.java │ │ ├── d2 │ │ ├── Circle.java │ │ ├── ConvexPolygon.java │ │ ├── Geometry.java │ │ ├── Polygon.java │ │ ├── Rectangle.java │ │ ├── RegularPolygon.java │ │ └── Vector2.java │ │ ├── d3 │ │ ├── Alignment.java │ │ ├── Anchor3.java │ │ ├── Axis.java │ │ ├── Cloner.java │ │ ├── Cuboid.java │ │ ├── Cylinder.java │ │ ├── Edge.java │ │ ├── Matrix4.java │ │ ├── Prism.java │ │ ├── Solid.java │ │ ├── Stl.java │ │ ├── Vector3.java │ │ └── op │ │ │ ├── AbstractSolid.java │ │ │ ├── AddSolid.java │ │ │ ├── AlignSolid.java │ │ │ ├── ConvexHullSolid.java │ │ │ ├── IntersectSolid.java │ │ │ ├── PolygonsSolid.java │ │ │ ├── SubSolid.java │ │ │ └── TransformedSolid.java │ │ └── util │ │ ├── Check.java │ │ ├── Hash.java │ │ └── Lists.java └── eu │ └── mihosoft │ └── vrl │ └── v3d │ ├── CSG.java │ ├── FileUtil.java │ ├── Node.java │ ├── ObjFile.java │ ├── Plane.java │ ├── Polygon.java │ ├── Sphere.java │ └── ext │ ├── imagej │ └── STLLoader.java │ ├── org │ └── poly2tri │ │ ├── AdvancingFront.java │ │ ├── AdvancingFrontIndex.java │ │ ├── AdvancingFrontNode.java │ │ ├── AnyToXYTransform.java │ │ ├── ConstrainedPointSet.java │ │ ├── CoordinateTransform.java │ │ ├── DTSweep.java │ │ ├── DTSweepConstraint.java │ │ ├── DTSweepContext.java │ │ ├── DTSweepDebugContext.java │ │ ├── DTSweepPointComparator.java │ │ ├── DelaunayTriangle.java │ │ ├── Edge.java │ │ ├── FloatBufferPoint.java │ │ ├── Matrix3Transform.java │ │ ├── NoTransform.java │ │ ├── Point.java │ │ ├── PointGenerator.java │ │ ├── PointOnEdgeException.java │ │ ├── PointSet.java │ │ ├── Poly2Tri.java │ │ ├── Polygon.java │ │ ├── PolygonGenerator.java │ │ ├── PolygonPoint.java │ │ ├── PolygonSet.java │ │ ├── TPoint.java │ │ ├── Triangulatable.java │ │ ├── TriangulationAlgorithm.java │ │ ├── TriangulationConstraint.java │ │ ├── TriangulationContext.java │ │ ├── TriangulationDebugContext.java │ │ ├── TriangulationMode.java │ │ ├── TriangulationPoint.java │ │ ├── TriangulationProcess.java │ │ ├── TriangulationProcessEvent.java │ │ ├── TriangulationProcessListener.java │ │ ├── TriangulationUtil.java │ │ ├── Tuple2.java │ │ ├── Tuple3.java │ │ └── XYToAnyTransform.java │ └── quickhull3d │ ├── COPYRIGHT │ ├── Face.java │ ├── FaceList.java │ ├── HalfEdge.java │ ├── HullUtil.java │ ├── InternalErrorException.java │ ├── Point3d.java │ ├── QuickHull3D.java │ ├── SimpleExample.java │ ├── Vector3d.java │ ├── Vertex.java │ └── VertexList.java └── junit ├── com └── perunlabs │ └── jsolid │ ├── AligningTest.java │ ├── CircleApiTest.java │ ├── ConvexHullApiTest.java │ ├── ConvexPolygonApiTest.java │ ├── CuboidApiTest.java │ ├── CylinderApiTest.java │ ├── EmptyTest.java │ ├── NullParametersTest.java │ ├── PrismApiTest.java │ ├── RectangleApiTest.java │ ├── RegularPolygonApiTest.java │ ├── TransformApiTest.java │ ├── d1 │ ├── Anchor1Test.java │ ├── AngleTest.java │ └── RangeTest.java │ ├── d2 │ ├── CircleTest.java │ ├── GeometryTest.java │ ├── RectangleTest.java │ └── Vector2Test.java │ ├── d3 │ ├── AlignmentTest.java │ ├── Anchor3Test.java │ ├── AxisTest.java │ ├── CuboidTest.java │ ├── EdgeTest.java │ ├── Matrix4Test.java │ ├── PolygonTest.java │ ├── StlTest.java │ ├── Vector3Matchers.java │ ├── Vector3Test.java │ └── op │ │ ├── AbstractSolidTest.java │ │ ├── AddTest.java │ │ ├── IntersectTest.java │ │ ├── PolygonsSolidTest.java │ │ └── SubTest.java │ └── util │ ├── CheckTest.java │ ├── ExceptionMatcher.java │ ├── HashTest.java │ ├── ListsTest.java │ ├── SolidMatcher.java │ └── SolidMatcherTest.java └── eu └── mihosoft └── vrl └── v3d └── ext └── quickhull3d ├── QhullTest.java └── QuickHull3DTest.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.smooth/ 2 | /bin/ 3 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml 3 | /$CACHE_FILE$ 4 | /$PRODUCT_WORKSPACE_FILE$ 5 | 6 | # User-specific stuff 7 | **/workspace.xml 8 | **/tasks.xml 9 | **/usage.statistics.xml 10 | **/dictionaries 11 | **/shelf 12 | 13 | # Generated files 14 | **/contentModel.xml 15 | 16 | # Sensitive or high-churn files 17 | **/dataSources/ 18 | **/dataSources.ids 19 | **/dataSources.local.xml 20 | **/sqlDataSources.xml 21 | **/dynamic.xml 22 | **/uiDesigner.xml 23 | **/dbnavigator.xml 24 | **/encodings.xml 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jsolid 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 22 13:03:39 CEST 2009 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 22 13:03:39 CEST 2009 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jsolid is a java library for 2 | [Constructive Solid Geometry](https://en.wikipedia.org/wiki/Constructive_solid_geometry) 3 | that internally uses [JCSG library](https://github.com/miho/JCSG) which uses 4 | [binary space partitioning algorithm](https://en.wikipedia.org/wiki/Binary_space_partitioning). 5 | It's great for programmatically generating STL shapes for 3d printer. 6 | 7 | ### Tutorial 8 | 9 | To use jsolid you need download latest [release jar](https://github.com/perunlabs/jsolid/releases). 10 | Whole API is available via static methods of 11 | [JSolid](https://github.com/perunlabs/jsolid/blob/master/src/java/com/perunlabs/jsolid/JSolid.java) 12 | class so all you need is to import it by adding following line 13 | (which is omitted for simplicity in all following examples). 14 | You may also want to add this line to favorites in your IDE. 15 | 16 | ``` 17 | import static com.perunlabs.jsolid.JSolid.*; 18 | ``` 19 | 20 | All curved (rounded) edges are approximated with finite precision, 21 | which is configured by specifying maximal distance allowed between required curve 22 | and closest point of approximated solid. 23 | 24 | ``` 25 | config().setCircleToPolygonPrecision(0.1); 26 | ``` 27 | 28 | Once you build your solid you can store it as STL file using 29 | 30 | ``` 31 | com.perunlabs.jsolid.d3.Stl.toStl(solid, "path/on/disk"); 32 | ``` 33 | 34 | ### Examples 35 | simple cuboid ([preview](./doc/simpleCuboid.stl)) 36 | 37 | ``` 38 | cuboid(2, 4, 8); 39 | ``` 40 | 41 | cuboid with rounded corners ([preview](./doc/cuboidWithRoundedCorners.stl)) 42 | 43 | ``` 44 | cuboid(5, 5, 5) 45 | .cornerR(z(), 1); 46 | ``` 47 | 48 | simple cylinder ([preview](./doc/simpleCylinder.stl)) 49 | 50 | ``` 51 | cylinder(5, 10); 52 | ``` 53 | 54 | cylinder with many segments ([preview](./doc/cylinderWithManySegments.stl)) 55 | 56 | ``` 57 | cylinder(10, 2) 58 | .addSegment(5, 10) 59 | .addFunnel(3, 2) 60 | .addSegment(4); 61 | ``` 62 | 63 | rotated ([preview](./doc/rotated.stl)) 64 | 65 | ``` 66 | cylinder(2, 10) 67 | .rotate(y(), degrees(45)); 68 | ``` 69 | 70 | adding solids ([preview](./doc/addingSolids.stl)) 71 | 72 | ``` 73 | cylinder(2, 10) 74 | .add(cuboid(10, 2, 5)); 75 | ``` 76 | 77 | subtracting solids ([preview](./doc/subtractingSolids.stl)) 78 | 79 | ``` 80 | cylinder(2, 10) 81 | .sub(cuboid(10, 2, 5)); 82 | ``` 83 | 84 | intersecting solids ([preview](./doc/intersectingSolids.stl)) 85 | 86 | ``` 87 | cylinder(2, 10) 88 | .intersect(cuboid(10, 2, 5)); 89 | ``` 90 | 91 | adding with shift ([preview](./doc/addingWithShift.stl)) 92 | 93 | ``` 94 | cylinder(3, 1) 95 | .add(cuboid(6, 6, 1).moveBy(vx(5))); 96 | ``` 97 | 98 | subtracting with alignment ([preview](./doc/subtractingWithAlignment.stl)) 99 | 100 | ``` 101 | cuboid(4, 4, 4) 102 | .sub(cylinder(1, 1), align(maxZ())); 103 | ``` 104 | 105 | subtracting with two alignments ([preview](./doc/subtractingWithTwoAlignments.stl)) 106 | 107 | ``` 108 | cuboid(4, 4, 4) 109 | .sub(cuboid(1, 1, 4), align(maxX()), align(minY())); 110 | ``` 111 | 112 | adding with outside alignment ([preview](./doc/addingWithOutsideAlignment.stl)) 113 | 114 | ``` 115 | cuboid(4, 4, 4) 116 | .add(cylinder(2, 4), alignOutside(maxZ())); 117 | ``` 118 | 119 | adding with outside alignment and margin ([preview](./doc/addingWithOutsideAlignmentAndMargin.stl)) 120 | 121 | ``` 122 | cuboid(4, 4, 4) 123 | .add(cylinder(2, 1), alignOutside(maxZ(), 2)); 124 | ``` 125 | 126 | convex hull ([preview](./doc/convexHull.stl)) 127 | 128 | ``` 129 | cuboid(4, 4, 1) 130 | .add(cylinder(1, 1).moveBy(vx(5))) 131 | .convexHull(); 132 | ``` 133 | 134 | prism with regular polygon as base ([preview](./doc/prismWithRegularPolygonAsBase.stl)) 135 | 136 | ``` 137 | prism(regularPolygon(4, 8), 4); 138 | ``` 139 | 140 | cloned step forming stairs ([preview](./doc/clonedStepFormingStairs.stl)) 141 | 142 | ``` 143 | cuboid(10, 4, 2) 144 | .clone(30, (i, s) -> s.moveBy(v(30, 0, i * 2)).rotate(z(), degrees(i * 6))); 145 | ``` 146 | 147 | -------------------------------------------------------------------------------- /build.smooth: -------------------------------------------------------------------------------- 1 | # 2 | # This is build script for jsolid library. 3 | # You need smooth-build tool to use it. 4 | # It can be downloaded for free from http://www.smoothbuild.org/ 5 | # 6 | 7 | vecmath_jar = file("lib/vecmath-1.3.1.jar"); 8 | hamcrest_core_jar = file("lib/hamcrest-core-1.3.jar"); 9 | hamcrest_library_jar = file("lib/hamcrest-library-1.3.jar"); 10 | junit_jar = file("lib/junit-4.12.jar"); 11 | testory_jar = file("lib/testory-1.4.0.jar"); 12 | 13 | sourceFiles = files("src/java"); 14 | 15 | dep_jars = [ 16 | vecmath_jar, 17 | ]; 18 | 19 | jsolid_classes = javac( 20 | srcs = sourceFiles, 21 | libs = dep_jars, 22 | source = "1.8", 23 | target = "1.8", 24 | ); 25 | 26 | jsolid_jar = 27 | concat([jsolid_classes, sourceFiles]) 28 | > jarFile("jsolid.jar"); 29 | 30 | testing_jars = [ 31 | junit_jar, 32 | hamcrest_core_jar, 33 | hamcrest_library_jar, 34 | jsolid_jar, 35 | testory_jar, 36 | ]; 37 | 38 | junit_dep_jars = concat([dep_jars, testing_jars]); 39 | 40 | test_classes = javac( 41 | srcs = files("src/junit"), 42 | source = "1.8", 43 | target = "1.8", 44 | libs = junit_dep_jars, 45 | ); 46 | test_jar = jarFile(test_classes, "test.jar"); 47 | 48 | test = 49 | junit( 50 | include = "**/*Test.class", 51 | tests = test_jar, 52 | deps = junit_dep_jars, 53 | ); 54 | 55 | -------------------------------------------------------------------------------- /doc/simpleCuboid.stl: -------------------------------------------------------------------------------- 1 | solid 2 | facet normal 0.0 0.0 -1.0 3 | outer loop 4 | vertex -1.0 2.0 -4.0 5 | vertex 1.0 2.0 -4.0 6 | vertex 1.0 -2.0 -4.0 7 | endloop 8 | endfacet 9 | facet normal 0.0 0.0 -1.0 10 | outer loop 11 | vertex -1.0 2.0 -4.0 12 | vertex 1.0 -2.0 -4.0 13 | vertex -1.0 -2.0 -4.0 14 | endloop 15 | endfacet 16 | facet normal 0.0 0.0 1.0 17 | outer loop 18 | vertex -1.0 -2.0 4.0 19 | vertex 1.0 -2.0 4.0 20 | vertex 1.0 2.0 4.0 21 | endloop 22 | endfacet 23 | facet normal 0.0 0.0 1.0 24 | outer loop 25 | vertex -1.0 -2.0 4.0 26 | vertex 1.0 2.0 4.0 27 | vertex -1.0 2.0 4.0 28 | endloop 29 | endfacet 30 | facet normal 0.0 -1.0 0.0 31 | outer loop 32 | vertex -1.0 -2.0 -4.0 33 | vertex 1.0 -2.0 -4.0 34 | vertex 1.0 -2.0 4.0 35 | endloop 36 | endfacet 37 | facet normal 0.0 -1.0 0.0 38 | outer loop 39 | vertex -1.0 -2.0 -4.0 40 | vertex 1.0 -2.0 4.0 41 | vertex -1.0 -2.0 4.0 42 | endloop 43 | endfacet 44 | facet normal 1.0 0.0 0.0 45 | outer loop 46 | vertex 1.0 -2.0 -4.0 47 | vertex 1.0 2.0 -4.0 48 | vertex 1.0 2.0 4.0 49 | endloop 50 | endfacet 51 | facet normal 1.0 0.0 0.0 52 | outer loop 53 | vertex 1.0 -2.0 -4.0 54 | vertex 1.0 2.0 4.0 55 | vertex 1.0 -2.0 4.0 56 | endloop 57 | endfacet 58 | facet normal 0.0 1.0 0.0 59 | outer loop 60 | vertex 1.0 2.0 -4.0 61 | vertex -1.0 2.0 -4.0 62 | vertex -1.0 2.0 4.0 63 | endloop 64 | endfacet 65 | facet normal 0.0 1.0 0.0 66 | outer loop 67 | vertex 1.0 2.0 -4.0 68 | vertex -1.0 2.0 4.0 69 | vertex 1.0 2.0 4.0 70 | endloop 71 | endfacet 72 | facet normal -1.0 0.0 0.0 73 | outer loop 74 | vertex -1.0 2.0 -4.0 75 | vertex -1.0 -2.0 -4.0 76 | vertex -1.0 -2.0 4.0 77 | endloop 78 | endfacet 79 | facet normal -1.0 0.0 0.0 80 | outer loop 81 | vertex -1.0 2.0 -4.0 82 | vertex -1.0 -2.0 4.0 83 | vertex -1.0 2.0 4.0 84 | endloop 85 | endfacet 86 | endsolid 87 | -------------------------------------------------------------------------------- /doc/subtractingWithTwoAlignments.stl: -------------------------------------------------------------------------------- 1 | solid 2 | facet normal -0.0 0.0 -1.0 3 | outer loop 4 | vertex -2.0 -1.0 -2.0 5 | vertex -2.0 2.0 -2.0 6 | vertex 2.0 2.0 -2.0 7 | endloop 8 | endfacet 9 | facet normal -0.0 0.0 -1.0 10 | outer loop 11 | vertex -2.0 -1.0 -2.0 12 | vertex 2.0 2.0 -2.0 13 | vertex 2.0 -1.0 -2.0 14 | endloop 15 | endfacet 16 | facet normal -0.0 -0.0 -1.0 17 | outer loop 18 | vertex -2.0 -1.0 -2.0 19 | vertex 1.0 -1.0 -2.0 20 | vertex 1.0 -2.0 -2.0 21 | endloop 22 | endfacet 23 | facet normal -0.0 -0.0 -1.0 24 | outer loop 25 | vertex -2.0 -1.0 -2.0 26 | vertex 1.0 -2.0 -2.0 27 | vertex -2.0 -2.0 -2.0 28 | endloop 29 | endfacet 30 | facet normal -0.0 -0.0 1.0 31 | outer loop 32 | vertex -2.0 -1.0 2.0 33 | vertex 2.0 -1.0 2.0 34 | vertex 2.0 2.0 2.0 35 | endloop 36 | endfacet 37 | facet normal -0.0 -0.0 1.0 38 | outer loop 39 | vertex -2.0 -1.0 2.0 40 | vertex 2.0 2.0 2.0 41 | vertex -2.0 2.0 2.0 42 | endloop 43 | endfacet 44 | facet normal -0.0 -0.0 1.0 45 | outer loop 46 | vertex 1.0 -1.0 2.0 47 | vertex -2.0 -1.0 2.0 48 | vertex -2.0 -2.0 2.0 49 | endloop 50 | endfacet 51 | facet normal -0.0 -0.0 1.0 52 | outer loop 53 | vertex 1.0 -1.0 2.0 54 | vertex -2.0 -2.0 2.0 55 | vertex 1.0 -2.0 2.0 56 | endloop 57 | endfacet 58 | facet normal 0.0 -1.0 -0.0 59 | outer loop 60 | vertex -2.0 -2.0 -2.0 61 | vertex 1.0 -2.0 -2.0 62 | vertex 1.0 -2.0 2.0 63 | endloop 64 | endfacet 65 | facet normal 0.0 -1.0 -0.0 66 | outer loop 67 | vertex -2.0 -2.0 -2.0 68 | vertex 1.0 -2.0 2.0 69 | vertex -2.0 -2.0 2.0 70 | endloop 71 | endfacet 72 | facet normal 1.0 -0.0 -0.0 73 | outer loop 74 | vertex 2.0 -1.0 -2.0 75 | vertex 2.0 2.0 -2.0 76 | vertex 2.0 2.0 2.0 77 | endloop 78 | endfacet 79 | facet normal 1.0 -0.0 -0.0 80 | outer loop 81 | vertex 2.0 -1.0 -2.0 82 | vertex 2.0 2.0 2.0 83 | vertex 2.0 -1.0 2.0 84 | endloop 85 | endfacet 86 | facet normal 0.0 1.0 0.0 87 | outer loop 88 | vertex 2.0 2.0 -2.0 89 | vertex -2.0 2.0 -2.0 90 | vertex -2.0 2.0 2.0 91 | endloop 92 | endfacet 93 | facet normal 0.0 1.0 0.0 94 | outer loop 95 | vertex 2.0 2.0 -2.0 96 | vertex -2.0 2.0 2.0 97 | vertex 2.0 2.0 2.0 98 | endloop 99 | endfacet 100 | facet normal -1.0 -0.0 -0.0 101 | outer loop 102 | vertex -2.0 2.0 -2.0 103 | vertex -2.0 -1.0 -2.0 104 | vertex -2.0 -1.0 2.0 105 | endloop 106 | endfacet 107 | facet normal -1.0 -0.0 -0.0 108 | outer loop 109 | vertex -2.0 2.0 -2.0 110 | vertex -2.0 -1.0 2.0 111 | vertex -2.0 2.0 2.0 112 | endloop 113 | endfacet 114 | facet normal -1.0 -0.0 -0.0 115 | outer loop 116 | vertex -2.0 -1.0 -2.0 117 | vertex -2.0 -2.0 -2.0 118 | vertex -2.0 -2.0 2.0 119 | endloop 120 | endfacet 121 | facet normal -1.0 -0.0 -0.0 122 | outer loop 123 | vertex -2.0 -1.0 -2.0 124 | vertex -2.0 -2.0 2.0 125 | vertex -2.0 -1.0 2.0 126 | endloop 127 | endfacet 128 | facet normal -0.0 -1.0 -0.0 129 | outer loop 130 | vertex 2.0 -1.0 2.0 131 | vertex 1.0 -1.0 2.0 132 | vertex 1.0 -1.0 -2.0 133 | endloop 134 | endfacet 135 | facet normal -0.0 -1.0 -0.0 136 | outer loop 137 | vertex 2.0 -1.0 2.0 138 | vertex 1.0 -1.0 -2.0 139 | vertex 2.0 -1.0 -2.0 140 | endloop 141 | endfacet 142 | facet normal 1.0 -0.0 -0.0 143 | outer loop 144 | vertex 1.0 -1.0 2.0 145 | vertex 1.0 -2.0 2.0 146 | vertex 1.0 -2.0 -2.0 147 | endloop 148 | endfacet 149 | facet normal 1.0 -0.0 -0.0 150 | outer loop 151 | vertex 1.0 -1.0 2.0 152 | vertex 1.0 -2.0 -2.0 153 | vertex 1.0 -1.0 -2.0 154 | endloop 155 | endfacet 156 | endsolid 157 | -------------------------------------------------------------------------------- /jsolid.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /lib/hamcrest-core-1.3-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/hamcrest-core-1.3-sources.jar -------------------------------------------------------------------------------- /lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /lib/hamcrest-library-1.3-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/hamcrest-library-1.3-sources.jar -------------------------------------------------------------------------------- /lib/hamcrest-library-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/hamcrest-library-1.3.jar -------------------------------------------------------------------------------- /lib/junit-4.12-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/junit-4.12-sources.jar -------------------------------------------------------------------------------- /lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/junit-4.12.jar -------------------------------------------------------------------------------- /lib/testory-1.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/testory-1.4.0.jar -------------------------------------------------------------------------------- /lib/vecmath-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perunlabs/jsolid/1defe439cce71e640c3bf6791d495880da09c093/lib/vecmath-1.3.1.jar -------------------------------------------------------------------------------- /notice/CSG_js.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Evan Wallace (http://madebyevan.com/) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /notice/ImageJ_Fiji.txt: -------------------------------------------------------------------------------- 1 | uses https://github.com/fiji/fiji/blob/master/src-plugins/3D_Viewer/src/main/java/customnode/STLLoader.java 2 | 3 | License unclear 4 | -------------------------------------------------------------------------------- /notice/JCSG.txt: -------------------------------------------------------------------------------- 1 | JCSG: 2 | 3 | /* 4 | * Copyright 2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | -------------------------------------------------------------------------------- /notice/Poly2Tri.txt: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | -------------------------------------------------------------------------------- /src/doc/Examples.java: -------------------------------------------------------------------------------- 1 | import static com.perunlabs.jsolid.JSolid.align; 2 | import static com.perunlabs.jsolid.JSolid.alignOutside; 3 | import static com.perunlabs.jsolid.JSolid.cuboid; 4 | import static com.perunlabs.jsolid.JSolid.cylinder; 5 | import static com.perunlabs.jsolid.JSolid.degrees; 6 | import static com.perunlabs.jsolid.JSolid.maxX; 7 | import static com.perunlabs.jsolid.JSolid.maxZ; 8 | import static com.perunlabs.jsolid.JSolid.minY; 9 | import static com.perunlabs.jsolid.JSolid.prism; 10 | import static com.perunlabs.jsolid.JSolid.regularPolygon; 11 | import static com.perunlabs.jsolid.JSolid.v; 12 | import static com.perunlabs.jsolid.JSolid.vx; 13 | import static com.perunlabs.jsolid.JSolid.y; 14 | import static com.perunlabs.jsolid.JSolid.z; 15 | 16 | import com.perunlabs.jsolid.JSolid; 17 | import com.perunlabs.jsolid.d1.Angle; 18 | import com.perunlabs.jsolid.d3.Solid; 19 | 20 | public class Examples { 21 | 22 | public static Solid simpleCuboid() { 23 | return cuboid(2, 4, 8); 24 | } 25 | 26 | public static Solid cuboidWithRoundedCorners() { 27 | return cuboid(5, 5, 5) 28 | .cornerR(z(), 1); 29 | } 30 | 31 | public static Solid simpleCylinder() { 32 | return cylinder(5, 10); 33 | } 34 | 35 | public static Solid cylinderWithManySegments() { 36 | return cylinder(10, 2) 37 | .addSegment(5, 10) 38 | .addFunnel(3, 2) 39 | .addSegment(4); 40 | } 41 | 42 | public static Solid rotated() { 43 | return cylinder(2, 10) 44 | .rotate(y(), degrees(45)); 45 | } 46 | 47 | public static Solid addingSolids() { 48 | return cylinder(2, 10) 49 | .add(cuboid(10, 2, 5)); 50 | } 51 | 52 | public static Solid subtractingSolids() { 53 | return cylinder(2, 10) 54 | .sub(cuboid(10, 2, 5)); 55 | } 56 | 57 | public static Solid intersectingSolids() { 58 | return cylinder(2, 10) 59 | .intersect(cuboid(10, 2, 5)); 60 | } 61 | 62 | public static Solid addingWithShift() { 63 | return cylinder(3, 1) 64 | .add(cuboid(6, 6, 1).moveBy(vx(5))); 65 | } 66 | 67 | public static Solid subtractingWithAlignment() { 68 | return cuboid(4, 4, 4) 69 | .sub(cylinder(1, 1), align(maxZ())); 70 | } 71 | 72 | public static Solid subtractingWithTwoAlignments() { 73 | return cuboid(4, 4, 4) 74 | .sub(cuboid(1, 1, 4), align(maxX()), align(minY())); 75 | } 76 | 77 | public static Solid addingWithOutsideAlignment() { 78 | return cuboid(4, 4, 4) 79 | .add(cylinder(2, 4), alignOutside(maxZ())); 80 | } 81 | 82 | public static Solid addingWithOutsideAlignmentAndMargin() { 83 | return cuboid(4, 4, 4) 84 | .add(cylinder(2, 1), alignOutside(maxZ(), 2)); 85 | } 86 | 87 | public static Solid convexHull() { 88 | return cuboid(4, 4, 1) 89 | .add(cylinder(1, 1).moveBy(vx(5))) 90 | .convexHull(); 91 | } 92 | 93 | public static Solid prismWithRegularPolygonAsBase() { 94 | return prism(regularPolygon(4, 8), 4); 95 | } 96 | 97 | public static Solid clonedStepFormingStairs() { 98 | return cuboid(10, 4, 2) 99 | .clone(30, (i, s) -> s.moveBy(v(30, 0, i * 2)).rotate(z(), degrees(i * 6))); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/doc/introduction.md: -------------------------------------------------------------------------------- 1 | jsolid is a java library for 2 | [Constructive Solid Geometry](https://en.wikipedia.org/wiki/Constructive_solid_geometry) 3 | that internally uses [JCSG library](https://github.com/miho/JCSG) which uses 4 | [binary space partitioning algorithm](https://en.wikipedia.org/wiki/Binary_space_partitioning). 5 | It's great for programmatically generating STL shapes for 3d printer. 6 | 7 | ### Tutorial 8 | 9 | To use jsolid you need download latest [release jar](https://github.com/perunlabs/jsolid/releases). 10 | Whole API is available via static methods of 11 | [JSolid](https://github.com/perunlabs/jsolid/blob/master/src/java/com/perunlabs/jsolid/JSolid.java) 12 | class so all you need is to import it by adding following line 13 | (which is omitted for simplicity in all following examples). 14 | You may also want to add this line to favorites in your IDE. 15 | 16 | ``` 17 | import static com.perunlabs.jsolid.JSolid.*; 18 | ``` 19 | 20 | All curved (rounded) edges are approximated with finite precision, 21 | which is configured by specifying maximal distance allowed between required curve 22 | and closest point of approximated solid. 23 | 24 | ``` 25 | config().setCircleToPolygonPrecision(0.1); 26 | ``` 27 | 28 | Once you build your solid you can store it as STL file using 29 | 30 | ``` 31 | com.perunlabs.jsolid.d3.Stl.toStl(solid, "path/on/disk"); 32 | ``` 33 | 34 | ### Examples 35 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/Config.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | public class Config { 4 | private double circleToPolygonPrecision = 0.004; 5 | 6 | public synchronized double getCircleToPolygonPrecision() { 7 | return circleToPolygonPrecision; 8 | } 9 | 10 | public synchronized void setCircleToPolygonPrecision(double value) { 11 | this.circleToPolygonPrecision = value; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d1/Anchor1.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d1; 2 | 3 | import static com.perunlabs.jsolid.JSolid.range; 4 | 5 | import java.util.stream.Stream; 6 | import java.util.stream.StreamSupport; 7 | 8 | import com.perunlabs.jsolid.d3.Anchor3; 9 | import com.perunlabs.jsolid.d3.Axis; 10 | import com.perunlabs.jsolid.util.Check; 11 | 12 | public abstract class Anchor1 { 13 | public final double edge; 14 | 15 | private Anchor1(double edge) { 16 | this.edge = edge; 17 | } 18 | 19 | public static Anchor1 min() { 20 | return new Anchor1(-1.0) { 21 | public Range moveTo(Range range, double value) { 22 | return range(value, value + range.size()); 23 | } 24 | 25 | public Range resizeTo(Range range, double size) { 26 | Check.notNegative(size); 27 | return range(range.min, range.min + size); 28 | } 29 | 30 | public double of(Iterable values) { 31 | return stream(values) 32 | .reduce(Math::min) 33 | .orElseThrow(IllegalArgumentException::new); 34 | } 35 | 36 | public Anchor1 opposite() { 37 | return max(); 38 | } 39 | }; 40 | } 41 | 42 | private static Stream stream(Iterable iterable) { 43 | return StreamSupport.stream(iterable.spliterator(), false); 44 | } 45 | 46 | public static Anchor1 max() { 47 | return new Anchor1(1.0) { 48 | public Range moveTo(Range range, double value) { 49 | return range(value - range.size(), value); 50 | } 51 | 52 | public Range resizeTo(Range range, double size) { 53 | Check.notNegative(size); 54 | return range(range.max - size, range.max); 55 | } 56 | 57 | public double of(Iterable values) { 58 | return stream(values) 59 | .reduce(Math::max) 60 | .orElseThrow(IllegalArgumentException::new); 61 | } 62 | 63 | public Anchor1 opposite() { 64 | return min(); 65 | } 66 | }; 67 | } 68 | 69 | public static Anchor1 center() { 70 | return new Anchor1(0.0) { 71 | public Range moveTo(Range range, double value) { 72 | double halfSize = range.size() / 2; 73 | return range(value - halfSize, value + halfSize); 74 | } 75 | 76 | public Range resizeTo(Range range, double size) { 77 | Check.notNegative(size); 78 | double center = range.center(); 79 | double halfSize = size / 2; 80 | return range(center - halfSize, center + halfSize); 81 | } 82 | 83 | public double of(Iterable values) { 84 | double min = min().of(values); 85 | double max = max().of(values); 86 | return (min + max) / 2; 87 | } 88 | 89 | public Anchor1 opposite() { 90 | return this; 91 | } 92 | }; 93 | } 94 | 95 | public abstract double of(Iterable values); 96 | 97 | public abstract Anchor1 opposite(); 98 | 99 | public > Anchor3 on(Axis axis) { 100 | return new Anchor3(axis, this); 101 | } 102 | 103 | public abstract Range moveTo(Range range, double value); 104 | 105 | public abstract Range resizeTo(Range range, double size); 106 | 107 | public Range resizeBy(Range range, double delta) { 108 | return resizeTo(range, range.size() + delta); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d1/Angle.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d1; 2 | 3 | import static java.lang.Math.PI; 4 | 5 | import com.perunlabs.jsolid.util.Hash; 6 | 7 | public class Angle { 8 | private static final int DEGREES_IN_PERIGON = 360; 9 | private static final double RADIANS_IN_PERIGON = 2 * PI; 10 | 11 | private final double perigon; 12 | 13 | private Angle(double perigons) { 14 | this.perigon = perigons; 15 | } 16 | 17 | public static Angle perigons(double perigons) { 18 | return new Angle(perigons); 19 | } 20 | 21 | public static Angle degrees(double degrees) { 22 | return new Angle(degrees / DEGREES_IN_PERIGON); 23 | } 24 | 25 | public static Angle radians(double radians) { 26 | return new Angle(radians / RADIANS_IN_PERIGON); 27 | } 28 | 29 | public double perigon() { 30 | return perigon; 31 | } 32 | 33 | public double degrees() { 34 | return DEGREES_IN_PERIGON * perigon; 35 | } 36 | 37 | public double radians() { 38 | return RADIANS_IN_PERIGON * perigon; 39 | } 40 | 41 | public boolean equals(Object object) { 42 | return (object instanceof Angle) && equals((Angle) object); 43 | } 44 | 45 | private boolean equals(Angle that) { 46 | return this.perigon == that.perigon; 47 | } 48 | 49 | public int hashCode() { 50 | return Hash.hash(perigon); 51 | } 52 | 53 | public String toString() { 54 | return Double.toString(perigon) + " perigons"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d1/Range.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d1; 2 | 3 | import com.perunlabs.jsolid.JSolid; 4 | import com.perunlabs.jsolid.util.Check; 5 | import com.perunlabs.jsolid.util.Hash; 6 | 7 | public final class Range { 8 | public final double min; 9 | public final double max; 10 | 11 | public Range(double size) { 12 | Check.positive(size); 13 | this.min = -size / 2; 14 | this.max = size / 2; 15 | } 16 | 17 | public Range(double v1, double v2) { 18 | this.min = v1 < v2 ? v1 : v2; 19 | this.max = v1 < v2 ? v2 : v1; 20 | } 21 | 22 | public double size() { 23 | return max - min; 24 | } 25 | 26 | public double center() { 27 | return (max + min) / 2; 28 | } 29 | 30 | public Range min(double min) { 31 | Check.notNegative(max - min); 32 | return new Range(min, max); 33 | } 34 | 35 | public Range max(double max) { 36 | Check.notNegative(max - min); 37 | return new Range(min, max); 38 | } 39 | 40 | public Range resizeTo(double size) { 41 | return resizeTo(size, JSolid.center()); 42 | } 43 | 44 | public Range resizeTo(double size, Anchor1 anchor) { 45 | return anchor.resizeTo(this, size); 46 | } 47 | 48 | public Range resizeBy(double delta) { 49 | return resizeBy(delta, JSolid.center()); 50 | } 51 | 52 | public Range resizeBy(double delta, Anchor1 anchor) { 53 | return resizeTo(size() + delta, anchor); 54 | } 55 | 56 | public Range moveBy(double value) { 57 | return new Range(min + value, max + value); 58 | } 59 | 60 | public Range moveTo(Anchor1 anchor, double value) { 61 | return anchor.moveTo(this, value); 62 | } 63 | 64 | public Range mul(double value) { 65 | Check.notNegative(value); 66 | double center = center(); 67 | double newHalfSize = (value * size()) / 2; 68 | return new Range(center - newHalfSize, center + newHalfSize); 69 | } 70 | 71 | public Range neg() { 72 | return new Range(-min, -max); 73 | } 74 | 75 | public boolean equals(Object object) { 76 | return object instanceof Range && equals((Range) object); 77 | } 78 | 79 | private boolean equals(Range range) { 80 | return this.min == range.min && this.max == range.max; 81 | } 82 | 83 | public int hashCode() { 84 | return Hash.hash(min, max); 85 | } 86 | 87 | public String toString() { 88 | return "range(" + min + ", " + max + ")"; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d2/Circle.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static com.perunlabs.jsolid.JSolid.config; 4 | import static java.lang.Math.PI; 5 | import static java.lang.Math.acos; 6 | 7 | public final class Circle extends RegularPolygon { 8 | private static final double PI_X_2 = 2 * Math.PI; 9 | private static final int MIN_VERTEX_COUNT = 8; 10 | private static final double MIN_ANGLE_STEP = 2 * Math.PI / MIN_VERTEX_COUNT; 11 | 12 | public Circle(double radius) { 13 | super(radius, vertexCount(radius, PI_X_2)); 14 | } 15 | 16 | public static int vertexCount(double radius) { 17 | return vertexCount(radius, 2 * PI); 18 | } 19 | 20 | public static int vertexCount(double radius, double circleAngle) { 21 | double angleStep = minAngleStep(radius, config().getCircleToPolygonPrecision()); 22 | return (int) Math.ceil(circleAngle / angleStep); 23 | } 24 | 25 | private static double minAngleStep(double radius, double circleToPolygonPrecision) { 26 | if (circleToPolygonPrecision < radius) { 27 | return 2 * acos((radius - circleToPolygonPrecision) / radius); 28 | } else { 29 | return MIN_ANGLE_STEP; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d2/ConvexPolygon.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static java.util.Arrays.asList; 4 | 5 | import java.util.List; 6 | 7 | import com.perunlabs.jsolid.util.Check; 8 | 9 | public final class ConvexPolygon implements Polygon { 10 | private final List vertexes; 11 | 12 | public ConvexPolygon(Vector2... vertexes) { 13 | List vertexList = asList(Check.noNullElements(vertexes)); 14 | if (!Geometry.isConvexCounterClockwisePolygon(vertexList)) { 15 | throw new IllegalArgumentException("vertexes should specify convex shape"); 16 | } 17 | this.vertexes = vertexList; 18 | } 19 | 20 | public List vertexes() { 21 | return vertexes; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d2/Geometry.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import java.util.List; 4 | 5 | public class Geometry { 6 | public static boolean isConvexCounterClockwisePolygon(List vertexes) { 7 | if (vertexes.size() < 3) { 8 | throw new IllegalArgumentException( 9 | "At least 3 vertexes are needed. Received " + vertexes.size()); 10 | } 11 | double lastAngle = vertexes.get(0).sub(vertexes.get(vertexes.size() - 1)).angle().perigon(); 12 | double previous = lastAngle; 13 | boolean alreadyDecreased = false; 14 | for (int i = 0; i < vertexes.size() - 1; i++) { 15 | double angle = vertexes.get(i + 1).sub(vertexes.get(i)).angle().perigon(); 16 | if (angle < previous) { 17 | if (alreadyDecreased) { 18 | return false; 19 | } 20 | alreadyDecreased = true; 21 | } 22 | previous = angle; 23 | } 24 | 25 | if (lastAngle < previous) { 26 | if (alreadyDecreased) { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d2/Polygon.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import java.util.List; 4 | 5 | public interface Polygon { 6 | 7 | public List vertexes(); 8 | } 9 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d2/Rectangle.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static com.perunlabs.jsolid.JSolid.v; 4 | import static java.lang.Math.PI; 5 | import static java.lang.Math.cos; 6 | import static java.lang.Math.min; 7 | import static java.lang.Math.sin; 8 | import static java.util.Arrays.asList; 9 | import static java.util.Objects.requireNonNull; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import com.perunlabs.jsolid.d1.Range; 15 | 16 | public final class Rectangle implements Polygon { 17 | private final Range xRange; 18 | private final Range yRange; 19 | private final double cornerR; 20 | 21 | public Rectangle(Range xRange, Range yRange, double cornerR) { 22 | this.xRange = requireNonNull(xRange); 23 | this.yRange = requireNonNull(yRange); 24 | this.cornerR = cornerR; 25 | } 26 | 27 | public Rectangle cornerR(double radius) { 28 | if (radius < 0) { 29 | throw new IllegalArgumentException("cornerR should be greater than 0, but is " + radius); 30 | } 31 | return new Rectangle(xRange, yRange, radius); 32 | } 33 | 34 | public List vertexes() { 35 | double x1 = xRange.min; 36 | double x2 = xRange.max; 37 | double y1 = yRange.min; 38 | double y2 = yRange.max; 39 | if (0 < cornerR) { 40 | return roundedVertexes(x1, y1, x2, y2); 41 | } else { 42 | return asList(v(x1, y1), v(x2, y1), v(x2, y2), v(x1, y2)); 43 | } 44 | } 45 | 46 | private List roundedVertexes(double x1, double y1, double x2, double y2) { 47 | double xSize = this.xRange.size(); 48 | double ySize = this.yRange.size(); 49 | double maxRadius = min(xSize, ySize) / 2; 50 | double radius = min(maxRadius, cornerR); 51 | double count = Circle.vertexCount(radius, 0.5 * Math.PI); 52 | ArrayList result = new ArrayList<>(); 53 | addCornerVertexes(result, v(x1 + radius, y1 + radius), radius, PI, count); 54 | if (2 * radius < xSize) { 55 | result.add(v(x1 + radius, y1)); 56 | } 57 | 58 | addCornerVertexes(result, v(x2 - radius, y1 + radius), radius, 1.5 * PI, count); 59 | if (2 * radius < ySize) { 60 | result.add(v(x2, y1 + radius)); 61 | } 62 | 63 | addCornerVertexes(result, v(x2 - radius, y2 - radius), radius, 0, count); 64 | if (2 * radius < xSize) { 65 | result.add(v(x2 - radius, y2)); 66 | } 67 | 68 | addCornerVertexes(result, v(x1 + radius, y2 - radius), radius, 0.5 * PI, count); 69 | if (2 * radius < ySize) { 70 | result.add(v(x1, y2 - radius)); 71 | } 72 | 73 | return result; 74 | } 75 | 76 | private void addCornerVertexes(ArrayList result, 77 | Vector2 v0, double radius, double angle0, double count) { 78 | for (int i = 0; i < count; i++) { 79 | Vector2 v = v( 80 | cos(angle0 + (i * 0.5 * PI) / count) * radius, 81 | sin(angle0 + (i * 0.5 * PI) / count) * radius); 82 | result.add(v0.add(v)); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d2/RegularPolygon.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static com.perunlabs.jsolid.JSolid.v; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import com.perunlabs.jsolid.util.Check; 9 | 10 | public class RegularPolygon implements Polygon { 11 | private final List vertexes; 12 | 13 | public RegularPolygon(double radius, int vertexCount) { 14 | this.vertexes = generateVertexes(Check.positive(radius), Check.positive(vertexCount)); 15 | } 16 | 17 | private static List generateVertexes(double radius, int vertexCount) { 18 | ArrayList result = new ArrayList<>(); 19 | for (int i = 0; i < vertexCount; i++) { 20 | double angle = (i * (2 * Math.PI)) / vertexCount; 21 | result.add(v(Math.cos(angle) * radius, Math.sin(angle) * radius)); 22 | } 23 | return result; 24 | } 25 | 26 | public List vertexes() { 27 | return vertexes; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d2/Vector2.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static com.perunlabs.jsolid.JSolid.radians; 4 | import static java.lang.Math.PI; 5 | import static java.lang.Math.sqrt; 6 | import static java.lang.String.format; 7 | 8 | import com.perunlabs.jsolid.d1.Angle; 9 | import com.perunlabs.jsolid.util.Check; 10 | import com.perunlabs.jsolid.util.Hash; 11 | 12 | public final class Vector2 { 13 | public final double x; 14 | public final double y; 15 | 16 | public static Vector2 vector2(double x, double y) { 17 | return new Vector2( 18 | Check.isFinite(x), 19 | Check.isFinite(y)); 20 | } 21 | 22 | private Vector2(double x, double y) { 23 | this.x = x; 24 | this.y = y; 25 | } 26 | 27 | public double length() { 28 | return sqrt(x * x + y * y); 29 | } 30 | 31 | public Angle angle() { 32 | return radians(angleInRadians()); 33 | } 34 | 35 | private double angleInRadians() { 36 | double result = Math.atan2(y, x); 37 | if (result < 0) { 38 | return result + PI * 2; 39 | } else { 40 | return result; 41 | } 42 | } 43 | 44 | public Vector2 add(Vector2 v) { 45 | return vector2(x + v.x, y + v.y); 46 | } 47 | 48 | public Vector2 sub(Vector2 v) { 49 | return vector2(x - v.x, y - v.y); 50 | } 51 | 52 | public Vector2 neg() { 53 | return vector2(-x, -y); 54 | } 55 | 56 | public Vector2 mul(double multiplier) { 57 | return vector2(x * multiplier, y * multiplier); 58 | } 59 | 60 | public Vector2 div(double divisor) { 61 | return vector2(x / divisor, y / divisor); 62 | } 63 | 64 | public double dot(Vector2 v) { 65 | return x * v.x + y * v.y; 66 | } 67 | 68 | public double cross(Vector2 v) { 69 | return x * v.y - y * v.x; 70 | } 71 | 72 | public Vector2 normalize() { 73 | return div(length()); 74 | } 75 | 76 | public boolean equals(Object object) { 77 | return object instanceof Vector2 && equals((Vector2) object); 78 | } 79 | 80 | private boolean equals(Vector2 that) { 81 | return this.x == that.x && this.y == that.y; 82 | } 83 | 84 | public int hashCode() { 85 | return Hash.hash(x, y); 86 | } 87 | 88 | public String toString() { 89 | return format("v(" + x + ", " + y + ")"); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Alignment.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | 5 | public class Alignment { 6 | private final Anchor3 anchorA; 7 | private final Anchor3 anchorB; 8 | private final double shift; 9 | 10 | public > Alignment(Anchor3 anchorA, Anchor3 anchorB, double shift) { 11 | this.anchorA = requireNonNull(anchorA); 12 | this.anchorB = requireNonNull(anchorB); 13 | this.shift = shift; 14 | } 15 | 16 | public Solid align(Solid solid1, Solid solid2) { 17 | return solid2.moveBy(alignShiftFor(solid1, solid2)); 18 | } 19 | 20 | public Vector3 alignShiftFor(Solid solid1, Solid solid2) { 21 | return anchorA.vectorIn(solid1).sub(anchorB.vectorIn(solid2)).add(anchorA.axis.v(shift)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Anchor3.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | import static java.util.stream.Collectors.toList; 5 | 6 | import java.util.List; 7 | 8 | import com.perunlabs.jsolid.d1.Anchor1; 9 | 10 | public class Anchor3> { 11 | public final Axis axis; 12 | private final Anchor1 anchor; 13 | 14 | public Anchor3(Axis axis, Anchor1 anchor) { 15 | this.axis = requireNonNull(axis); 16 | this.anchor = requireNonNull(anchor); 17 | } 18 | 19 | public double valueIn(Solid solid) { 20 | List elements = solid.vertexes().stream() 21 | .map(v -> axis.coordinate(v)) 22 | .collect(toList()); 23 | return anchor.of(elements); 24 | } 25 | 26 | public Anchor3 other() { 27 | return new Anchor3<>(axis, anchor.opposite()); 28 | } 29 | 30 | public double edge() { 31 | return anchor.edge; 32 | } 33 | 34 | public Vector3 vectorIn(Solid solid) { 35 | return axis.v(valueIn(solid)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Axis.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.matrix; 4 | import static com.perunlabs.jsolid.JSolid.max; 5 | import static com.perunlabs.jsolid.JSolid.min; 6 | import static com.perunlabs.jsolid.JSolid.range; 7 | 8 | import com.perunlabs.jsolid.JSolid; 9 | import com.perunlabs.jsolid.d1.Angle; 10 | import com.perunlabs.jsolid.d1.Range; 11 | 12 | public abstract class Axis> extends Vector3 { 13 | public static final XAxis X = new XAxis(); 14 | public static final YAxis Y = new YAxis(); 15 | public static final ZAxis Z = new ZAxis(); 16 | 17 | private Axis(double x, double y, double z) { 18 | super(x, y, z); 19 | } 20 | 21 | public abstract double coordinate(Vector3 v); 22 | 23 | public abstract Vector3 v(double coordinate); 24 | 25 | public Range rangeOf(Solid solid) { 26 | return range(min().on(this).valueIn(solid), max().on(this).valueIn(solid)); 27 | } 28 | 29 | public double sizeOf(Solid solid) { 30 | return rangeOf(solid).size(); 31 | } 32 | 33 | public abstract Matrix4 rotateMatrix(Angle angle); 34 | 35 | public abstract Matrix4 mirrorMatrix(); 36 | 37 | public abstract Matrix4 scaleMatrix(double factor); 38 | 39 | public static class XAxis extends Axis { 40 | public XAxis() { 41 | super(1, 0, 0); 42 | } 43 | 44 | public double coordinate(Vector3 v) { 45 | return v.x; 46 | } 47 | 48 | public Vector3 v(double coordinate) { 49 | return JSolid.v(coordinate, 0, 0); 50 | } 51 | 52 | public Matrix4 rotateMatrix(Angle angle) { 53 | double sin = Math.sin(angle.radians()); 54 | double cos = Math.cos(angle.radians()); 55 | return matrix( 56 | 1, 0, 0, 0, 57 | 0, cos, -sin, 0, 58 | 0, sin, cos, 0, 59 | 0, 0, 0, 1); 60 | } 61 | 62 | public Matrix4 mirrorMatrix() { 63 | return new Matrix4( 64 | -1, 0, 0, 0, 65 | 0, 1, 0, 0, 66 | 0, 0, 1, 0, 67 | 0, 0, 0, 1); 68 | } 69 | 70 | public Matrix4 scaleMatrix(double factor) { 71 | return matrix( 72 | factor, 0, 0, 0, 73 | 0, 1, 0, 0, 74 | 0, 0, 1, 0, 75 | 0, 0, 0, 1); 76 | } 77 | } 78 | 79 | public static class YAxis extends Axis { 80 | public YAxis() { 81 | super(0, 1, 0); 82 | } 83 | 84 | public double coordinate(Vector3 v) { 85 | return v.y; 86 | } 87 | 88 | public Vector3 v(double coordinate) { 89 | return JSolid.v(0, coordinate, 0); 90 | } 91 | 92 | public Matrix4 rotateMatrix(Angle angle) { 93 | double sin = Math.sin(angle.radians()); 94 | double cos = Math.cos(angle.radians()); 95 | return matrix( 96 | cos, 0, sin, 0, 97 | 0, 1, 0, 0, 98 | -sin, 0, cos, 0, 99 | 0, 0, 0, 1); 100 | } 101 | 102 | public Matrix4 mirrorMatrix() { 103 | return new Matrix4( 104 | 1, 0, 0, 0, 105 | 0, -1, 0, 0, 106 | 0, 0, 1, 0, 107 | 0, 0, 0, 1); 108 | } 109 | 110 | public Matrix4 scaleMatrix(double factor) { 111 | return matrix( 112 | 1, 0, 0, 0, 113 | 0, factor, 0, 0, 114 | 0, 0, 1, 0, 115 | 0, 0, 0, 1); 116 | } 117 | } 118 | 119 | public static class ZAxis extends Axis { 120 | public ZAxis() { 121 | super(0, 0, 1); 122 | } 123 | 124 | public double coordinate(Vector3 v) { 125 | return v.z; 126 | } 127 | 128 | public Vector3 v(double coordinate) { 129 | return JSolid.v(0, 0, coordinate); 130 | } 131 | 132 | public Matrix4 rotateMatrix(Angle angle) { 133 | double sin = Math.sin(angle.radians()); 134 | double cos = Math.cos(angle.radians()); 135 | return matrix( 136 | cos, -sin, 0, 0, 137 | sin, cos, 0, 0, 138 | 0, 0, 1, 0, 139 | 0, 0, 0, 1); 140 | } 141 | 142 | public Matrix4 mirrorMatrix() { 143 | return new Matrix4( 144 | 1, 0, 0, 0, 145 | 0, 1, 0, 0, 146 | 0, 0, -1, 0, 147 | 0, 0, 0, 1); 148 | } 149 | 150 | public Matrix4 scaleMatrix(double factor) { 151 | return matrix( 152 | 1, 0, 0, 0, 153 | 0, 1, 0, 0, 154 | 0, 0, factor, 0, 155 | 0, 0, 0, 1); 156 | } 157 | 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Cloner.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | @FunctionalInterface 4 | public interface Cloner { 5 | public Solid clone(int index, Solid solid); 6 | } 7 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Cuboid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.prism; 4 | import static com.perunlabs.jsolid.JSolid.prismXZ; 5 | import static com.perunlabs.jsolid.JSolid.prismYZ; 6 | import static com.perunlabs.jsolid.JSolid.rectangle; 7 | import static com.perunlabs.jsolid.JSolid.x; 8 | import static com.perunlabs.jsolid.JSolid.y; 9 | import static com.perunlabs.jsolid.JSolid.z; 10 | import static java.util.Objects.requireNonNull; 11 | 12 | import java.util.List; 13 | 14 | import com.perunlabs.jsolid.d1.Range; 15 | import com.perunlabs.jsolid.d2.Rectangle; 16 | import com.perunlabs.jsolid.d3.op.AbstractSolid; 17 | 18 | import eu.mihosoft.vrl.v3d.Polygon; 19 | 20 | public final class Cuboid extends AbstractSolid { 21 | private final Range xRange; 22 | private final Range yRange; 23 | private final Range zRange; 24 | private final double zRadius; 25 | private final double yRadius; 26 | private final double xRadius; 27 | 28 | public Cuboid(Range xRange, Range yRange, Range zRange, double xRadius, double yRadius, 29 | double zRadius) { 30 | this.xRange = requireNonNull(xRange); 31 | this.yRange = requireNonNull(yRange); 32 | this.zRange = requireNonNull(zRange); 33 | this.xRadius = xRadius; 34 | this.yRadius = yRadius; 35 | this.zRadius = zRadius; 36 | } 37 | 38 | public Cuboid cornerR(Axis axis, double radius) { 39 | if (radius < 0) { 40 | throw new IllegalArgumentException("radius must be greater than 0, but is == " + radius); 41 | } 42 | if (axis == x()) { 43 | return new Cuboid(xRange, yRange, zRange, radius, yRadius, zRadius); 44 | } else if (axis == y()) { 45 | return new Cuboid(xRange, yRange, zRange, xRadius, radius, zRadius); 46 | } else if (axis == z()) { 47 | return new Cuboid(xRange, yRange, zRange, xRadius, yRadius, radius); 48 | } else { 49 | throw new IllegalArgumentException("Unknown axis: " + axis); 50 | } 51 | } 52 | 53 | protected List calculateSides() { 54 | Rectangle base = rectangle(xRange, yRange) 55 | .cornerR(zRadius); 56 | Solid prism = prism(base, zRange); 57 | if (0 < xRadius) { 58 | Rectangle baseYZ = rectangle(yRange, zRange) 59 | .cornerR(xRadius); 60 | prism = prism.intersect(prismYZ(baseYZ, xRange)); 61 | } 62 | if (0 < yRadius) { 63 | Rectangle baseXZ = rectangle(xRange, zRange) 64 | .cornerR(yRadius); 65 | prism = prism.intersect(prismXZ(baseXZ, yRange)); 66 | } 67 | return prism.sides(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Edge.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | 5 | import java.util.Objects; 6 | 7 | public class Edge { 8 | public final Vector3 pointA; 9 | public final Vector3 pointB; 10 | 11 | public Edge(Vector3 pointA, Vector3 pointB) { 12 | this.pointA = requireNonNull(pointA); 13 | this.pointB = requireNonNull(pointB); 14 | } 15 | 16 | public Edge flip() { 17 | return new Edge(pointB, pointA); 18 | } 19 | 20 | public boolean equals(Object object) { 21 | return object instanceof Edge && equals((Edge) object); 22 | } 23 | 24 | private boolean equals(Edge that) { 25 | return eq(that); 26 | } 27 | 28 | private boolean eq(Edge that) { 29 | return this.pointA.equals(that.pointA) && this.pointB.equals(that.pointB); 30 | } 31 | 32 | public int hashCode() { 33 | return Objects.hash(pointA, pointB); 34 | } 35 | 36 | public String toString() { 37 | return "edge(" + pointA + ", " + pointB + ")"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Prism.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.v; 4 | import static com.perunlabs.jsolid.util.Lists.reverse; 5 | import static java.util.Objects.requireNonNull; 6 | import static java.util.stream.Collectors.toList; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import com.perunlabs.jsolid.d1.Range; 12 | import com.perunlabs.jsolid.d2.Geometry; 13 | import com.perunlabs.jsolid.d2.Polygon; 14 | import com.perunlabs.jsolid.d2.Vector2; 15 | import com.perunlabs.jsolid.d3.op.AbstractSolid; 16 | 17 | public final class Prism extends AbstractSolid { 18 | private final Polygon base; 19 | private final Range zRange; 20 | 21 | public Prism(Polygon base, Range zRange) { 22 | this.base = requireNonNull(base); 23 | this.zRange = requireNonNull(zRange); 24 | } 25 | 26 | protected List calculateSides() { 27 | if (!Geometry.isConvexCounterClockwisePolygon(base.vertexes())) { 28 | throw new IllegalStateException("base is not convex, counter clockwise polygon."); 29 | } 30 | double bottom = zRange.min; 31 | double top = zRange.max; 32 | List polygons = new ArrayList<>(); 33 | polygons.add(base(reverse(base.vertexes()), bottom)); 34 | polygons.add(base(base.vertexes(), top)); 35 | List vertexes = base.vertexes(); 36 | for (int i = 0; i < vertexes.size(); i++) { 37 | int next = (i + 1) % vertexes.size(); 38 | polygons.add(poly( 39 | v(vertexes.get(i), bottom), 40 | v(vertexes.get(next), bottom), 41 | v(vertexes.get(next), top), 42 | v(vertexes.get(i), top))); 43 | } 44 | return polygons; 45 | } 46 | 47 | private eu.mihosoft.vrl.v3d.Polygon base(List vertexes, double bottom) { 48 | return new eu.mihosoft.vrl.v3d.Polygon( 49 | vertexes 50 | .stream() 51 | .map(v2 -> v(v2.x, v2.y, bottom)) 52 | .collect(toList())); 53 | } 54 | 55 | private static eu.mihosoft.vrl.v3d.Polygon poly(Vector3... points) { 56 | return eu.mihosoft.vrl.v3d.Polygon.fromPoints(points); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Solid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import java.util.List; 4 | 5 | import com.perunlabs.jsolid.d1.Angle; 6 | 7 | import eu.mihosoft.vrl.v3d.Polygon; 8 | 9 | public interface Solid { 10 | public List sides(); 11 | 12 | public List vertexes(); 13 | 14 | public Solid apply(Matrix4 matrix); 15 | 16 | public Solid add(Solid solid); 17 | 18 | public Solid add(Solid solid, Anchor3... edges); 19 | 20 | public Solid add(Solid solid, Alignment... alignments); 21 | 22 | public Solid sub(Solid solid); 23 | 24 | public Solid sub(Solid solid, Anchor3... edges); 25 | 26 | public Solid sub(Solid solid, Alignment... alignments); 27 | 28 | public Solid intersect(Solid solid); 29 | 30 | public Solid intersect(Solid solid, Anchor3... edges); 31 | 32 | public Solid intersect(Solid solid, Alignment... alignments); 33 | 34 | public Solid moveBy(Vector3 shift); 35 | 36 | public Solid moveTo(Anchor3 anchor, double position); 37 | 38 | public Solid rotate(Axis axis, Angle angle); 39 | 40 | public Solid mirror(Axis planNormal); 41 | 42 | public Solid scale(Axis direction, double factor); 43 | 44 | public Solid convexHull(); 45 | 46 | public Solid mirroredTwins(Vector3 shift); 47 | 48 | public Solid clone(int count, Cloner cloner); 49 | } 50 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Stl.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static java.nio.file.StandardOpenOption.CREATE; 4 | import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; 5 | 6 | import java.io.BufferedWriter; 7 | import java.io.IOException; 8 | import java.io.Writer; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | 12 | import eu.mihosoft.vrl.v3d.Polygon; 13 | 14 | public class Stl { 15 | public static void toStl(Solid solid, Path path) throws IOException { 16 | try (BufferedWriter writer = Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING)) { 17 | toStl(solid, writer); 18 | } 19 | } 20 | 21 | public static void toStl(Solid solid, Writer writer) throws IOException { 22 | writer.write("solid \n"); 23 | for (Polygon side : solid.sides()) { 24 | writeSide(side, writer); 25 | } 26 | writer.write("endsolid\n"); 27 | } 28 | 29 | private static void writeSide(Polygon side, Writer writer) throws IOException { 30 | for (int i = 0; i < side.vertices.size() - 2; i++) { 31 | writer.write("facet normal "); 32 | writerVector(side.plane.normal, writer); 33 | writer.write(" outer loop\n"); 34 | writer.write(" vertex "); 35 | writerVector(side.vertices.get(0), writer); 36 | writer.write(" vertex "); 37 | writerVector(side.vertices.get(i + 1), writer); 38 | writer.write(" vertex "); 39 | writerVector(side.vertices.get(i + 2), writer); 40 | writer.write(" endloop\n"); 41 | writer.write("endfacet\n"); 42 | } 43 | } 44 | 45 | private static void writerVector(Vector3 position, Writer writer) throws IOException { 46 | writer.write(Double.toString(position.x)); 47 | writer.write(" "); 48 | writer.write(Double.toString(position.y)); 49 | writer.write(" "); 50 | writer.write(Double.toString(position.z)); 51 | writer.write("\n"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/Vector3.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.v0; 4 | import static java.lang.Math.sqrt; 5 | 6 | import com.perunlabs.jsolid.util.Check; 7 | import com.perunlabs.jsolid.util.Hash; 8 | 9 | public class Vector3 { 10 | public final double x; 11 | public final double y; 12 | public final double z; 13 | 14 | public static Vector3 vector3(double x, double y, double z) { 15 | return new Vector3( 16 | Check.isFinite(x), 17 | Check.isFinite(y), 18 | Check.isFinite(z)); 19 | } 20 | 21 | Vector3(double x, double y, double z) { 22 | this.x = Check.isFinite(x); 23 | this.y = Check.isFinite(y); 24 | this.z = Check.isFinite(z); 25 | } 26 | 27 | public double length() { 28 | return sqrt(x * x + y * y + z * z); 29 | } 30 | 31 | public Vector3 add(Vector3 v) { 32 | return new Vector3( 33 | x + v.x, 34 | y + v.y, 35 | z + v.z); 36 | } 37 | 38 | public Vector3 sub(Vector3 v) { 39 | return new Vector3( 40 | x - v.x, 41 | y - v.y, 42 | z - v.z); 43 | } 44 | 45 | public Vector3 dif(Vector3 v) { 46 | return new Vector3( 47 | Math.abs(x - v.x), 48 | Math.abs(y - v.y), 49 | Math.abs(z - v.z)); 50 | } 51 | 52 | public Vector3 neg() { 53 | return new Vector3(-x, -y, -z); 54 | } 55 | 56 | public Vector3 mul(double multiplier) { 57 | return new Vector3(x * multiplier, y * multiplier, z * multiplier); 58 | } 59 | 60 | public Vector3 div(double divisor) { 61 | return new Vector3(x / divisor, y / divisor, z / divisor); 62 | } 63 | 64 | public Vector3 abs() { 65 | return new Vector3(Math.abs(x), Math.abs(y), Math.abs(z)); 66 | } 67 | 68 | public double dot(Vector3 v) { 69 | return x * v.x + y * v.y + z * v.z; 70 | } 71 | 72 | public Vector3 cross(Vector3 v) { 73 | return new Vector3( 74 | y * v.z - z * v.y, 75 | z * v.x - x * v.z, 76 | x * v.y - y * v.x); 77 | } 78 | 79 | public Vector3 normalize() { 80 | double length = length(); 81 | if (length == 0) { 82 | return v0(); 83 | } else { 84 | return new Vector3( 85 | x / length, 86 | y / length, 87 | z / length); 88 | } 89 | } 90 | 91 | public Vector3 interpolate(Vector3 v, double value) { 92 | Check.notNegative(value); 93 | if (1.0 < value) { 94 | throw new IllegalArgumentException(); 95 | } 96 | return new Vector3( 97 | x + value * (v.x - x), 98 | y + value * (v.y - y), 99 | z + value * (v.z - z)); 100 | } 101 | 102 | public boolean equals(Object object) { 103 | return object instanceof Vector3 && equals((Vector3) object); 104 | } 105 | 106 | private boolean equals(Vector3 that) { 107 | return this.x == that.x 108 | && this.y == that.y 109 | && this.z == that.z; 110 | } 111 | 112 | public int hashCode() { 113 | return Hash.hash(x, y, z); 114 | } 115 | 116 | public String toString() { 117 | return "v(" + x + ", " + y + ", " + z + ")"; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/op/AddSolid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | 5 | import java.util.List; 6 | 7 | import com.perunlabs.jsolid.d3.Solid; 8 | 9 | import eu.mihosoft.vrl.v3d.CSG; 10 | import eu.mihosoft.vrl.v3d.Polygon; 11 | 12 | public class AddSolid extends AbstractSolid { 13 | private final Solid solid1; 14 | private final Solid solid2; 15 | 16 | public AddSolid(Solid solid1, Solid solid2) { 17 | this.solid1 = requireNonNull(solid1); 18 | this.solid2 = requireNonNull(solid2); 19 | } 20 | 21 | protected List calculateSides() { 22 | if (solid1.sides().isEmpty()) { 23 | return solid2.sides(); 24 | } 25 | if (solid2.sides().isEmpty()) { 26 | return solid1.sides(); 27 | } 28 | return CSG.union(solid1.sides(), solid2.sides()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/op/AlignSolid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static java.util.Arrays.asList; 4 | import static java.util.Objects.requireNonNull; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.perunlabs.jsolid.d3.Alignment; 10 | import com.perunlabs.jsolid.d3.Solid; 11 | 12 | import eu.mihosoft.vrl.v3d.Polygon; 13 | 14 | public class AlignSolid extends AbstractSolid { 15 | private final Solid solid; 16 | private final Solid aligning; 17 | private final List alignments; 18 | 19 | public AlignSolid(Solid solid, Solid aligning, List alignments) { 20 | this.solid = requireNonNull(solid); 21 | this.aligning = requireNonNull(aligning); 22 | this.alignments = new ArrayList<>(alignments); 23 | } 24 | 25 | protected List calculateSides() { 26 | if (solid.sides().isEmpty()) { 27 | return asList(); 28 | } 29 | Solid result = solid; 30 | for (Alignment alignment : alignments) { 31 | result = alignment.align(aligning, result); 32 | } 33 | return result.sides(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/op/ConvexHullSolid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil.hullPolygons; 4 | 5 | import java.util.List; 6 | 7 | import com.perunlabs.jsolid.d3.Solid; 8 | 9 | import eu.mihosoft.vrl.v3d.Polygon; 10 | 11 | public class ConvexHullSolid extends AbstractSolid { 12 | private final Solid solid; 13 | 14 | public ConvexHullSolid(Solid solid) { 15 | this.solid = solid; 16 | } 17 | 18 | protected List calculateSides() { 19 | return hullPolygons(solid.vertexes()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/op/IntersectSolid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static java.util.Arrays.asList; 4 | import static java.util.Objects.requireNonNull; 5 | 6 | import java.util.List; 7 | 8 | import com.perunlabs.jsolid.d3.Solid; 9 | 10 | import eu.mihosoft.vrl.v3d.CSG; 11 | import eu.mihosoft.vrl.v3d.Polygon; 12 | 13 | public class IntersectSolid extends AbstractSolid { 14 | private final Solid solid1; 15 | private final Solid solid2; 16 | 17 | public IntersectSolid(Solid solid1, Solid solid2) { 18 | this.solid1 = requireNonNull(solid1); 19 | this.solid2 = requireNonNull(solid2); 20 | } 21 | 22 | protected List calculateSides() { 23 | if (solid1.sides().isEmpty() || solid2.sides().isEmpty()) { 24 | return asList(); 25 | } 26 | return CSG.intersect(solid1.sides(), solid2.sides()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/op/PolygonsSolid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static com.perunlabs.jsolid.util.Lists.immutable; 4 | 5 | import java.util.List; 6 | 7 | import eu.mihosoft.vrl.v3d.Polygon; 8 | 9 | public class PolygonsSolid extends AbstractSolid { 10 | private final List sides; 11 | 12 | public PolygonsSolid(List sides) { 13 | this.sides = immutable(sides); 14 | } 15 | 16 | protected List calculateSides() { 17 | return sides; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/op/SubSolid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | 5 | import java.util.List; 6 | 7 | import com.perunlabs.jsolid.d3.Solid; 8 | 9 | import eu.mihosoft.vrl.v3d.CSG; 10 | import eu.mihosoft.vrl.v3d.Polygon; 11 | 12 | public class SubSolid extends AbstractSolid { 13 | private final Solid solid1; 14 | private final Solid solid2; 15 | 16 | public SubSolid(Solid solid1, Solid solid2) { 17 | this.solid1 = requireNonNull(solid1); 18 | this.solid2 = requireNonNull(solid2); 19 | } 20 | 21 | protected List calculateSides() { 22 | if (solid1.sides().isEmpty() || solid2.sides().isEmpty()) { 23 | return solid1.sides(); 24 | } 25 | return CSG.difference(solid1.sides(), solid2.sides()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/d3/op/TransformedSolid.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | import com.perunlabs.jsolid.d3.Matrix4; 9 | import com.perunlabs.jsolid.d3.Solid; 10 | 11 | import eu.mihosoft.vrl.v3d.Polygon; 12 | 13 | public class TransformedSolid extends AbstractSolid { 14 | private final Solid solid; 15 | private final Matrix4 matrix; 16 | 17 | public TransformedSolid(Solid solid, Matrix4 matrix) { 18 | this.solid = requireNonNull(solid); 19 | this.matrix = requireNonNull(matrix); 20 | } 21 | 22 | public Solid apply(Matrix4 matrix) { 23 | return new TransformedSolid(solid, matrix.mul(this.matrix)); 24 | } 25 | 26 | protected List calculateSides() { 27 | return solid.sides() 28 | .stream() 29 | .map(p -> p.mul(matrix)) 30 | .collect(Collectors.toList()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/util/Check.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | 5 | public class Check { 6 | public static double positive(double value) { 7 | if (value <= 0) { 8 | throw new IllegalArgumentException( 9 | "Parameter is " + value + " but expected positive double."); 10 | } 11 | return value; 12 | } 13 | 14 | public static int positive(int value) { 15 | if (value <= 0) { 16 | throw new IllegalArgumentException( 17 | "Parameter is " + value + " but expected positive int."); 18 | } 19 | return value; 20 | } 21 | 22 | public static double notNegative(double value) { 23 | if (value < 0) { 24 | throw new IllegalArgumentException( 25 | "Parameter is " + value + " but expected not negative double."); 26 | } 27 | return value; 28 | } 29 | 30 | public static double isFinite(double value) { 31 | if (Double.isFinite(value)) { 32 | return value; 33 | } 34 | throw new IllegalArgumentException( 35 | "Parameter is " + value + " but expected finite double."); 36 | } 37 | 38 | public static T[] noNullElements(T[] array) { 39 | for (T element : array) { 40 | requireNonNull(element); 41 | } 42 | return array; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/util/Hash.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Hash { 6 | public static int hash(double... values) { 7 | return Arrays.hashCode(sanitize(values)); 8 | } 9 | 10 | public static int hash(double value) { 11 | return Double.hashCode(sanitized(value)); 12 | } 13 | 14 | private static double[] sanitize(double... values) { 15 | double[] copy = Arrays.copyOf(values, values.length); 16 | for (int i = 0; i < copy.length; i++) { 17 | copy[i] = sanitized(copy[i]); 18 | } 19 | return copy; 20 | } 21 | 22 | private static double sanitized(double value) { 23 | return value == -0.0 ? 0.0 : value; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/java/com/perunlabs/jsolid/util/Lists.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import static java.util.Collections.unmodifiableList; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Lists { 9 | public static List immutable(List list) { 10 | return unmodifiableList(new ArrayList<>(list)); 11 | } 12 | 13 | public static List reverse(List list) { 14 | ArrayList reversed = new ArrayList<>(list.size()); 15 | for (int i = list.size() - 1; i >= 0; i--) { 16 | reversed.add(list.get(i)); 17 | } 18 | return reversed; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/FileUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * FileUtil.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d; 32 | 33 | import java.io.BufferedWriter; 34 | import java.io.IOException; 35 | import java.nio.charset.Charset; 36 | import java.nio.file.Files; 37 | import java.nio.file.Path; 38 | import java.nio.file.StandardOpenOption; 39 | 40 | /** 41 | * File util class. 42 | * 43 | * @author Michael Hoffer <info@michaelhoffer.de> 44 | */ 45 | public class FileUtil { 46 | 47 | private FileUtil() { 48 | throw new AssertionError("Don't instantiate me", null); 49 | } 50 | 51 | /** 52 | * Writes the specified string to a file. 53 | * 54 | * @param p 55 | * file destination (existing files will be overwritten) 56 | * @param s 57 | * string to save 58 | * 59 | * @throws IOException 60 | * if writing to file fails 61 | */ 62 | public static void write(Path p, String s) throws IOException { 63 | try (BufferedWriter writer = Files.newBufferedWriter(p, Charset.forName("UTF-8"), 64 | StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { 65 | writer.write(s, 0, s.length()); 66 | } 67 | } 68 | 69 | /** 70 | * Reads the specified file to a string. 71 | * 72 | * @param p 73 | * file to read 74 | * @return the content of the file 75 | * 76 | * @throws IOException 77 | * if reading from file failed 78 | */ 79 | public static String read(Path p) throws IOException { 80 | return new String(Files.readAllBytes(p), Charset.forName("UTF-8")); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ObjFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package eu.mihosoft.vrl.v3d; 7 | 8 | import java.io.ByteArrayInputStream; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.nio.charset.StandardCharsets; 12 | import java.nio.file.Path; 13 | import java.nio.file.Paths; 14 | 15 | /** 16 | * 17 | * @author Michael Hoffer <info@michaelhoffer.de> 18 | */ 19 | public final class ObjFile { 20 | 21 | private String obj; 22 | private final String mtl; 23 | private InputStream objStream; 24 | private InputStream mtlStream; 25 | 26 | static final String MTL_NAME = "$JCSG_MTL_NAME$"; 27 | 28 | ObjFile(String obj, String mtl) { 29 | this.obj = obj; 30 | this.mtl = mtl; 31 | } 32 | 33 | public void toFiles(Path p) throws IOException { 34 | 35 | Path parent = p.getParent(); 36 | 37 | String fileName = p.getFileName().toString(); 38 | 39 | if (fileName.toLowerCase().endsWith(".obj") 40 | || fileName.toLowerCase().endsWith(".mtl")) { 41 | fileName = fileName.substring(0, fileName.length() - 4); 42 | } 43 | 44 | String objName = fileName + ".obj"; 45 | String mtlName = fileName + ".mtl"; 46 | 47 | obj = obj.replace(MTL_NAME, mtlName); 48 | objStream = null; 49 | 50 | if (parent == null) { 51 | FileUtil.write(Paths.get(objName), obj); 52 | FileUtil.write(Paths.get(mtlName), mtl); 53 | } else { 54 | FileUtil.write(Paths.get(parent.toString(), objName), obj); 55 | FileUtil.write(Paths.get(parent.toString(), mtlName), mtl); 56 | } 57 | 58 | } 59 | 60 | public String getObj() { 61 | return this.obj; 62 | } 63 | 64 | public String getMtl() { 65 | return this.mtl; 66 | } 67 | 68 | public InputStream getObjStream() { 69 | if (objStream == null) { 70 | objStream = new ByteArrayInputStream(obj.getBytes(StandardCharsets.UTF_8)); 71 | } 72 | 73 | return objStream; 74 | } 75 | 76 | public InputStream getMtlStream() { 77 | if (mtlStream == null) { 78 | mtlStream = new ByteArrayInputStream(mtl.getBytes(StandardCharsets.UTF_8)); 79 | } 80 | 81 | return mtlStream; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/AdvancingFrontIndex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * AdvancingFrontIndex.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | class AdvancingFrontIndex { 64 | double _min, _max; 65 | IndexNode _root; 66 | 67 | public AdvancingFrontIndex(double min, double max, int depth) { 68 | if (depth > 5) 69 | depth = 5; 70 | _root = createIndex(depth); 71 | } 72 | 73 | private IndexNode createIndex(int n) { 74 | IndexNode node = null; 75 | if (n > 0) { 76 | node = new IndexNode(); 77 | node.bigger = createIndex(n - 1); 78 | node.smaller = createIndex(n - 1); 79 | } 80 | return node; 81 | } 82 | 83 | public A fetchAndRemoveIndex(A key) { 84 | return null; 85 | } 86 | 87 | public A fetchAndInsertIndex(A key) { 88 | return null; 89 | } 90 | 91 | class IndexNode { 92 | V value; 93 | IndexNode smaller; 94 | IndexNode bigger; 95 | double range; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/AdvancingFrontNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * AdvancingFrontNode.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | class AdvancingFrontNode { 34 | protected AdvancingFrontNode next = null; 35 | protected AdvancingFrontNode prev = null; 36 | 37 | protected final Double key; // XXX: BST 38 | protected final double value; 39 | protected final TriangulationPoint point; 40 | protected DelaunayTriangle triangle; 41 | 42 | public AdvancingFrontNode(TriangulationPoint point) { 43 | this.point = point; 44 | value = point.getX(); 45 | key = Double.valueOf(value); // XXX: BST 46 | } 47 | 48 | public AdvancingFrontNode getNext() { 49 | return next; 50 | } 51 | 52 | public AdvancingFrontNode getPrevious() { 53 | return prev; 54 | } 55 | 56 | public TriangulationPoint getPoint() { 57 | return point; 58 | } 59 | 60 | public DelaunayTriangle getTriangle() { 61 | return triangle; 62 | } 63 | 64 | public boolean hasNext() { 65 | return next != null; 66 | } 67 | 68 | public boolean hasPrevious() { 69 | return prev != null; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/CoordinateTransform.java: -------------------------------------------------------------------------------- 1 | /** 2 | * CoordinateTransform.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | import java.util.List; 64 | 65 | abstract interface CoordinateTransform { 66 | public abstract void transform(Point p, Point store); 67 | 68 | public abstract void transform(Point p); 69 | 70 | public abstract void transform(List list); 71 | } 72 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/DTSweepPointComparator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * DTSweepPointComparator.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | import java.util.Comparator; 64 | 65 | class DTSweepPointComparator implements Comparator { 66 | @Override 67 | public int compare(TriangulationPoint p1, TriangulationPoint p2) { 68 | if (p1.getY() < p2.getY()) { 69 | return -1; 70 | } else if (p1.getY() > p2.getY()) { 71 | return 1; 72 | } else { 73 | if (p1.getX() < p2.getX()) { 74 | return -1; 75 | } else if (p1.getX() > p2.getX()) { 76 | return 1; 77 | } else { 78 | return 0; 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/Edge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Edge.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | abstract class Edge { 64 | protected A p; 65 | protected A q; 66 | 67 | public A getP() { 68 | return p; 69 | } 70 | 71 | public A getQ() { 72 | return q; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/NoTransform.java: -------------------------------------------------------------------------------- 1 | /** 2 | * NoTransform.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | import java.util.List; 64 | 65 | class NoTransform implements CoordinateTransform { 66 | public void transform(Point p, Point store) { 67 | store.set(p.getX(), p.getY(), p.getZ()); 68 | } 69 | 70 | public void transform(Point p) {} 71 | 72 | public void transform(List list) {} 73 | } 74 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/Point.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Point.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | abstract class Point { 64 | public abstract double getX(); 65 | 66 | public abstract double getY(); 67 | 68 | public abstract double getZ(); 69 | 70 | public abstract float getXf(); 71 | 72 | public abstract float getYf(); 73 | 74 | public abstract float getZf(); 75 | 76 | public abstract void set(double x, double y, double z); 77 | 78 | protected static int calculateHashCode(double x, double y, double z) { 79 | int result = 17; 80 | 81 | final long a = Double.doubleToLongBits(x); 82 | result += 31 * result + (int) (a ^ (a >>> 32)); 83 | 84 | final long b = Double.doubleToLongBits(y); 85 | result += 31 * result + (int) (b ^ (b >>> 32)); 86 | 87 | final long c = Double.doubleToLongBits(z); 88 | result += 31 * result + (int) (c ^ (c >>> 32)); 89 | 90 | return result; 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/PointOnEdgeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * PointOnEdgeException.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | class PointOnEdgeException extends RuntimeException { 64 | 65 | /** 66 | * 67 | */ 68 | private static final long serialVersionUID = 1L; 69 | 70 | public PointOnEdgeException(String msg) { 71 | super(msg); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/PolygonPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * PolygonPoint.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | /* Poly2Tri 33 | * Copyright (c) 2009-2010, Poly2Tri Contributors 34 | * http://code.google.com/p/poly2tri/ 35 | * 36 | * All rights reserved. 37 | * 38 | * Redistribution and use in source and binary forms, with or without modification, 39 | * are permitted provided that the following conditions are met: 40 | * 41 | * * Redistributions of source code must retain the above copyright notice, 42 | * this list of conditions and the following disclaimer. 43 | * * Redistributions in binary form must reproduce the above copyright notice, 44 | * this list of conditions and the following disclaimer in the documentation 45 | * and/or other materials provided with the distribution. 46 | * * Neither the name of Poly2Tri nor the names of its contributors may be 47 | * used to endorse or promote products derived from this software without specific 48 | * prior written permission. 49 | * 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 54 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 55 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 56 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 57 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 58 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 59 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 60 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 | */ 62 | 63 | class PolygonPoint extends TPoint { 64 | protected PolygonPoint _next; 65 | protected PolygonPoint _previous; 66 | 67 | public PolygonPoint(double x, double y) { 68 | super(x, y); 69 | } 70 | 71 | public PolygonPoint(double x, double y, double z) { 72 | super(x, y, z); 73 | } 74 | 75 | public void setPrevious(PolygonPoint p) { 76 | _previous = p; 77 | } 78 | 79 | public void setNext(PolygonPoint p) { 80 | _next = p; 81 | } 82 | 83 | public PolygonPoint getNext() { 84 | return _next; 85 | } 86 | 87 | public PolygonPoint getPrevious() { 88 | return _previous; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/PolygonSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * PolygonSet.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | import java.util.ArrayList; 64 | import java.util.List; 65 | 66 | class PolygonSet { 67 | protected ArrayList _polygons = new ArrayList<>(); 68 | 69 | public PolygonSet() {} 70 | 71 | public PolygonSet(Polygon poly) { 72 | _polygons.add(poly); 73 | } 74 | 75 | public void add(Polygon p) { 76 | _polygons.add(p); 77 | } 78 | 79 | public List getPolygons() { 80 | return _polygons; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/Triangulatable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Triangulatable.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | import java.util.List; 64 | 65 | interface Triangulatable { 66 | /** 67 | * Preparations needed before triangulation start should be handled here 68 | */ 69 | public void prepareTriangulation(TriangulationContext tcx); 70 | 71 | public List getTriangles(); 72 | 73 | public List getPoints(); 74 | 75 | public void addTriangle(DelaunayTriangle t); 76 | 77 | public void addTriangles(List list); 78 | 79 | public void clearTriangulation(); 80 | 81 | public TriangulationMode getTriangulationMode(); 82 | } 83 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/TriangulationAlgorithm.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TriangulationAlgorithm.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | public enum TriangulationAlgorithm { 64 | DTSweep 65 | } 66 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/TriangulationConstraint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TriangulationConstraint.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | /* Poly2Tri 33 | * Copyright (c) 2009-2010, Poly2Tri Contributors 34 | * http://code.google.com/p/poly2tri/ 35 | * 36 | * All rights reserved. 37 | * 38 | * Redistribution and use in source and binary forms, with or without modification, 39 | * are permitted provided that the following conditions are met: 40 | * 41 | * * Redistributions of source code must retain the above copyright notice, 42 | * this list of conditions and the following disclaimer. 43 | * * Redistributions in binary form must reproduce the above copyright notice, 44 | * this list of conditions and the following disclaimer in the documentation 45 | * and/or other materials provided with the distribution. 46 | * * Neither the name of Poly2Tri nor the names of its contributors may be 47 | * used to endorse or promote products derived from this software without specific 48 | * prior written permission. 49 | * 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 54 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 55 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 56 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 57 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 58 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 59 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 60 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 | */ 62 | 63 | /** 64 | * Forces a triangle edge between two points p and q when triangulating. For 65 | * example used to enforce Polygon Edges during a polygon triangulation. 66 | * 67 | * @author Thomas ???, thahlen@gmail.com 68 | */ 69 | class TriangulationConstraint { 70 | protected TriangulationPoint p; 71 | protected TriangulationPoint q; 72 | 73 | public TriangulationPoint getP() { 74 | return p; 75 | } 76 | 77 | public TriangulationPoint getQ() { 78 | return q; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/TriangulationDebugContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TriangulationDebugContext.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | abstract class TriangulationDebugContext { 64 | protected TriangulationContext _tcx; 65 | 66 | public TriangulationDebugContext(TriangulationContext tcx) { 67 | _tcx = tcx; 68 | } 69 | 70 | public abstract void clear(); 71 | } 72 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/TriangulationMode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TriangulationMode.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | enum TriangulationMode { 64 | UNCONSTRAINED, 65 | CONSTRAINED, 66 | POLYGON; 67 | } 68 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/TriangulationProcessEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TriangulationProcessEvent.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | enum TriangulationProcessEvent { 64 | Started, 65 | Waiting, 66 | Failed, 67 | Aborted, 68 | Done 69 | } 70 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/TriangulationProcessListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TriangulationProcessListener.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | interface TriangulationProcessListener { 64 | public void triangulationEvent(TriangulationProcessEvent e, Triangulatable unit); 65 | } 66 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/Tuple2.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tuple2.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | class Tuple2 { 64 | public A a; 65 | public B b; 66 | 67 | public Tuple2(A a, B b) { 68 | this.a = a; 69 | this.b = b; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/org/poly2tri/Tuple3.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tuple3.java 3 | * 4 | * Copyright 2014-2014 Michael Hoffer . All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Michael Hoffer "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are those of the 27 | * authors and should not be interpreted as representing official policies, either expressed 28 | * or implied, of Michael Hoffer . 29 | */ 30 | 31 | package eu.mihosoft.vrl.v3d.ext.org.poly2tri; 32 | 33 | /* Poly2Tri 34 | * Copyright (c) 2009-2010, Poly2Tri Contributors 35 | * http://code.google.com/p/poly2tri/ 36 | * 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 42 | * * Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * * Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * * Neither the name of Poly2Tri nor the names of its contributors may be 48 | * used to endorse or promote products derived from this software without specific 49 | * prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 55 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 56 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 58 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 59 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 60 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 61 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | */ 63 | class Tuple3 { 64 | public A a; 65 | public B b; 66 | public C c; 67 | 68 | public Tuple3(A a, B b, C c) { 69 | this.a = a; 70 | this.b = b; 71 | this.c = c; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/COPYRIGHT: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright John E. Lloyd, 2004. All rights reserved. Permission to use, 3 | * copy, modify and redistribute is granted, provided that this copyright 4 | * notice is retained and the author is given credit whenever appropriate. 5 | * 6 | * This software is distributed "as is", without any warranty, including 7 | * any implied warranty of merchantability or fitness for a particular 8 | * use. The author assumes no responsibility for, and shall not be liable 9 | * for, any special, indirect, or consequential damages, or any damages 10 | * whatsoever, arising out of or in connection with the use of this 11 | * software. 12 | */ 13 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/FaceList.java: -------------------------------------------------------------------------------- 1 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 2 | 3 | /** 4 | * Maintains a single-linked list of faces for use by QuickHull3D 5 | */ 6 | class FaceList { 7 | private Face head; 8 | private Face tail; 9 | 10 | /** 11 | * Clears this list. 12 | */ 13 | public void clear() { 14 | head = tail = null; 15 | } 16 | 17 | /** 18 | * Adds a vertex to the end of this list. 19 | */ 20 | public void add(Face vtx) { 21 | if (head == null) { 22 | head = vtx; 23 | } else { 24 | tail.next = vtx; 25 | } 26 | vtx.next = null; 27 | tail = vtx; 28 | } 29 | 30 | public Face first() { 31 | return head; 32 | } 33 | 34 | /** 35 | * Returns true if this list is empty. 36 | */ 37 | public boolean isEmpty() { 38 | return head == null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/HullUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import com.perunlabs.jsolid.d3.Vector3; 12 | 13 | import eu.mihosoft.vrl.v3d.CSG; 14 | import eu.mihosoft.vrl.v3d.Polygon; 15 | 16 | /** 17 | * 18 | * @author Michael Hoffer <info@michaelhoffer.de> 19 | */ 20 | public class HullUtil { 21 | 22 | private HullUtil() { 23 | throw new AssertionError("Don't instantiate me!", null); 24 | } 25 | 26 | public static CSG hull(List points) { 27 | List polygons = hullPolygons(points); 28 | return CSG.fromPolygons(polygons); 29 | } 30 | 31 | public static List hullPolygons(List points) { 32 | Point3d[] hullPoints = points.stream().map((vec) -> new Point3d(vec.x, vec.y, vec.z)).toArray( 33 | Point3d[]::new); 34 | 35 | QuickHull3D hull = new QuickHull3D(); 36 | hull.build(hullPoints); 37 | hull.triangulate(); 38 | 39 | int[][] faces = hull.getFaces(); 40 | 41 | List polygons = new ArrayList<>(); 42 | 43 | List vertices = new ArrayList<>(); 44 | 45 | for (int[] verts : faces) { 46 | 47 | for (int i : verts) { 48 | vertices.add(points.get(hull.getVertexPointIndices()[i])); 49 | } 50 | 51 | polygons.add(Polygon.fromPoints(vertices)); 52 | 53 | vertices.clear(); 54 | } 55 | return polygons; 56 | } 57 | 58 | public static CSG hull(CSG csg) { 59 | 60 | List points = new ArrayList<>(csg.getPolygons().size() * 3); 61 | 62 | csg.getPolygons().forEach((p) -> p.vertices.forEach((v) -> points.add(v))); 63 | 64 | return hull(points); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/InternalErrorException.java: -------------------------------------------------------------------------------- 1 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 2 | 3 | /** 4 | * Exception thrown when QuickHull3D encounters an internal error. 5 | */ 6 | class InternalErrorException extends RuntimeException { 7 | public InternalErrorException(String msg) { 8 | super(msg); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/Point3d.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright John E. Lloyd, 2004. All rights reserved. Permission to use, 3 | * copy, modify and redistribute is granted, provided that this copyright 4 | * notice is retained and the author is given credit whenever appropriate. 5 | * 6 | * This software is distributed "as is", without any warranty, including 7 | * any implied warranty of merchantability or fitness for a particular 8 | * use. The author assumes no responsibility for, and shall not be liable 9 | * for, any special, indirect, or consequential damages, or any damages 10 | * whatsoever, arising out of or in connection with the use of this 11 | * software. 12 | */ 13 | 14 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 15 | 16 | /** 17 | * A three-element spatial point. 18 | * 19 | * The only difference between a point and a vector is in the the way it is 20 | * transformed by an affine transformation. Since the transform method is not 21 | * included in this reduced implementation for QuickHull3D, the difference is 22 | * purely academic. 23 | * 24 | * @author John E. Lloyd, Fall 2004 25 | */ 26 | public class Point3d extends Vector3d { 27 | /** 28 | * Creates a Point3d and initializes it to zero. 29 | */ 30 | public Point3d() {} 31 | 32 | /** 33 | * Creates a Point3d by copying a vector 34 | * 35 | * @param v 36 | * vector to be copied 37 | */ 38 | public Point3d(Vector3d v) { 39 | set(v); 40 | } 41 | 42 | /** 43 | * Creates a Point3d with the supplied element values. 44 | * 45 | * @param x 46 | * first element 47 | * @param y 48 | * second element 49 | * @param z 50 | * third element 51 | */ 52 | public Point3d(double x, double y, double z) { 53 | set(x, y, z); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/SimpleExample.java: -------------------------------------------------------------------------------- 1 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 2 | 3 | /** 4 | * Simple example usage of QuickHull3D. Run as the command 5 | * 6 | *
 7 |  *   java quickhull3d.SimpleExample
 8 |  * 
9 | */ 10 | class SimpleExample { 11 | /** 12 | * Run for a simple demonstration of QuickHull3D. 13 | */ 14 | public static void main(String[] args) { 15 | // x y z coordinates of 6 points 16 | Point3d[] points = new Point3d[] { new Point3d(0.0, 0.0, 0.0), 17 | new Point3d(1.0, 0.5, 0.0), 18 | new Point3d(2.0, 0.0, 0.0), 19 | new Point3d(0.5, 0.5, 0.5), 20 | new Point3d(0.0, 0.0, 2.0), 21 | new Point3d(0.1, 0.2, 0.3), 22 | new Point3d(0.0, 2.0, 0.0), 23 | }; 24 | 25 | QuickHull3D hull = new QuickHull3D(); 26 | hull.build(points); 27 | 28 | System.out.println("Vertices:"); 29 | Point3d[] vertices = hull.getVertices(); 30 | for (int i = 0; i < vertices.length; i++) { 31 | Point3d pnt = vertices[i]; 32 | System.out.println(pnt.x + " " + pnt.y + " " + pnt.z); 33 | } 34 | 35 | System.out.println("Faces:"); 36 | int[][] faceIndices = hull.getFaces(); 37 | for (int i = 0; i < vertices.length; i++) { 38 | for (int k = 0; k < faceIndices[i].length; k++) { 39 | System.out.print(faceIndices[i][k] + " "); 40 | } 41 | System.out.println(""); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/Vertex.java: -------------------------------------------------------------------------------- 1 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 2 | 3 | /** 4 | * Represents vertices of the hull, as well as the points from which it is 5 | * formed. 6 | * 7 | * @author John E. Lloyd, Fall 2004 8 | */ 9 | class Vertex { 10 | /** 11 | * Spatial point associated with this vertex. 12 | */ 13 | Point3d pnt; 14 | 15 | /** 16 | * Back index into an array. 17 | */ 18 | int index; 19 | 20 | /** 21 | * List forward link. 22 | */ 23 | Vertex prev; 24 | 25 | /** 26 | * List backward link. 27 | */ 28 | Vertex next; 29 | 30 | /** 31 | * Current face that this vertex is outside of. 32 | */ 33 | Face face; 34 | 35 | /** 36 | * Constructs a vertex and sets its coordinates to 0. 37 | */ 38 | public Vertex() { 39 | pnt = new Point3d(); 40 | } 41 | 42 | /** 43 | * Constructs a vertex with the specified coordinates and index. 44 | */ 45 | public Vertex(double x, double y, double z, int idx) { 46 | pnt = new Point3d(x, y, z); 47 | index = idx; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/VertexList.java: -------------------------------------------------------------------------------- 1 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 2 | 3 | /** 4 | * Maintains a double-linked list of vertices for use by QuickHull3D 5 | */ 6 | class VertexList { 7 | private Vertex head; 8 | private Vertex tail; 9 | 10 | /** 11 | * Clears this list. 12 | */ 13 | public void clear() { 14 | head = tail = null; 15 | } 16 | 17 | /** 18 | * Adds a vertex to the end of this list. 19 | */ 20 | public void add(Vertex vtx) { 21 | if (head == null) { 22 | head = vtx; 23 | } else { 24 | tail.next = vtx; 25 | } 26 | vtx.prev = tail; 27 | vtx.next = null; 28 | tail = vtx; 29 | } 30 | 31 | /** 32 | * Adds a chain of vertices to the end of this list. 33 | */ 34 | public void addAll(Vertex vtx) { 35 | if (head == null) { 36 | head = vtx; 37 | } else { 38 | tail.next = vtx; 39 | } 40 | vtx.prev = tail; 41 | while (vtx.next != null) { 42 | vtx = vtx.next; 43 | } 44 | tail = vtx; 45 | } 46 | 47 | /** 48 | * Deletes a vertex from this list. 49 | */ 50 | public void delete(Vertex vtx) { 51 | if (vtx.prev == null) { 52 | head = vtx.next; 53 | } else { 54 | vtx.prev.next = vtx.next; 55 | } 56 | if (vtx.next == null) { 57 | tail = vtx.prev; 58 | } else { 59 | vtx.next.prev = vtx.prev; 60 | } 61 | } 62 | 63 | /** 64 | * Deletes a chain of vertices from this list. 65 | */ 66 | public void delete(Vertex vtx1, Vertex vtx2) { 67 | if (vtx1.prev == null) { 68 | head = vtx2.next; 69 | } else { 70 | vtx1.prev.next = vtx2.next; 71 | } 72 | if (vtx2.next == null) { 73 | tail = vtx1.prev; 74 | } else { 75 | vtx2.next.prev = vtx1.prev; 76 | } 77 | } 78 | 79 | /** 80 | * Inserts a vertex into this list before another specificed vertex. 81 | */ 82 | public void insertBefore(Vertex vtx, Vertex next) { 83 | vtx.prev = next.prev; 84 | if (next.prev == null) { 85 | head = vtx; 86 | } else { 87 | next.prev.next = vtx; 88 | } 89 | vtx.next = next; 90 | next.prev = vtx; 91 | } 92 | 93 | /** 94 | * Returns the first element in this list. 95 | */ 96 | public Vertex first() { 97 | return head; 98 | } 99 | 100 | /** 101 | * Returns true if this list is empty. 102 | */ 103 | public boolean isEmpty() { 104 | return head == null; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/CircleApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.circle; 4 | import static org.testory.Testory.thenThrown; 5 | import static org.testory.Testory.when; 6 | 7 | import org.junit.Test; 8 | 9 | public class CircleApiTest { 10 | @Test 11 | public void negative_radius_throws_exception() throws Exception { 12 | when(() -> circle(-1)); 13 | thenThrown(IllegalArgumentException.class); 14 | } 15 | 16 | @Test 17 | public void zero_radius_throws_exception() throws Exception { 18 | when(() -> circle(-1)); 19 | thenThrown(IllegalArgumentException.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/ConvexHullApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.convexHull; 4 | import static com.perunlabs.jsolid.JSolid.v; 5 | import static org.testory.Testory.thenThrown; 6 | import static org.testory.Testory.when; 7 | 8 | import org.junit.Test; 9 | 10 | public class ConvexHullApiTest { 11 | @Test 12 | public void zero_arguments_throws_exception() throws Exception { 13 | when(() -> convexHull()); 14 | thenThrown(IllegalArgumentException.class); 15 | } 16 | 17 | @Test 18 | public void one_argument_throws_exception() throws Exception { 19 | when(() -> convexHull(v(1, 1, 1))); 20 | thenThrown(IllegalArgumentException.class); 21 | } 22 | 23 | @Test 24 | public void two_arguments_throws_exception() throws Exception { 25 | when(() -> convexHull(v(1, 1, 1), v(2, 2, 2))); 26 | thenThrown(IllegalArgumentException.class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/ConvexPolygonApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.convexPolygon; 4 | import static com.perunlabs.jsolid.JSolid.v; 5 | import static org.testory.Testory.thenThrown; 6 | import static org.testory.Testory.when; 7 | 8 | import org.junit.Test; 9 | 10 | public class ConvexPolygonApiTest { 11 | @Test 12 | public void zero_vertexes_throws_exception() throws Exception { 13 | when(() -> convexPolygon()); 14 | thenThrown(IllegalArgumentException.class); 15 | } 16 | 17 | @Test 18 | public void one_vertex_throws_exception() throws Exception { 19 | when(() -> convexPolygon(v(1, 1))); 20 | thenThrown(IllegalArgumentException.class); 21 | } 22 | 23 | @Test 24 | public void two_vertexes_throws_exception() throws Exception { 25 | when(() -> convexPolygon(v(1, 1), v(2, 2))); 26 | thenThrown(IllegalArgumentException.class); 27 | } 28 | 29 | @Test 30 | public void null_argument_causes_exception() throws Exception { 31 | when(() -> convexPolygon(v(1, 1), v(2, 2), null)); 32 | thenThrown(NullPointerException.class); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/CuboidApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.cuboid; 4 | import static com.perunlabs.jsolid.JSolid.x; 5 | import static org.testory.Testory.thenThrown; 6 | import static org.testory.Testory.when; 7 | 8 | import org.junit.Test; 9 | 10 | public class CuboidApiTest { 11 | @Test 12 | public void negative_corner_throws_exception() throws Exception { 13 | when(() -> cuboid(1, 2, 3).cornerR(x(), -1)); 14 | thenThrown(IllegalArgumentException.class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/CylinderApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.cylinder; 4 | import static com.perunlabs.jsolid.JSolid.funnel; 5 | import static org.testory.Testory.thenReturned; 6 | import static org.testory.Testory.thenThrown; 7 | import static org.testory.Testory.when; 8 | 9 | import org.junit.Test; 10 | 11 | public class CylinderApiTest { 12 | @Test 13 | public void negative_initial_segment_length_throws_exception() throws Exception { 14 | when(() -> cylinder(3, -1)); 15 | thenThrown(IllegalArgumentException.class); 16 | } 17 | 18 | @Test 19 | public void negative_segment_length_throws_exception() throws Exception { 20 | when(() -> cylinder(3, 1).addSegment(3, -1)); 21 | thenThrown(IllegalArgumentException.class); 22 | } 23 | 24 | @Test 25 | public void negative_segment_length_without_radius_throws_exception() throws Exception { 26 | when(() -> cylinder(3, 1).addSegment(-1)); 27 | thenThrown(IllegalArgumentException.class); 28 | } 29 | 30 | @Test 31 | public void negative_initial_radius_throws_exception() throws Exception { 32 | when(() -> cylinder(-3, 1)); 33 | thenThrown(IllegalArgumentException.class); 34 | } 35 | 36 | @Test 37 | public void negative_segment_radius_throws_exception() throws Exception { 38 | when(() -> cylinder(3, 1).addSegment(-3, 1)); 39 | thenThrown(IllegalArgumentException.class); 40 | } 41 | 42 | @Test 43 | public void zero_initial_radius_is_allowed() throws Exception { 44 | when(() -> cylinder(0, 1)); 45 | thenReturned(); 46 | } 47 | 48 | @Test 49 | public void zero_segment_radius_throws_exception() throws Exception { 50 | when(() -> cylinder(3, 1).addSegment(0, 1)); 51 | thenThrown(IllegalArgumentException.class); 52 | } 53 | 54 | @Test 55 | public void negative_initial_funnel_length_throws_exception() throws Exception { 56 | when(() -> funnel(3, 2, -1)); 57 | thenThrown(IllegalArgumentException.class); 58 | } 59 | 60 | @Test 61 | public void negative_funnel_length_throws_exception() throws Exception { 62 | when(() -> cylinder(3, 1).addFunnel(2, -1)); 63 | thenThrown(IllegalArgumentException.class); 64 | } 65 | 66 | @Test 67 | public void negative_initial_funnel_radius_start_throws_exception() throws Exception { 68 | when(() -> funnel(-3, 2, 1)); 69 | thenThrown(IllegalArgumentException.class); 70 | } 71 | 72 | @Test 73 | public void negative_initial_funnel_radius_end_throws_exception() throws Exception { 74 | when(() -> funnel(3, -2, 1)); 75 | thenThrown(IllegalArgumentException.class); 76 | } 77 | 78 | @Test 79 | public void negative_funnel_radius_throws_exception() throws Exception { 80 | when(() -> cylinder(3, 1).addFunnel(-2, 1)); 81 | thenThrown(IllegalArgumentException.class); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/EmptyTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.cuboid; 4 | import static org.testory.Testory.given; 5 | import static org.testory.Testory.thenReturned; 6 | import static org.testory.Testory.when; 7 | 8 | import org.junit.Test; 9 | 10 | import com.perunlabs.jsolid.d3.Cuboid; 11 | import com.perunlabs.jsolid.d3.Solid; 12 | 13 | public class EmptyTest { 14 | private Cuboid solid; 15 | 16 | @Test 17 | public void subtracting_empty_solid_does_not_change_anything() throws Exception { 18 | given(solid = cuboid(1, 2, 3)); 19 | when(solid.sub(empty()).sides()); 20 | thenReturned(solid.sides()); 21 | } 22 | 23 | @Test 24 | public void subtracting_from_empty_solid_returns_empty_solid() throws Exception { 25 | given(solid = cuboid(1, 2, 3)); 26 | when(empty().sub(solid).sides()); 27 | thenReturned(empty().sides()); 28 | } 29 | 30 | @Test 31 | public void adding_empty_solid_does_not_change_anything() throws Exception { 32 | given(solid = cuboid(1, 2, 3)); 33 | when(solid.add(empty()).sides()); 34 | thenReturned(solid.sides()); 35 | } 36 | 37 | @Test 38 | public void adding_to_empty_solid_returns_added_solid() throws Exception { 39 | given(solid = cuboid(1, 2, 3)); 40 | when(empty().add(solid).sides()); 41 | thenReturned(solid.sides()); 42 | } 43 | 44 | @Test 45 | public void intersecting_with_empty_solid_returns_empty_solid() throws Exception { 46 | when(cuboid(1, 1, 1).intersect(empty()).sides()); 47 | thenReturned(empty().sides()); 48 | } 49 | 50 | @Test 51 | public void intersecting_empty_solid_with_anything_returns_empty_solid() throws Exception { 52 | when(empty().intersect(cuboid(1, 1, 1)).sides()); 53 | thenReturned(empty().sides()); 54 | } 55 | 56 | private Solid empty() { 57 | return cuboid(1, 1, 1).sub(cuboid(9, 9, 9)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/PrismApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.circle; 4 | import static com.perunlabs.jsolid.JSolid.prism; 5 | import static org.testory.Testory.thenThrown; 6 | import static org.testory.Testory.when; 7 | 8 | import org.junit.Test; 9 | 10 | public class PrismApiTest { 11 | @Test 12 | public void null_base_argument_causes_exception() throws Exception { 13 | when(() -> prism(null, 1)); 14 | thenThrown(NullPointerException.class); 15 | } 16 | 17 | @Test 18 | public void null_range_argument_causes_exception() throws Exception { 19 | when(() -> prism(circle(1), null)); 20 | thenThrown(NullPointerException.class); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/RectangleApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.rectangle; 4 | import static org.testory.Testory.thenThrown; 5 | import static org.testory.Testory.when; 6 | 7 | import org.junit.Test; 8 | 9 | public class RectangleApiTest { 10 | @Test 11 | public void negative_corner_throws_exception() throws Exception { 12 | when(() -> rectangle(1, 2).cornerR(-1)); 13 | thenThrown(IllegalArgumentException.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/RegularPolygonApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.regularPolygon; 4 | import static org.testory.Testory.thenThrown; 5 | import static org.testory.Testory.when; 6 | 7 | import org.junit.Test; 8 | 9 | public class RegularPolygonApiTest { 10 | @Test 11 | public void negative_radius_throws_exception() throws Exception { 12 | when(() -> regularPolygon(-1, 10)); 13 | thenThrown(IllegalArgumentException.class); 14 | } 15 | 16 | @Test 17 | public void zero_radius_throws_exception() throws Exception { 18 | when(() -> regularPolygon(0, 10)); 19 | thenThrown(IllegalArgumentException.class); 20 | } 21 | 22 | @Test 23 | public void negative_vertex_count_throws_exception() throws Exception { 24 | when(() -> regularPolygon(10, -1)); 25 | thenThrown(IllegalArgumentException.class); 26 | } 27 | 28 | @Test 29 | public void zero_vertex_count_throws_exception() throws Exception { 30 | when(() -> regularPolygon(10, 0)); 31 | thenThrown(IllegalArgumentException.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/TransformApiTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid; 2 | 3 | import static com.perunlabs.jsolid.JSolid.cuboid; 4 | import static com.perunlabs.jsolid.JSolid.degrees; 5 | import static com.perunlabs.jsolid.JSolid.x; 6 | import static com.perunlabs.jsolid.JSolid.y; 7 | import static org.testory.Testory.any; 8 | import static org.testory.Testory.given; 9 | import static org.testory.Testory.spy; 10 | import static org.testory.Testory.thenCalledNever; 11 | import static org.testory.Testory.when; 12 | 13 | import org.junit.Test; 14 | 15 | import com.perunlabs.jsolid.d3.Matrix4; 16 | import com.perunlabs.jsolid.d3.Vector3; 17 | 18 | public class TransformApiTest { 19 | private Matrix4 matrix; 20 | private Matrix4 matrix2; 21 | 22 | @Test 23 | public void matrix_transforms_are_multiplied_and_result_matrix_is_applied() throws Exception { 24 | given(matrix = spy(x().rotateMatrix(degrees(90)))); 25 | given(matrix2 = spy(y().rotateMatrix(degrees(90)))); 26 | when(cuboid(1, 2, 3).apply(matrix).apply(matrix).vertexes()); 27 | thenCalledNever(matrix).mul(any(Vector3.class)); 28 | thenCalledNever(matrix2).mul(any(Vector3.class)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d1/AngleTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d1; 2 | 3 | import static com.perunlabs.jsolid.JSolid.degrees; 4 | import static com.perunlabs.jsolid.JSolid.perigons; 5 | import static com.perunlabs.jsolid.JSolid.radians; 6 | import static java.lang.Math.PI; 7 | import static org.testory.Testory.given; 8 | import static org.testory.Testory.thenEqual; 9 | import static org.testory.Testory.thenReturned; 10 | import static org.testory.Testory.when; 11 | 12 | import org.junit.Test; 13 | 14 | public class AngleTest { 15 | private Angle angle; 16 | private Angle angle2; 17 | 18 | @Test 19 | public void one_perigon_equals_360_degrees() throws Exception { 20 | given(angle = perigons(1)); 21 | when(() -> angle.degrees()); 22 | thenReturned(360.0); 23 | } 24 | 25 | @Test 26 | public void one_perigon_equals_2_pi_radians() throws Exception { 27 | given(angle = perigons(1)); 28 | when(() -> angle.radians()); 29 | thenReturned(2 * PI); 30 | } 31 | 32 | @Test 33 | public void _360_degrees_equals_one_perigon() throws Exception { 34 | given(angle = degrees(360)); 35 | when(() -> angle.perigon()); 36 | thenReturned(1.0); 37 | } 38 | 39 | @Test 40 | public void _360_degrees_equals_2_pi_radians() throws Exception { 41 | given(angle = degrees(360)); 42 | when(() -> angle.radians()); 43 | thenReturned(2 * PI); 44 | } 45 | 46 | @Test 47 | public void _2_PI_radians_equals_1_perigon() throws Exception { 48 | given(angle = radians(2 * PI)); 49 | when(() -> angle.perigon()); 50 | thenReturned(1.0); 51 | } 52 | 53 | @Test 54 | public void _2_PI_radians_equals_360_degrees() throws Exception { 55 | given(angle = radians(2 * PI)); 56 | when(() -> angle.degrees()); 57 | thenReturned(360.0); 58 | } 59 | 60 | @Test 61 | public void equal_angles() throws Exception { 62 | given(angle = perigons(3)); 63 | given(angle2 = perigons(3)); 64 | thenEqual(angle, angle2); 65 | } 66 | 67 | @Test 68 | public void not_equal_angles() throws Exception { 69 | given(angle = perigons(3)); 70 | given(angle2 = perigons(2)); 71 | when(angle.equals(angle2)); 72 | thenReturned(false); 73 | } 74 | 75 | @Test 76 | public void equal_angles_have_equal_hashes() throws Exception { 77 | given(angle = perigons(3)); 78 | given(angle2 = perigons(3)); 79 | thenEqual(angle.hashCode(), angle2.hashCode()); 80 | } 81 | 82 | @Test 83 | public void to_string() throws Exception { 84 | given(angle = perigons(12.3)); 85 | when(() -> angle.toString()); 86 | thenReturned("12.3 perigons"); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d2/CircleTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static com.perunlabs.jsolid.JSolid.circle; 4 | import static org.testory.Testory.given; 5 | import static org.testory.Testory.thenReturned; 6 | import static org.testory.Testory.when; 7 | 8 | import org.junit.Test; 9 | 10 | public class CircleTest { 11 | private Circle circle; 12 | 13 | @Test 14 | public void circle_vertexes_are_convex_and_counter_clockwise() throws Exception { 15 | given(circle = circle(20)); 16 | when(Geometry.isConvexCounterClockwisePolygon(circle.vertexes())); 17 | thenReturned(true); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d2/GeometryTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static com.perunlabs.jsolid.JSolid.v; 4 | import static com.perunlabs.jsolid.d2.Geometry.isConvexCounterClockwisePolygon; 5 | import static java.util.Arrays.asList; 6 | import static org.testory.Testory.thenReturned; 7 | import static org.testory.Testory.thenThrown; 8 | import static org.testory.Testory.when; 9 | 10 | import org.junit.Test; 11 | 12 | public class GeometryTest { 13 | 14 | @Test 15 | public void is_convex_throws_exception_for_empty_vertex_list() throws Exception { 16 | when(() -> isConvexCounterClockwisePolygon(asList())); 17 | thenThrown(IllegalArgumentException.class); 18 | } 19 | 20 | @Test 21 | public void is_convex_throws_exception_for_single_vertex() throws Exception { 22 | when(() -> isConvexCounterClockwisePolygon(asList(v(1, 2)))); 23 | thenThrown(IllegalArgumentException.class); 24 | } 25 | 26 | @Test 27 | public void is_convex_throws_exception_for_two_vertexes() throws Exception { 28 | when(() -> isConvexCounterClockwisePolygon(asList(v(1, 2), v(3, 4)))); 29 | thenThrown(IllegalArgumentException.class); 30 | } 31 | 32 | @Test 33 | public void triangle_is_convex() throws Exception { 34 | when(() -> isConvexCounterClockwisePolygon(asList(v(0, 0), v(3, 0), v(0, 4)))); 35 | thenReturned(true); 36 | } 37 | 38 | @Test 39 | public void triangle_with_clockwise_vertexes_is_not_convex() throws Exception { 40 | when(() -> isConvexCounterClockwisePolygon(asList(v(0, 0), v(0, 4), v(3, 0)))); 41 | thenReturned(false); 42 | } 43 | 44 | @Test 45 | public void double_triangle_spiral_is_not_convex() throws Exception { 46 | when(() -> isConvexCounterClockwisePolygon(asList( 47 | v(0, 0), v(3, 0), v(0, 4), v(0, 0), v(3, 0), v(0, 4)))); 48 | thenReturned(false); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d2/RectangleTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d2; 2 | 3 | import static com.perunlabs.jsolid.JSolid.range; 4 | import static org.testory.Testory.given; 5 | import static org.testory.Testory.thenReturned; 6 | import static org.testory.Testory.when; 7 | 8 | import org.junit.Test; 9 | 10 | public class RectangleTest { 11 | private Rectangle rectangle; 12 | 13 | @Test 14 | public void rectangle_vertexes_are_convex_and_counter_clockwise() throws Exception { 15 | given(rectangle = new Rectangle(range(10), range(20), 0)); 16 | when(Geometry.isConvexCounterClockwisePolygon(rectangle.vertexes())); 17 | thenReturned(true); 18 | } 19 | 20 | @Test 21 | public void rounded_rectangle_vertexes_are_convex_and_counter_clockwise() throws Exception { 22 | given(rectangle = new Rectangle(range(10), range(20), 0).cornerR(100)); 23 | when(Geometry.isConvexCounterClockwisePolygon(rectangle.vertexes())); 24 | thenReturned(true); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/AlignmentTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.align; 4 | import static com.perunlabs.jsolid.JSolid.centerX; 5 | import static com.perunlabs.jsolid.JSolid.cuboid; 6 | import static com.perunlabs.jsolid.JSolid.maxX; 7 | import static com.perunlabs.jsolid.JSolid.minX; 8 | import static com.perunlabs.jsolid.JSolid.vx; 9 | import static org.testory.Testory.given; 10 | import static org.testory.Testory.thenReturned; 11 | import static org.testory.Testory.thenThrown; 12 | import static org.testory.Testory.when; 13 | 14 | import org.junit.Test; 15 | 16 | public class AlignmentTest { 17 | private Alignment alignment; 18 | 19 | @Test 20 | public void alignment() throws Exception { 21 | given(alignment = new Alignment(maxX(), minX(), 0)); 22 | when(alignment.alignShiftFor(cuboid(3, 7, 11), cuboid(5, 13, 17))); 23 | thenReturned(vx(4)); 24 | } 25 | 26 | @Test 27 | public void alignment_with_shift() throws Exception { 28 | given(alignment = new Alignment(maxX(), minX(), 3)); 29 | when(alignment.alignShiftFor(cuboid(3, 7, 11), cuboid(5, 13, 17))); 30 | thenReturned(vx(7)); 31 | } 32 | 33 | @Test 34 | public void aligning_with_margin_using_two_not_edgy_anchors_fails() throws Exception { 35 | when(() -> align(centerX(), 3, centerX())); 36 | thenThrown(IllegalArgumentException.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/Anchor3Test.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.cuboid; 4 | import static com.perunlabs.jsolid.JSolid.range; 5 | import static org.testory.Testory.given; 6 | import static org.testory.Testory.thenReturned; 7 | import static org.testory.Testory.when; 8 | 9 | import org.junit.Test; 10 | 11 | import com.perunlabs.jsolid.JSolid; 12 | 13 | public class Anchor3Test { 14 | private Cuboid cuboid; 15 | 16 | @Test 17 | public void minX() throws Exception { 18 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 19 | when(JSolid.minX().valueIn(cuboid)); 20 | thenReturned(1.0); 21 | } 22 | 23 | @Test 24 | public void centerX() { 25 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 26 | when(JSolid.centerX().valueIn(cuboid)); 27 | thenReturned(1.5); 28 | } 29 | 30 | @Test 31 | public void maxX() throws Exception { 32 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 33 | when(JSolid.maxX().valueIn(cuboid)); 34 | thenReturned(2.0); 35 | } 36 | 37 | @Test 38 | public void minY() throws Exception { 39 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 40 | when(JSolid.minY().valueIn(cuboid)); 41 | thenReturned(3.0); 42 | } 43 | 44 | @Test 45 | public void centerY() { 46 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 47 | when(JSolid.centerY().valueIn(cuboid)); 48 | thenReturned(3.5); 49 | } 50 | 51 | @Test 52 | public void maxY() throws Exception { 53 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 54 | when(JSolid.maxY().valueIn(cuboid)); 55 | thenReturned(4.0); 56 | } 57 | 58 | @Test 59 | public void minZ() throws Exception { 60 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 61 | when(JSolid.minZ().valueIn(cuboid)); 62 | thenReturned(5.0); 63 | } 64 | 65 | @Test 66 | public void centerZ() { 67 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 68 | when(JSolid.centerZ().valueIn(cuboid)); 69 | thenReturned(5.5); 70 | } 71 | 72 | @Test 73 | public void maxZ() throws Exception { 74 | given(cuboid = cuboid(range(1, 2), range(3, 4), range(5, 6))); 75 | when(JSolid.maxZ().valueIn(cuboid)); 76 | thenReturned(6.0); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/CuboidTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.cuboid; 4 | import static com.perunlabs.jsolid.JSolid.range; 5 | import static com.perunlabs.jsolid.JSolid.v; 6 | import static com.perunlabs.jsolid.util.SolidMatcher.matchesSolid; 7 | import static org.testory.Testory.thenReturned; 8 | import static org.testory.Testory.when; 9 | 10 | import org.junit.Test; 11 | 12 | public class CuboidTest { 13 | @Test 14 | public void simple_cube() throws Exception { 15 | when(cuboid(2, 2, 2)); 16 | thenReturned(matchesSolid( 17 | v(1, 1, 1), 18 | v(1, 1, -1), 19 | v(1, -1, 1), 20 | v(1, -1, -1), 21 | v(-1, 1, 1), 22 | v(-1, 1, -1), 23 | v(-1, -1, 1), 24 | v(-1, -1, -1))); 25 | } 26 | 27 | @Test 28 | public void range_x() throws Exception { 29 | when(cuboid(range(-7, 3), 2, 2)); 30 | thenReturned(matchesSolid( 31 | v(-7, 1, 1), 32 | v(-7, 1, -1), 33 | v(-7, -1, 1), 34 | v(-7, -1, -1), 35 | v(3, 1, 1), 36 | v(3, 1, -1), 37 | v(3, -1, 1), 38 | v(3, -1, -1))); 39 | } 40 | 41 | @Test 42 | public void range_y() throws Exception { 43 | when(cuboid(2, range(-7, 3), 2)); 44 | thenReturned(matchesSolid( 45 | v(1, 3, 1), 46 | v(1, 3, -1), 47 | v(1, -7, 1), 48 | v(1, -7, -1), 49 | v(-1, 3, 1), 50 | v(-1, 3, -1), 51 | v(-1, -7, 1), 52 | v(-1, -7, -1))); 53 | } 54 | 55 | @Test 56 | public void range_z() throws Exception { 57 | when(cuboid(2, 2, range(-7, 3))); 58 | thenReturned(matchesSolid( 59 | v(1, 1, 3), 60 | v(1, 1, -7), 61 | v(1, -1, 3), 62 | v(1, -1, -7), 63 | v(-1, 1, 3), 64 | v(-1, 1, -7), 65 | v(-1, -1, 3), 66 | v(-1, -1, -7))); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/EdgeTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.edge; 4 | import static com.perunlabs.jsolid.JSolid.v; 5 | import static org.hamcrest.Matchers.equalTo; 6 | import static org.hamcrest.Matchers.not; 7 | import static org.testory.Testory.given; 8 | import static org.testory.Testory.then; 9 | import static org.testory.Testory.thenEqual; 10 | import static org.testory.Testory.thenReturned; 11 | import static org.testory.Testory.when; 12 | 13 | import org.junit.Test; 14 | 15 | public class EdgeTest { 16 | private Edge edge; 17 | private Edge edge2; 18 | 19 | @Test 20 | public void flip() throws Exception { 21 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 22 | when(() -> edge.flip()); 23 | thenReturned(edge(v(4, 5, 6), v(1, 2, 3))); 24 | } 25 | 26 | @Test 27 | public void is_equal_to_edge_with_same_points() throws Exception { 28 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 29 | given(edge2 = edge(v(1, 2, 3), v(4, 5, 6))); 30 | thenEqual(edge, edge2); 31 | } 32 | 33 | @Test 34 | public void is_not_equal_to_edge_with_points_reordered() throws Exception { 35 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 36 | given(edge2 = edge(v(4, 5, 6), v(1, 2, 3))); 37 | then(edge, not(equalTo(edge2))); 38 | } 39 | 40 | @Test 41 | public void is_not_equal_to_edge_with_different_point_a() throws Exception { 42 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 43 | given(edge2 = edge(v(0, 2, 3), v(4, 5, 6))); 44 | then(edge, not(equalTo(edge2))); 45 | } 46 | 47 | @Test 48 | public void is_not_equal_to_edge_with_different_point_b() throws Exception { 49 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 50 | given(edge2 = edge(v(1, 2, 3), v(0, 5, 6))); 51 | then(edge, not(equalTo(edge2))); 52 | } 53 | 54 | @Test 55 | public void equal_edges_have_same_hashcode() throws Exception { 56 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 57 | given(edge2 = edge(v(1, 2, 3), v(4, 5, 6))); 58 | thenEqual(edge.hashCode(), edge2.hashCode()); 59 | } 60 | 61 | @Test 62 | public void different_edges_have_different_hashcodes() throws Exception { 63 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 64 | given(edge2 = edge(v(0, 2, 3), v(4, 5, 6))); 65 | then(edge.hashCode(), not(equalTo(edge2.hashCode()))); 66 | } 67 | 68 | @Test 69 | public void to_string() throws Exception { 70 | given(edge = edge(v(1, 2, 3), v(4, 5, 6))); 71 | when(() -> edge.toString()); 72 | thenReturned("edge(v(1.0, 2.0, 3.0), v(4.0, 5.0, 6.0))"); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/PolygonTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.edge; 4 | import static com.perunlabs.jsolid.JSolid.v; 5 | import static eu.mihosoft.vrl.v3d.Polygon.fromPoints; 6 | import static java.util.Arrays.asList; 7 | import static org.testory.Testory.given; 8 | import static org.testory.Testory.thenReturned; 9 | import static org.testory.Testory.when; 10 | 11 | import org.junit.Test; 12 | 13 | import eu.mihosoft.vrl.v3d.Polygon; 14 | 15 | public class PolygonTest { 16 | private Polygon polygon; 17 | 18 | @Test 19 | public void edges() throws Exception { 20 | given(polygon = fromPoints(v(1, 1, 1), v(2, 2, 2), v(3, 3, 3))); 21 | when(() -> polygon.edges()); 22 | thenReturned(asList( 23 | edge(v(1, 1, 1), v(2, 2, 2)), 24 | edge(v(2, 2, 2), v(3, 3, 3)), 25 | edge(v(3, 3, 3), v(1, 1, 1)))); 26 | } 27 | 28 | @Test 29 | public void to_string() throws Exception { 30 | given(polygon = fromPoints(v(1, 1, 1), v(2, 2, 2), v(3, 3, 3))); 31 | when(() -> polygon.toString()); 32 | thenReturned("side(v(1.0, 1.0, 1.0), v(2.0, 2.0, 2.0), v(3.0, 3.0, 3.0))"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/StlTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.x; 4 | import static com.perunlabs.jsolid.JSolid.y; 5 | import static com.perunlabs.jsolid.JSolid.z; 6 | import static java.util.Arrays.asList; 7 | import static org.testory.Testory.given; 8 | import static org.testory.Testory.mock; 9 | import static org.testory.Testory.thenEqual; 10 | import static org.testory.Testory.when; 11 | import static org.testory.Testory.willReturn; 12 | 13 | import java.io.StringWriter; 14 | 15 | import org.junit.Test; 16 | 17 | import eu.mihosoft.vrl.v3d.Polygon; 18 | 19 | public class StlTest { 20 | private StringWriter writer; 21 | private Solid solid; 22 | private Polygon side; 23 | 24 | @Test 25 | public void toStl() throws Exception { 26 | given(writer = new StringWriter()); 27 | given(solid = mock(Solid.class)); 28 | given(side = new Polygon(x(), y(), z(), z().neg())); 29 | given(willReturn(asList(side)), solid).sides(); 30 | when(() -> Stl.toStl(solid, writer)); 31 | thenEqual(writer.toString(), 32 | "solid \n" 33 | + "facet normal 0.5773502691896258 0.5773502691896258 0.5773502691896258\n" 34 | + " outer loop\n" 35 | + " vertex 1.0 0.0 0.0\n" 36 | + " vertex 0.0 1.0 0.0\n" 37 | + " vertex 0.0 0.0 1.0\n" 38 | + " endloop\n" 39 | + "endfacet\n" 40 | + "facet normal 0.5773502691896258 0.5773502691896258 0.5773502691896258\n" 41 | + " outer loop\n" 42 | + " vertex 1.0 0.0 0.0\n" 43 | + " vertex 0.0 0.0 1.0\n" 44 | + " vertex -0.0 -0.0 -1.0\n" 45 | + " endloop\n" 46 | + "endfacet\n" 47 | + "endsolid\n"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/Vector3Matchers.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3; 2 | 3 | import static com.perunlabs.jsolid.JSolid.v; 4 | 5 | import org.hamcrest.Description; 6 | import org.hamcrest.Matcher; 7 | import org.hamcrest.TypeSafeMatcher; 8 | 9 | public class Vector3Matchers { 10 | public static Matcher closeTo(final Vector3 expected) { 11 | double delta = 1e-15; 12 | return new TypeSafeMatcher() { 13 | @Override 14 | public boolean matchesSafely(Vector3 value) { 15 | Vector3 actualDelta = actualDelta(value); 16 | return actualDelta.x <= 0.0 17 | && actualDelta.y <= 0.0 18 | && actualDelta.z <= 0.0; 19 | } 20 | 21 | @Override 22 | public void describeMismatchSafely(Vector3 v, Description mismatchDescription) { 23 | mismatchDescription.appendValue(v) 24 | .appendText(" differed by ") 25 | .appendValue(actualDelta(v)); 26 | } 27 | 28 | @Override 29 | public void describeTo(Description description) { 30 | description.appendText("a vector value within ") 31 | .appendValue(delta) 32 | .appendText(" of ") 33 | .appendValue(expected); 34 | } 35 | 36 | private Vector3 actualDelta(Vector3 value) { 37 | return value.dif(expected).sub(v(delta, delta, delta)); 38 | } 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/op/AbstractSolidTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static com.perunlabs.jsolid.JSolid.x; 4 | import static com.perunlabs.jsolid.JSolid.y; 5 | import static com.perunlabs.jsolid.JSolid.z; 6 | import static com.perunlabs.jsolid.util.Lists.immutable; 7 | import static java.util.Arrays.asList; 8 | import static org.testory.Testory.given; 9 | import static org.testory.Testory.thenReturned; 10 | import static org.testory.Testory.when; 11 | 12 | import java.util.List; 13 | 14 | import org.junit.Test; 15 | 16 | import eu.mihosoft.vrl.v3d.Polygon; 17 | 18 | public class AbstractSolidTest { 19 | private List sides; 20 | private AbstractSolid solid; 21 | 22 | @Test 23 | public void sides_returns_value_from_calculate_sides() throws Exception { 24 | given(sides = polygonList()); 25 | given(solid = abstractSolid(sides)); 26 | when(solid.sides()); 27 | thenReturned(sides); 28 | } 29 | 30 | @Test 31 | public void sides_returns_value_from_calculate_sides_on_second_call() throws Exception { 32 | given(sides = polygonList()); 33 | given(solid = abstractSolid(sides)); 34 | given(solid).sides(); 35 | when(solid.sides()); 36 | thenReturned(sides); 37 | } 38 | 39 | @Test 40 | public void calculate_sides_is_called_only_once() throws Exception { 41 | given(sides = polygonList()); 42 | given(solid = new AbstractSolid() { 43 | int count = 0; 44 | 45 | public List calculateSides() { 46 | if (count == 0) { 47 | count++; 48 | return sides; 49 | } else { 50 | return null; 51 | } 52 | } 53 | }); 54 | given(solid).sides(); 55 | when(solid).sides(); 56 | thenReturned(sides); 57 | } 58 | 59 | private static List polygonList() { 60 | return immutable(asList(new Polygon(x(), y(), z()))); 61 | } 62 | 63 | private static AbstractSolid abstractSolid(List polygons) { 64 | return new AbstractSolid() { 65 | public List calculateSides() { 66 | return polygons; 67 | } 68 | }; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/op/AddTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static com.perunlabs.jsolid.JSolid.align; 4 | import static com.perunlabs.jsolid.JSolid.cuboid; 5 | import static com.perunlabs.jsolid.JSolid.maxX; 6 | import static com.perunlabs.jsolid.JSolid.nothing; 7 | import static com.perunlabs.jsolid.JSolid.range; 8 | import static com.perunlabs.jsolid.JSolid.v; 9 | import static com.perunlabs.jsolid.util.ExceptionMatcher.exception; 10 | import static com.perunlabs.jsolid.util.SolidMatcher.matchesSolid; 11 | import static org.testory.Testory.given; 12 | import static org.testory.Testory.thenReturned; 13 | import static org.testory.Testory.thenThrown; 14 | import static org.testory.Testory.when; 15 | 16 | import org.junit.Test; 17 | 18 | import com.perunlabs.jsolid.d3.Cuboid; 19 | 20 | public class AddTest { 21 | private Cuboid solid; 22 | 23 | @Test 24 | public void add_two_cuboid_halves() throws Exception { 25 | given(solid = cuboid(range(-1, 0), 2, 2)); 26 | when(() -> solid.add(cuboid(range(0, 1), 2, 2))); 27 | thenReturned(matchesSolid( 28 | v(-1, 1, 1), 29 | v(-1, 1, -1), 30 | v(-1, -1, 1), 31 | v(-1, -1, -1), 32 | v(0, 1, 1), 33 | v(0, 1, -1), 34 | v(0, -1, 1), 35 | v(0, -1, -1), 36 | v(1, 1, 1), 37 | v(1, 1, -1), 38 | v(1, -1, 1), 39 | v(1, -1, -1))); 40 | } 41 | 42 | @Test 43 | public void add_itself_returns_itself() throws Exception { 44 | given(solid = cuboid(2, 2, 2)); 45 | when(() -> solid.add(cuboid(2, 2, 2))); 46 | thenReturned(matchesSolid( 47 | v(-1, 1, 1), 48 | v(-1, 1, -1), 49 | v(-1, -1, 1), 50 | v(-1, -1, -1), 51 | v(1, 1, 1), 52 | v(1, 1, -1), 53 | v(1, -1, 1), 54 | v(1, -1, -1))); 55 | } 56 | 57 | @Test 58 | public void adding_aligned_nothing_succeeds() throws Exception { 59 | when(() -> cuboid(1, 2, 3).add(nothing(), align(maxX())).sides()); 60 | thenReturned(); 61 | } 62 | 63 | @Test 64 | public void adding_aligned_to_nothing_fails() throws Exception { 65 | when(() -> nothing().add(cuboid(1, 2, 3), align(maxX())).sides()); 66 | thenThrown(exception(new IllegalArgumentException( 67 | "It is not possible to align against empty Solid."))); 68 | } 69 | 70 | @Test 71 | public void adding_anchored_nothing_succeeds() throws Exception { 72 | when(() -> cuboid(1, 2, 3).add(nothing(), maxX()).sides()); 73 | thenReturned(); 74 | } 75 | 76 | @Test 77 | public void adding_anchored_to_nothing_fails() throws Exception { 78 | when(() -> nothing().add(cuboid(1, 2, 3), maxX()).sides()); 79 | thenThrown(exception(new IllegalArgumentException( 80 | "It is not possible to align against empty Solid."))); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/op/IntersectTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static com.perunlabs.jsolid.JSolid.align; 4 | import static com.perunlabs.jsolid.JSolid.cuboid; 5 | import static com.perunlabs.jsolid.JSolid.maxX; 6 | import static com.perunlabs.jsolid.JSolid.nothing; 7 | import static com.perunlabs.jsolid.JSolid.range; 8 | import static com.perunlabs.jsolid.JSolid.v; 9 | import static com.perunlabs.jsolid.util.SolidMatcher.matchesSolid; 10 | import static org.testory.Testory.given; 11 | import static org.testory.Testory.thenReturned; 12 | import static org.testory.Testory.when; 13 | 14 | import org.junit.Test; 15 | 16 | import com.perunlabs.jsolid.d3.Cuboid; 17 | 18 | public class IntersectTest { 19 | private Cuboid solid; 20 | 21 | @Test 22 | public void intersect_with_itself_returns_itself() throws Exception { 23 | given(solid = cuboid(2, 2, 2)); 24 | when(() -> solid.intersect(cuboid(2, 2, 2))); 25 | thenReturned(matchesSolid( 26 | v(-1, 1, 1), 27 | v(-1, 1, -1), 28 | v(-1, -1, 1), 29 | v(-1, -1, -1), 30 | v(1, 1, 1), 31 | v(1, 1, -1), 32 | v(1, -1, 1), 33 | v(1, -1, -1))); 34 | } 35 | 36 | @Test 37 | public void intersect_with_not_overlapping_returns_nothing() throws Exception { 38 | given(solid = cuboid(range(-1, 0), 2, 2)); 39 | when(() -> solid.intersect(cuboid(range(0, 1), 2, 2))); 40 | thenReturned(matchesSolid()); 41 | } 42 | 43 | @Test 44 | public void intersecting_with_aligned_nothing_succeeds() throws Exception { 45 | when(() -> cuboid(1, 2, 3).intersect(nothing(), maxX()).sides()); 46 | thenReturned(); 47 | } 48 | 49 | @Test 50 | public void intersecting_nothing_with_aligned_succeeds() throws Exception { 51 | when(() -> nothing().intersect(cuboid(1, 2, 3), maxX()).sides()); 52 | thenReturned(); 53 | } 54 | 55 | @Test 56 | public void intersecting_with_anchored_nothing_succeeds() throws Exception { 57 | when(() -> cuboid(1, 2, 3).intersect(nothing(), align(maxX())).sides()); 58 | thenReturned(); 59 | } 60 | 61 | @Test 62 | public void intersecting_nothing_with_anchored_succeeds() throws Exception { 63 | when(() -> nothing().intersect(cuboid(1, 2, 3), align(maxX())).sides()); 64 | thenReturned(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/op/PolygonsSolidTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static com.perunlabs.jsolid.JSolid.x; 4 | import static com.perunlabs.jsolid.JSolid.y; 5 | import static com.perunlabs.jsolid.JSolid.z; 6 | import static java.util.Arrays.asList; 7 | import static org.hamcrest.Matchers.equalTo; 8 | import static org.hamcrest.Matchers.not; 9 | import static org.testory.Testory.given; 10 | import static org.testory.Testory.thenReturned; 11 | import static org.testory.Testory.when; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import org.junit.Test; 17 | 18 | import eu.mihosoft.vrl.v3d.Polygon; 19 | 20 | public class PolygonsSolidTest { 21 | private List sides; 22 | private PolygonsSolid solid; 23 | 24 | @Test 25 | public void sides_returns_list_passed_to_constructor() throws Exception { 26 | given(sides = asList(new Polygon(x(), y(), z()))); 27 | given(solid = new PolygonsSolid(sides)); 28 | when(solid).sides(); 29 | thenReturned(sides); 30 | } 31 | 32 | @Test 33 | public void sides_are_defensive_copied() throws Exception { 34 | given(sides = new ArrayList<>(asList(new Polygon(x(), y(), z())))); 35 | given(solid = new PolygonsSolid(sides)); 36 | given(sides).add(new Polygon(z(), y(), x())); 37 | when(solid).sides(); 38 | thenReturned(not(equalTo(sides))); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/d3/op/SubTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.d3.op; 2 | 3 | import static com.perunlabs.jsolid.JSolid.align; 4 | import static com.perunlabs.jsolid.JSolid.cuboid; 5 | import static com.perunlabs.jsolid.JSolid.maxX; 6 | import static com.perunlabs.jsolid.JSolid.nothing; 7 | import static com.perunlabs.jsolid.JSolid.range; 8 | import static com.perunlabs.jsolid.JSolid.v; 9 | import static com.perunlabs.jsolid.util.SolidMatcher.matchesSolid; 10 | import static org.testory.Testory.given; 11 | import static org.testory.Testory.thenReturned; 12 | import static org.testory.Testory.when; 13 | 14 | import org.junit.Test; 15 | 16 | import com.perunlabs.jsolid.d3.Cuboid; 17 | 18 | public class SubTest { 19 | private Cuboid solid; 20 | 21 | @Test 22 | public void sub_half_of_cuboid() throws Exception { 23 | given(solid = cuboid(2, 2, 2)); 24 | when(() -> solid.sub(cuboid(range(0, 1), 2, 2))); 25 | thenReturned(matchesSolid( 26 | v(0, 1, 1), 27 | v(0, 1, -1), 28 | v(0, -1, 1), 29 | v(0, -1, -1), 30 | v(-1, 1, 1), 31 | v(-1, 1, -1), 32 | v(-1, -1, 1), 33 | v(-1, -1, -1))); 34 | } 35 | 36 | @Test 37 | public void sub_itself_returns_nothing() throws Exception { 38 | given(solid = cuboid(2, 2, 2)); 39 | when(() -> solid.sub(solid)); 40 | thenReturned(matchesSolid()); 41 | } 42 | 43 | @Test 44 | public void sub_enclosing_solid_returns_nothing() throws Exception { 45 | given(solid = cuboid(2, 2, 2)); 46 | when(() -> solid.sub(cuboid(4, 4, 4))); 47 | thenReturned(matchesSolid()); 48 | } 49 | 50 | @Test 51 | public void subtracting_aligned_nothing_succeeds() throws Exception { 52 | when(() -> cuboid(1, 2, 3).sub(nothing(), maxX()).sides()); 53 | thenReturned(); 54 | } 55 | 56 | @Test 57 | public void subtracting_aligned_from_nothing_succeeds() throws Exception { 58 | when(() -> nothing().sub(cuboid(1, 2, 3), maxX()).sides()); 59 | thenReturned(); 60 | } 61 | 62 | @Test 63 | public void subtracting_anchored_nothing_succeeds() throws Exception { 64 | when(() -> cuboid(1, 2, 3).sub(nothing(), align(maxX())).sides()); 65 | thenReturned(); 66 | } 67 | 68 | @Test 69 | public void subtracting_anchored_from_nothing_succeeds() throws Exception { 70 | when(() -> nothing().sub(cuboid(1, 2, 3), align(maxX())).sides()); 71 | thenReturned(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/util/CheckTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import static org.testory.Testory.thenReturned; 4 | import static org.testory.Testory.thenThrown; 5 | import static org.testory.Testory.when; 6 | 7 | import org.hamcrest.Matcher; 8 | import org.junit.Test; 9 | 10 | public class CheckTest { 11 | @Test 12 | public void positive_int_returns_value_when_positive() throws Exception { 13 | when(Check.positive(33)); 14 | thenReturned(33); 15 | } 16 | 17 | @Test 18 | public void positive_int_throws_exception_when_negative() throws Exception { 19 | when(() -> Check.positive(-1)); 20 | thenThrown(iae("Parameter is -1 but expected positive int.")); 21 | } 22 | 23 | @Test 24 | public void positive_int_throws_exception_when_zero() throws Exception { 25 | when(() -> Check.positive(0)); 26 | thenThrown(iae("Parameter is 0 but expected positive int.")); 27 | } 28 | 29 | @Test 30 | public void positive_double_returns_value_when_positive() throws Exception { 31 | when(Check.positive(33.0)); 32 | thenReturned(33.0); 33 | } 34 | 35 | @Test 36 | public void positive_double_throws_exception_when_negative() throws Exception { 37 | when(() -> Check.positive(-1.0)); 38 | thenThrown(iae("Parameter is -1.0 but expected positive double.")); 39 | } 40 | 41 | @Test 42 | public void positive_double_throws_exception_when_zero() throws Exception { 43 | when(() -> Check.positive(0.0)); 44 | thenThrown(iae("Parameter is 0.0 but expected positive double.")); 45 | } 46 | 47 | @Test 48 | public void not_negative_double_returns_value_when_positive() throws Exception { 49 | when(Check.notNegative(33.0)); 50 | thenReturned(33.0); 51 | } 52 | 53 | @Test 54 | public void not_negative_double_throws_exception_when_negative() throws Exception { 55 | when(() -> Check.notNegative(-1.0)); 56 | thenThrown(iae("Parameter is -1.0 but expected not negative double.")); 57 | } 58 | 59 | @Test 60 | public void not_negative_double_throws_exception_when_zero() throws Exception { 61 | when(() -> Check.notNegative(0.0)); 62 | thenReturned(0.0); 63 | } 64 | 65 | @Test 66 | public void is_finite_returns_value_if_it_is_number() throws Exception { 67 | when(() -> Check.isFinite(33)); 68 | thenReturned(33.0); 69 | } 70 | 71 | @Test 72 | public void is_finite_throws_exception_when_argument_is_NaN() throws Exception { 73 | when(() -> Check.isFinite(Double.NaN)); 74 | thenThrown(iae("Parameter is NaN but expected finite double.")); 75 | } 76 | 77 | @Test 78 | public void is_finite_throws_exception_when_argument_is_positive_infinity() throws Exception { 79 | when(() -> Check.isFinite(Double.POSITIVE_INFINITY)); 80 | thenThrown(iae("Parameter is Infinity but expected finite double.")); 81 | } 82 | 83 | @Test 84 | public void is_finite_throws_exception_when_argument_is_negative_infinity() throws Exception { 85 | when(() -> Check.isFinite(Double.NEGATIVE_INFINITY)); 86 | thenThrown(iae("Parameter is -Infinity but expected finite double.")); 87 | } 88 | 89 | @Test 90 | public void noNullElements_returns_argument() throws Exception { 91 | String[] array = new String[] { "abc", "def" }; 92 | when(() -> Check.noNullElements(array)); 93 | thenReturned(array); 94 | } 95 | 96 | @Test 97 | public void noNullElements_fails_when_element_is_null() throws Exception { 98 | when(() -> Check.noNullElements(new String[] { "abc", null })); 99 | thenThrown(NullPointerException.class); 100 | } 101 | 102 | private static Matcher iae(String message) { 103 | return ExceptionMatcher.exception(new IllegalArgumentException(message)); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/util/ExceptionMatcher.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import java.util.Objects; 4 | 5 | import org.hamcrest.Description; 6 | import org.hamcrest.Matcher; 7 | import org.hamcrest.TypeSafeMatcher; 8 | 9 | public class ExceptionMatcher extends TypeSafeMatcher { 10 | private final Throwable throwable; 11 | 12 | public static Matcher exception(Throwable throwable) { 13 | return new ExceptionMatcher(throwable); 14 | } 15 | 16 | private ExceptionMatcher(Throwable throwable) { 17 | this.throwable = throwable; 18 | } 19 | 20 | public void describeTo(Description description) { 21 | description.appendText("is instance of " + throwable.getClass().getSimpleName() 22 | + " with message '" 23 | + throwable.getMessage() + "'."); 24 | } 25 | 26 | protected boolean matchesSafely(Throwable item) { 27 | return throwable.getClass().isInstance(item) 28 | && Objects.equals(item.getMessage(), throwable.getMessage()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/util/HashTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import static org.hamcrest.Matchers.not; 4 | import static org.testory.Testory.thenReturned; 5 | import static org.testory.Testory.when; 6 | 7 | import org.junit.Test; 8 | 9 | public class HashTest { 10 | @Test 11 | public void equal_values_have_equal_hash() throws Exception { 12 | when(Hash.hash(33)); 13 | thenReturned(Hash.hash(33)); 14 | } 15 | 16 | @Test 17 | public void different_values_have_equal_hash() throws Exception { 18 | when(Hash.hash(33)); 19 | thenReturned(not(Hash.hash(34))); 20 | } 21 | 22 | @Test 23 | public void zero_and_zero_have_equal_hash() throws Exception { 24 | when(Hash.hash(0.0)); 25 | thenReturned(Hash.hash(0.0)); 26 | } 27 | 28 | @Test 29 | public void zero_and_minus_zero_have_equal_hash() throws Exception { 30 | when(Hash.hash(0.0)); 31 | thenReturned(Hash.hash(-0.0)); 32 | } 33 | 34 | @Test 35 | public void zero_and_zero_have_equal_hash_array_version() throws Exception { 36 | when(Hash.hash(0.0)); 37 | thenReturned(Hash.hash(0.0)); 38 | } 39 | 40 | @Test 41 | public void zero_and_minus_zero_have_equal_hash_array_version() throws Exception { 42 | when(Hash.hash(0.0, 1.0)); 43 | thenReturned(Hash.hash(-0.0, 1.0)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/util/ListsTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import static com.perunlabs.jsolid.util.Lists.immutable; 4 | import static java.util.Arrays.asList; 5 | import static org.testory.Testory.given; 6 | import static org.testory.Testory.thenEqual; 7 | import static org.testory.Testory.thenReturned; 8 | import static org.testory.Testory.when; 9 | 10 | import java.util.List; 11 | 12 | import org.junit.Test; 13 | 14 | public class ListsTest { 15 | private List list; 16 | private List list2; 17 | 18 | @Test 19 | public void immutable_does_defensive_copy_of_argument() throws Exception { 20 | given(list = asList(1, 2, 3)); 21 | given(list2 = Lists.immutable(list)); 22 | when(list).set(0, 0); 23 | thenEqual(list2, asList(1, 2, 3)); 24 | } 25 | 26 | @Test 27 | public void immutable_creates_equal_copy() throws Exception { 28 | given(list = asList(1, 2, 3)); 29 | when(immutable(list)); 30 | thenReturned(asList(1, 2, 3)); 31 | } 32 | 33 | @Test 34 | public void reverse_reverses_elements() throws Exception { 35 | given(list = asList(1, 2, 3)); 36 | when(Lists.reverse(list)); 37 | thenReturned(asList(3, 2, 1)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/util/SolidMatcher.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import static java.util.function.Function.identity; 4 | import static java.util.stream.Collectors.counting; 5 | import static java.util.stream.Collectors.groupingBy; 6 | import static java.util.stream.Collectors.toList; 7 | 8 | import java.util.Collections; 9 | import java.util.HashSet; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.Set; 13 | import java.util.stream.Collectors; 14 | 15 | import org.hamcrest.Description; 16 | import org.hamcrest.Matcher; 17 | import org.hamcrest.TypeSafeMatcher; 18 | 19 | import com.perunlabs.jsolid.d3.Edge; 20 | import com.perunlabs.jsolid.d3.Solid; 21 | import com.perunlabs.jsolid.d3.Vector3; 22 | 23 | public class SolidMatcher extends TypeSafeMatcher { 24 | private final Set vertexes; 25 | 26 | public static Matcher matchesSolid(Vector3... vertexes) { 27 | return new SolidMatcher(vertexes); 28 | } 29 | 30 | private SolidMatcher(Vector3[] vertexes) { 31 | this.vertexes = toSet(vertexes); 32 | } 33 | 34 | private static HashSet toSet(Vector3[] vertexes) { 35 | HashSet set = new HashSet<>(); 36 | Collections.addAll(set, vertexes); 37 | return set; 38 | } 39 | 40 | public void describeTo(Description description) { 41 | description.appendText("is equal to given solid."); 42 | } 43 | 44 | protected boolean matchesSafely(Solid solid) { 45 | if (!vertexesMatch(solid)) { 46 | return false; 47 | } 48 | if (hasSideWithDoubleVertex(solid)) { 49 | return false; 50 | } 51 | if (!eachEdgeHasFlippedPartner(solid)) { 52 | return false; 53 | } 54 | return true; 55 | } 56 | 57 | private boolean vertexesMatch(Solid solid) { 58 | Set actualVertexes = solid.sides().stream() 59 | .flatMap(s -> s.vertices.stream()) 60 | .collect(Collectors.toSet()); 61 | return actualVertexes.equals(vertexes); 62 | } 63 | 64 | private static boolean hasSideWithDoubleVertex(Solid solid) { 65 | return solid.sides().stream() 66 | .anyMatch(side -> hasDoubledVertex(side.vertices)); 67 | } 68 | 69 | private static boolean hasDoubledVertex(List vertexes) { 70 | for (int i = 0; i < vertexes.size(); i++) { 71 | for (int j = i + 1; j < vertexes.size(); j++) { 72 | if (vertexes.get(i).equals(vertexes.get(j))) { 73 | return true; 74 | } 75 | } 76 | } 77 | return false; 78 | } 79 | 80 | private static boolean eachEdgeHasFlippedPartner(Solid solid) { 81 | List edges = solid.sides().stream() 82 | .flatMap(s -> s.edges().stream()) 83 | .collect(toList()); 84 | Map counts = edges.stream() 85 | .collect(groupingBy(identity(), counting())); 86 | for (Edge edge : edges) { 87 | if (counts.get(edge) != 1) { 88 | System.out.println(counts.get(edge)); 89 | return false; 90 | } 91 | Long flippedCount = counts.get(edge.flip()); 92 | if (flippedCount == null || flippedCount != 1) { 93 | return false; 94 | } 95 | } 96 | return true; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/junit/com/perunlabs/jsolid/util/SolidMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.perunlabs.jsolid.util; 2 | 3 | import static com.perunlabs.jsolid.JSolid.v; 4 | import static com.perunlabs.jsolid.util.SolidMatcher.matchesSolid; 5 | import static java.util.Arrays.asList; 6 | import static org.testory.Testory.given; 7 | import static org.testory.Testory.thenReturned; 8 | import static org.testory.Testory.when; 9 | 10 | import java.util.List; 11 | 12 | import org.hamcrest.Matcher; 13 | import org.junit.Test; 14 | 15 | import com.perunlabs.jsolid.d3.Solid; 16 | import com.perunlabs.jsolid.d3.Vector3; 17 | import com.perunlabs.jsolid.d3.op.AbstractSolid; 18 | 19 | import eu.mihosoft.vrl.v3d.Polygon; 20 | 21 | public class SolidMatcherTest { 22 | private Matcher matcher; 23 | 24 | @Test 25 | public void matches() throws Exception { 26 | given(matcher = matchesSolid( 27 | v(0, 0, 0), 28 | v(1, 0, 0), 29 | v(0, 1, 0))); 30 | when(matcher.matches(solid( 31 | poly(v(0, 0, 0), v(1, 0, 0), v(0, 1, 0)), 32 | poly(v(0, 0, 0), v(0, 1, 0), v(1, 0, 0))))); 33 | thenReturned(true); 34 | } 35 | 36 | @Test 37 | public void no_match_when_vertex_is_missing() throws Exception { 38 | given(matcher = matchesSolid( 39 | v(0, 0, 0), 40 | v(1, 0, 0), 41 | v(0, 1, 0), 42 | v(33, 33, 33))); 43 | when(matcher.matches(solid( 44 | poly(v(0, 0, 0), v(1, 0, 0), v(0, 1, 0)), 45 | poly(v(0, 0, 0), v(0, 1, 0), v(1, 0, 0))))); 46 | thenReturned(false); 47 | } 48 | 49 | @Test 50 | public void no_match_when_extra_vertex_is_present() throws Exception { 51 | given(matcher = matchesSolid( 52 | v(0, 0, 0), 53 | v(1, 0, 0), 54 | v(0, 1, 0))); 55 | when(matcher.matches(solid( 56 | poly(v(0, 0, 0), v(1, 0, 0), v(1, 1, 0), v(0, 1, 0)), 57 | poly(v(0, 0, 0), v(0, 1, 0), v(1, 1, 0), v(1, 0, 0))))); 58 | thenReturned(false); 59 | } 60 | 61 | @Test 62 | public void no_match_when_side_has_doubled_vertex() throws Exception { 63 | given(matcher = matchesSolid( 64 | v(0, 0, 0), 65 | v(1, 0, 0), 66 | v(0, 1, 0))); 67 | when(matcher.matches(solid( 68 | poly(v(0, 0, 0), v(1, 0, 0), v(0, 1, 0), v(0, 0, 0)), 69 | poly(v(0, 0, 0), v(0, 1, 0), v(1, 0, 0))))); 70 | thenReturned(false); 71 | } 72 | 73 | @Test 74 | public void no_match_when_edge_doesnt_have_flipped_partner() throws Exception { 75 | given(matcher = matchesSolid( 76 | v(0, 0, 0), 77 | v(1, 0, 0), 78 | v(0, 1, 0), 79 | v(1, 1, 0))); 80 | when(matcher.matches(solid( 81 | poly(v(0, 0, 0), v(1, 0, 0), v(1, 1, 0), v(0, 1, 0)), 82 | poly(v(0, 0, 0), v(0, 1, 0), v(1, 0, 0))))); 83 | thenReturned(false); 84 | } 85 | 86 | private Polygon poly(Vector3... vertexes) { 87 | return new Polygon(vertexes); 88 | } 89 | 90 | private static Solid solid(Polygon... polygons) { 91 | return new AbstractSolid() { 92 | 93 | protected List calculateSides() { 94 | return asList(polygons); 95 | } 96 | }; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/junit/eu/mihosoft/vrl/v3d/ext/quickhull3d/QhullTest.java: -------------------------------------------------------------------------------- 1 | package eu.mihosoft.vrl.v3d.ext.quickhull3d; 2 | 3 | import static org.junit.Assert.fail; 4 | 5 | import org.junit.Test; 6 | 7 | public class QhullTest { 8 | 9 | @Test 10 | public void test_qhull() throws Exception { 11 | QuickHull3D hull = new QuickHull3D(); 12 | QuickHull3DTest tester = new QuickHull3DTest(); 13 | 14 | hull = new QuickHull3D(); 15 | 16 | for (int i = 0; i < 100; i++) { 17 | double[] pnts = tester.randomCubedPoints(100, 1.0, 0.5); 18 | 19 | // hull = new QuickHull3D (); 20 | hull.build(pnts, pnts.length / 3); 21 | hull.triangulate(); 22 | 23 | if (!hull.check(System.out)) { 24 | fail("failed for QuickHull3D triangulated"); 25 | } 26 | 27 | // hull = new QuickHull3D (); 28 | hull.build(pnts, pnts.length / 3); 29 | 30 | if (!hull.check(System.out)) { 31 | fail("failed for QuickHull3D regular"); 32 | } 33 | } 34 | } 35 | } 36 | --------------------------------------------------------------------------------