-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathAbstractGeometry.java
More file actions
79 lines (68 loc) · 2.17 KB
/
AbstractGeometry.java
File metadata and controls
79 lines (68 loc) · 2.17 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
package nodebox.graphics;
import java.util.Iterator;
/**
*
*/
public abstract class AbstractGeometry extends AbstractTransformable implements IGeometry {
//// Container operations ////
/**
* Extend the current geometry with the given list of points.
*
* @param points the points to add to the geometry.
*/
public void extend(Iterator<Point> points) {
while (points.hasNext()) {
Point point = points.next();
addPoint(point.clone());
}
}
/**
* Extend the current geometry with the given list of points.
*
* @param points the points to add to the geometry.
*/
public void extend(Point[] points) {
for (Point point : points) {
addPoint(point.clone());
}
}
//// Geometric operations ////
/**
* Make 100 new points along the contours of the existing path.
* <p/>
* Points are evenly distributed according to the length of each geometric object.
*
* @return a list of Points.
*/
public Point[] makePoints() {
return makePoints(DEFAULT_POINT_AMOUNT, false);
}
public Point[] makePoints(int amount) {
return makePoints(amount, false);
}
/**
* Calculate how far the points would be apart, given the specified amount and whether the geometry is closed.
*
* @param amount the amount of points
* @param closed whether the geometry is closed
* @return the delta value between each point
*/
protected float pointDelta(int amount, boolean closed) {
float delta = 1;
if (closed) {
if (amount > 0) {
delta = 1f / amount;
}
} else {
// The delta value is divided by amount - 1, because we also want the last point (t=1.0)
// If I wouldn't use amount - 1, I fall one point short of the end.
// E.g. if amount = 4, I want point at t 0.0, 0.33, 0.66 and 1.0,
// if amount = 2, I want point at t 0.0 and t 1.0
if (amount > 2) {
delta = 1f / (amount - 1f);
}
}
return delta;
}
public abstract IGeometry clone();
}