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 package math.geom2d.domain;
28
29 import java.awt.Graphics2D;
30 import java.util.Collection;
31
32 import math.geom2d.AffineTransform2D;
33
34
35
36
37
38
39
40
41
42 public class BoundaryPolyCurve2D<T extends ContinuousOrientedCurve2D> extends PolyOrientedCurve2D<T> implements ContinuousBoundary2D {
43
44
45
46
47 public BoundaryPolyCurve2D() {
48 super();
49 }
50
51 public BoundaryPolyCurve2D(int n) {
52 super(n);
53 }
54
55 public BoundaryPolyCurve2D(T[] curves) {
56 super(curves);
57 }
58
59 public BoundaryPolyCurve2D(Collection<? extends T> curves) {
60 super(curves);
61 }
62
63
64
65
66
67
68
69
70
71
72 public static <T extends ContinuousOrientedCurve2D> BoundaryPolyCurve2D<T> create(
73 Collection<T> curves) {
74 return new BoundaryPolyCurve2D<T>(curves);
75 }
76
77
78
79
80
81
82 public static <T extends ContinuousOrientedCurve2D> BoundaryPolyCurve2D<T> create(
83 T[] curves) {
84 return new BoundaryPolyCurve2D<T>(curves);
85 }
86
87
88
89
90
91
92
93
94
95 @Override
96 public boolean isClosed() {
97 for (T curve : curves) {
98 if (!curve.isBounded())
99 return false;
100 }
101 return true;
102 }
103
104
105
106
107
108
109
110
111 public Collection<? extends ContinuousBoundary2D> getBoundaryCurves() {
112 return wrapCurve(this);
113 }
114
115 public Domain2D getDomain() {
116 return new GenericDomain2D(this);
117 }
118
119 public void fill(Graphics2D g2) {
120 g2.fill(this.getGeneralPath());
121 }
122
123
124
125
126 @Override
127 public BoundaryPolyCurve2D<? extends ContinuousOrientedCurve2D> getReverseCurve() {
128 ContinuousOrientedCurve2D[] curves2 = new ContinuousOrientedCurve2D[curves
129 .size()];
130 int n = curves.size();
131 for (int i = 0; i<n; i++)
132 curves2[i] = (ContinuousOrientedCurve2D)curves.get(n-1-i).getReverseCurve();
133 return new BoundaryPolyCurve2D<ContinuousOrientedCurve2D>(curves2);
134 }
135
136 @Override
137 public BoundaryPolyCurve2D<ContinuousOrientedCurve2D> transform(
138 AffineTransform2D trans) {
139 BoundaryPolyCurve2D<ContinuousOrientedCurve2D> result =
140 new BoundaryPolyCurve2D<ContinuousOrientedCurve2D>();
141 for (ContinuousOrientedCurve2D curve : curves)
142 result.addCurve((ContinuousOrientedCurve2D)curve.transform(trans));
143 return result;
144 }
145 }