Using Java 2D I've patched several Bezier curves (CubicCurve2D
) together to create a "blob". The problem I now face is how to:
- Efficiently fill the blob with a given colour.
- Efficiently determine whether a given point lies inside the blob.
I noticed thst CubicCurve2D
implements Shape
which provides numerous contains
methods for determining "insideness" and that Graphics2D
is able to fill a Shape
via the fill(Shape)
(which I believe uses Shape
's getPathIterator
methods to do this).
Given this I was hoping I could create a composite Shape
, whereby my getPathIterator(AffineTransform)
method would simply link the underlying PathIterator
s together. However, this is producing a NoSuchElementException
once my shape contains more than one CubicCurve2D
. Even if I do manage to achieve this I'm not convinced it will work as expected because a CubicCurve2D
is always filled on the convex side, and my "blob" is composed of concave and convex curves. The "contains" problem is even harder as a point can legitimately lie within the blob but not within any of the individual curves.
- Am I approaching this problem in the correct way (trying to implement
Shape
?) or is there an idiomatic way to do this that I'm unaware of? I would have thought that the problem of compositing geometric shapes would be fairly common. - Does anyone have any suggestions regarding how to solve this problem?
Thanks in advance.