-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathClipperD.java
More file actions
142 lines (118 loc) · 3.61 KB
/
ClipperD.java
File metadata and controls
142 lines (118 loc) · 3.61 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package clipper2.engine;
import clipper2.Clipper;
import clipper2.core.ClipType;
import clipper2.core.FillRule;
import clipper2.core.Path64;
import clipper2.core.PathD;
import clipper2.core.PathType;
import clipper2.core.Paths64;
import clipper2.core.PathsD;
/**
* The ClipperD class performs boolean 'clipping'. This class is very similar to
* Clipper64 except that coordinates passed to ClipperD objects are of type
* <code>double</code> instead of type <code>long</code>.
*/
public class ClipperD extends ClipperBase {
private static final String PRECISION_RANGE_ERROR = "Error: Precision is out of range.";
private double scale;
private double invScale;
public ClipperD() {
this(2);
}
/**
* @param roundingDecimalPrecision default = 2
*/
public ClipperD(int roundingDecimalPrecision) {
if (roundingDecimalPrecision < -8 || roundingDecimalPrecision > 8) {
throw new IllegalArgumentException(PRECISION_RANGE_ERROR);
}
scale = Math.pow(10, roundingDecimalPrecision);
invScale = 1 / scale;
}
public void AddPath(PathD path, PathType polytype) {
AddPath(path, polytype, false);
}
public void AddPath(PathD path, PathType polytype, boolean isOpen) {
super.AddPath(Clipper.ScalePath64(path, scale), polytype, isOpen);
}
public void AddPaths(PathsD paths, PathType polytype) {
AddPaths(paths, polytype, false);
}
public void AddPaths(PathsD paths, PathType polytype, boolean isOpen) {
super.AddPaths(Clipper.ScalePaths64(paths, scale), polytype, isOpen);
}
public void AddSubject(PathD path) {
AddPath(path, PathType.Subject);
}
public void AddOpenSubject(PathD path) {
AddPath(path, PathType.Subject, true);
}
public void AddClip(PathD path) {
AddPath(path, PathType.Clip);
}
public void AddSubjects(PathsD paths) {
AddPaths(paths, PathType.Subject);
}
public void AddOpenSubjects(PathsD paths) {
AddPaths(paths, PathType.Subject, true);
}
public void AddClips(PathsD paths) {
AddPaths(paths, PathType.Clip);
}
public boolean Execute(ClipType clipType, FillRule fillRule, PathsD solutionClosed, PathsD solutionOpen) {
Paths64 solClosed64 = new Paths64(), solOpen64 = new Paths64();
boolean success = true;
solutionClosed.clear();
solutionOpen.clear();
try {
ExecuteInternal(clipType, fillRule);
BuildPaths(solClosed64, solOpen64);
} catch (Exception e) {
success = false;
}
ClearSolutionOnly();
if (!success) {
return false;
}
solutionClosed.ensureCapacity(solClosed64.size());
for (Path64 path : solClosed64) {
solutionClosed.add(Clipper.ScalePathD(path, invScale));
}
solutionOpen.ensureCapacity(solOpen64.size());
for (Path64 path : solOpen64) {
solutionOpen.add(Clipper.ScalePathD(path, invScale));
}
return true;
}
public boolean Execute(ClipType clipType, FillRule fillRule, PathsD solutionClosed) {
return Execute(clipType, fillRule, solutionClosed, new PathsD());
}
public boolean Execute(ClipType clipType, FillRule fillRule, PolyTreeD polytree, PathsD openPaths) {
polytree.Clear();
polytree.setScale(invScale);
openPaths.clear();
Paths64 oPaths = new Paths64();
boolean success = true;
try {
ExecuteInternal(clipType, fillRule);
BuildTree(polytree, oPaths);
} catch (Exception e) {
success = false;
}
ClearSolutionOnly();
if (!success) {
return false;
}
if (oPaths.isEmpty()) {
return true;
}
openPaths.ensureCapacity(oPaths.size());
for (Path64 path : oPaths) {
openPaths.add(Clipper.ScalePathD(path, invScale));
}
return true;
}
public boolean Execute(ClipType clipType, FillRule fillRule, PolyTreeD polytree) {
return Execute(clipType, fillRule, polytree, new PathsD());
}
}