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
31 import math.geom2d.AffineTransform2D;
32 import math.geom2d.Box2D;
33 import math.geom2d.Point2D;
34
35
36
37
38
39
40
41
42
43
44
45 public class GenericDomain2D implements Domain2D {
46
47 protected Boundary2D boundary = null;
48
49 public GenericDomain2D(Boundary2D boundary) {
50 this.boundary = boundary;
51 }
52
53
54
55
56 public Boundary2D getBoundary() {
57 return boundary;
58 }
59
60 public Domain2D complement() {
61 return new GenericDomain2D((Boundary2D)boundary.getReverseCurve());
62 }
63
64
65
66
67 public double getDistance(java.awt.geom.Point2D p) {
68 return Math.max(boundary.getSignedDistance(p.getX(), p.getY()), 0);
69 }
70
71 public double getDistance(double x, double y) {
72 return Math.max(boundary.getSignedDistance(x, y), 0);
73 }
74
75
76
77
78
79
80 public boolean isBounded() {
81
82 if (!boundary.isBounded())
83 return false;
84
85
86
87 Box2D box = boundary.getBoundingBox();
88 Point2D point = new Point2D(box.getMinX(), box.getMinY());
89
90 return !boundary.isInside(point);
91 }
92
93 public boolean isEmpty() {
94 return boundary.isEmpty()&&!this.contains(0, 0);
95 }
96
97 public Domain2D clip(Box2D box) {
98 return new GenericDomain2D(
99 Boundary2DUtils.clipBoundary(this.getBoundary(), box));
100 }
101
102
103
104
105
106 public Box2D getBoundingBox() {
107 if (this.isBounded())
108 return boundary.getBoundingBox();
109 return new Box2D(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
110 Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
111 }
112
113
114
115
116
117 public GenericDomain2D transform(AffineTransform2D trans) {
118 Boundary2D transformed = (Boundary2D)boundary.transform(trans);
119 if (!trans.isDirect())
120 transformed = (Boundary2D)transformed.getReverseCurve();
121 return new GenericDomain2D(transformed);
122 }
123
124 public boolean contains(double x, double y) {
125 return boundary.getSignedDistance(x, y)<=0;
126 }
127
128
129
130
131 public boolean contains(java.awt.geom.Point2D p) {
132 return contains(p.getX(), p.getY());
133 }
134
135 public void draw(Graphics2D g2) {
136 boundary.draw(g2);
137 }
138
139 public void fill(Graphics2D g2) {
140 boundary.fill(g2);
141 }
142 }