Search code examples
javasvgjava-2d

Java2D faster Area alternative


I'm using Java2D in conjunction with apache batik to draw some fairly large svg images.

So far it is working quite nicely, but i am frustrated with the performance of areas. In particular, i have three things i want to accomplish:

  1. merge a bunch of colliding shapes to one large area
  2. removing a bunch of shapes from one large area
  3. checking for colliding shapes

naively, point 1 and 2 can be accomplished with Area.add and Area.subtract. This works, but can easily take up to twenty minutes in an average use case.

Point 3 can be accomplished by subtracting the areas from each other and checking the remaing area. Still slow, but can be sped up to be usable by using some prior spatial hashing or something similar.

Is there a better and faster way to merge/subtract Java2D areas? If not, is there another library which can do this sort of thing faster?

unfortunately, libraries like JOGL or LWJGL do not work on a resolution independent space like svg-paths or the Java2D Paths.


Solution

  • You can try this: AreaX

    According to the author:

    The AreaX class is intended to achieve exactly the same visual results as the Area class. However several possible optimizations have been carefully implemented to reach those results faster.