This repository was archived by the owner on Dec 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathPaths.java
More file actions
125 lines (107 loc) · 3.36 KB
/
Paths.java
File metadata and controls
125 lines (107 loc) · 3.36 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
package de.lighti.clipper;
import java.util.ArrayList;
/**
* A pure convenience class to avoid writing List<Path> everywhere.
*
* @author Tobias Mahlmann
*
*/
public class Paths extends ArrayList<Path> {
public static Paths closedPathsFromPolyTree(PolyTree polytree ) {
final Paths result = new Paths();
// result.Capacity = polytree.Total;
result.addPolyNode( polytree, PolyNode.NodeType.CLOSED );
return result;
}
public static Paths makePolyTreeToPaths(PolyTree polytree ) {
final Paths result = new Paths();
// result.Capacity = polytree.Total;
result.addPolyNode( polytree, PolyNode.NodeType.ANY );
return result;
}
public static Paths openPathsFromPolyTree(PolyTree polytree ) {
final Paths result = new Paths();
// result.Capacity = polytree.ChildCount;
for (final PolyNode c : polytree.getChilds()) {
if (c.isOpen()) {
result.add( c.getPolygon() );
}
}
return result;
}
/**
*
*/
private static final long serialVersionUID = 1910552127810480852L;
public Paths() {
super();
}
public Paths( int initialCapacity ) {
super( initialCapacity );
}
public void addPolyNode(PolyNode polynode, PolyNode.NodeType nt ) {
boolean match = true;
switch (nt) {
case OPEN:
return;
case CLOSED:
match = !polynode.isOpen();
break;
default:
break;
}
if (polynode.getPolygon().size() > 0 && match) {
add( polynode.getPolygon() );
}
for (final PolyNode pn : polynode.getChilds()) {
addPolyNode( pn, nt );
}
}
public Paths cleanPolygons() {
return cleanPolygons( 1.415 );
}
public Paths cleanPolygons(double distance ) {
final Paths result = new Paths( size() );
for (int i = 0; i < size(); i++) {
result.add( get( i ).cleanPolygon( distance ) );
}
return result;
}
public LongRect getBounds() {
int i = 0;
final int cnt = size();
final LongRect result = new LongRect();
while (i < cnt && get( i ).isEmpty()) {
i++;
}
if (i == cnt) {
return result;
}
result.left = get( i ).get( 0 ).getX();
result.right = result.left;
result.top = get( i ).get( 0 ).getY();
result.bottom = result.top;
for (; i < cnt; i++) {
for (int j = 0; j < get( i ).size(); j++) {
if (get( i ).get( j ).getX() < result.left) {
result.left = get( i ).get( j ).getX();
}
else if (get( i ).get( j ).getX() > result.right) {
result.right = get( i ).get( j ).getX();
}
if (get( i ).get( j ).getY() < result.top) {
result.top = get( i ).get( j ).getY();
}
else if (get( i ).get( j ).getY() > result.bottom) {
result.bottom = get( i ).get( j ).getY();
}
}
}
return result;
}
public void reversePaths() {
for (final Path poly : this) {
poly.reverse();
}
}
}