-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathSimplify3DTest.java
More file actions
executable file
·124 lines (98 loc) · 3.44 KB
/
Simplify3DTest.java
File metadata and controls
executable file
·124 lines (98 loc) · 3.44 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.goebl.simplify;
import org.junit.Assert;
import org.junit.Test;
/**
* Test class for {@link com.goebl.simplify.Simplify}.
*
* @author goebl
* @since 06.07.13
*/
public class Simplify3DTest {
private static final float[][] POINTS_3D = new float[][]{
{3.14f, 5.2f, 4f}, {5.7f, 8.1f, 5f}, {4.6f, -1.3f, 6f}
};
private static final double DELTA = 0.00001d;
@Test
public void testCustomPoint3DExtractor() {
Point3DExtractor<float[]> pointExtractor = new Point3DExtractor<float[]>() {
@Override
public double getX(float[] point) {
return point[0];
}
@Override
public double getY(float[] point) {
return point[1];
}
@Override
public double getZ(float[] point) {
return point[2];
}
};
Simplify3D<float[]> simplify = new Simplify3D<float[]>(new float[0][0], pointExtractor);
float[][] simplified = simplify.simplify(POINTS_3D, 5.0f, false);
Assert.assertEquals("array should be simplified", 2, simplified.length);
simplified = simplify.simplify(POINTS_3D, 5.0f, true);
Assert.assertEquals("array should be simplified", 2, simplified.length);
}
@Test
public void testDefaultPointExtractor() {
Point3D[] points = new MyPoint[POINTS_3D.length];
for (int i = 0; i < POINTS_3D.length; ++i) {
points[i] = new MyPoint(POINTS_3D[i][0], POINTS_3D[i][1], POINTS_3D[i][2]);
}
Simplify3D<Point3D> simplify3D = new Simplify3D<Point3D>(new MyPoint[0]);
Point3D[] simplified = simplify3D.simplify(points, 5.0d, false);
Assert.assertEquals("array should be simplified", 2, simplified.length);
simplified = simplify3D.simplify(points, 5.0d, true);
Assert.assertEquals("array should be simplified", 2, simplified.length);
}
@Test
public void testCalculateSquareSegmentDistance() {
double res = Simplify3D.calculateSquareSegmentDistance(
2, 1, 1,
1, 1, 1,
3, 3, 1);
Assert.assertEquals(0.5d, res, DELTA);
double resBis = Simplify3D.calculateSquareSegmentDistance(
-0.1, -0.2, -0.3,
-0.7, -0.8, -0.9,
-0.4, -0.5, -0.6);
Assert.assertEquals(0.27d, resBis, DELTA);
}
private static class MyPoint implements Point3D {
double x;
double y;
double z;
private MyPoint(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public double getX() {
return x;
}
@Override
public double getY() {
return y;
}
@Override
public double getZ() {
return z;
}
@Override
public String toString() {
return "{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyPoint myPoint = (MyPoint) o;
if (Double.compare(myPoint.x, x) != 0) return false;
if (Double.compare(myPoint.y, y) != 0) return false;
if (Double.compare(myPoint.z, z) != 0) return false;
return true;
}
}
}