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 pathPolyNode.java
More file actions
115 lines (92 loc) · 2.35 KB
/
PolyNode.java
File metadata and controls
115 lines (92 loc) · 2.35 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
package de.lighti.clipper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.lighti.clipper.Clipper.EndType;
import de.lighti.clipper.Clipper.JoinType;
import de.lighti.clipper.Point.LongPoint;
public class PolyNode {
enum NodeType {
ANY, OPEN, CLOSED
}
private PolyNode parent;
private final Path polygon = new Path();
private int index;
private JoinType joinType;
private EndType endType;
protected final List<PolyNode> childs = new ArrayList<PolyNode>();
private boolean isOpen;
public void addChild( PolyNode child ) {
final int cnt = childs.size();
childs.add( child );
child.parent = this;
child.index = cnt;
}
public int getChildCount() {
return childs.size();
}
public List<PolyNode> getChilds() {
return Collections.unmodifiableList( childs );
}
public List<LongPoint> getContour() {
return polygon;
}
public EndType getEndType() {
return endType;
}
public JoinType getJoinType() {
return joinType;
}
public PolyNode getNext() {
if (!childs.isEmpty()) {
return childs.get( 0 );
}
else {
return getNextSiblingUp();
}
}
private PolyNode getNextSiblingUp() {
if (parent == null) {
return null;
}
else if (index == parent.childs.size() - 1) {
return parent.getNextSiblingUp();
}
else {
return parent.childs.get( index + 1 );
}
}
public PolyNode getParent() {
return parent;
}
public Path getPolygon() {
return polygon;
}
public boolean isHole() {
return isHoleNode();
}
private boolean isHoleNode() {
boolean result = true;
PolyNode node = parent;
while (node != null) {
result = !result;
node = node.parent;
}
return result;
}
public boolean isOpen() {
return isOpen;
}
public void setEndType( EndType value ) {
endType = value;
}
public void setJoinType( JoinType value ) {
joinType = value;
}
public void setOpen( boolean isOpen ) {
this.isOpen = isOpen;
}
public void setParent( PolyNode n ) {
parent = n;
}
}