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 |
--------------------------------------------------------------------------------