Java2D awt.geom.Area Performance woes

Is anyone else using geom.* intensively?

It seems that the Area class is pretty horrendously crap, performance wise. For instance, new Area(…) is many times slower than typical object creation, and even Area.contains( x, y ) is EXTREMELY slow for any halfway-complex Area object.

E.g. for a CAG shape composed of 6 Circle’s and about 3 subtractions and an intersection, I can see 75 ms for “new Area()” (a problem I can avoid by hierarchical caching of Area objects in a tree), and multiple milliseconds for the contains method.

Unless someone knows of an improvement to Convex Hull that can provide the “outer surface of a CAG shape” (i.e. discards any internal “holes”) AND provides some not-too-hard-to-implement method of doing contains( x,y ) tests, I’m stuck with J2D’s versions.

Even any tips on improving performance on them would be gratefully received.

Judging by the descriptions in the Area class, I wouldn’t be surprised if the area is being scanline converted, so anything more complicated than simple rects or polys (ie circles, elipses, etc.) just become a series of thin rectangles :frowning: This is how clip regions and other irregular areas are handled, and the performance is awful there as well…

I posted a ConvexHull class in the shared code section a while ago, which would give you a starting point at least. Failing that, you could try the QuickHull algo.

[quote]Judging by the descriptions in the Area class, I wouldn’t be surprised if the area is being scanline converted, so anything more complicated than simple rects or polys (ie circles, elipses, etc.) just become a series of thin rectangles :frowning: This is how clip regions and other irregular areas are handled, and the performance is awful there as well…

I posted a ConvexHull class in the shared code section a while ago, which would give you a starting point at least. Failing that, you could try the QuickHull algo.
[/quote]
…but I’d expect anything based on scanline conversion to be lightning fast - you’re generating bitmaps, which are just a fancy form of array, which is the fastest possible data structure for random-access. I too have noticed that rectangle-based operations in java.* libraries often blow goats, but it seems really weird that they do. I’d previously always assumed it was just poor implementations in early versions of java - have you noticed poor performance in recent (ie. >=1.3) versions?

I can do convex hull easily enough, but can’t think of any simple relationship between that and the algo I need/describe. At the moment, I’m using j2d’s Area.getPathIterator() to get individual path’s for the different “contours” in a complex, holey Area, and compare the sizes of them to find the biggest.

P.S. - there’s a bug in J2d that I haven’t bothered logging yet, where composing various circles using CAG causes it to create absolutely tiny (typically 0.000001 wide/high) areas in spurious locations. Anyone testing the code visually won’t see them (too small to display), but they’re there!