martinez icon indicating copy to clipboard operation
martinez copied to clipboard

algorithm comparison

Open daef opened this issue 6 years ago • 14 comments

not really an issue, but I wanted to dump a reference here too:

I made a small comparison between some boolean operation algorithms and wanted to share the results: https://daef.github.io/poly-bool-comparison/

preview

daef avatar Mar 19 '20 12:03 daef

Great thing! can you please explain the metrics? I didn't understand the abbrevations

w8r avatar Mar 19 '20 13:03 w8r

I'd like to forward you to the graphicsmagick documentation but it's not very helpful.

Wikipedia got it partially covered thou: MAE, RMSE, PSNR

daef avatar Mar 19 '20 13:03 daef

Thanks a lot!

w8r avatar Mar 19 '20 13:03 w8r

Really really good tool. Thank you.

Llorx avatar Jun 17 '20 11:06 Llorx

have you found a new use case for this hack @Llorx ? i thought it doesn't do much on its own so there's no real benefit to make it more reusable.

daef avatar Jun 18 '20 13:06 daef

@daef Just to see the problems some libraries have with certain polygons. The red/green error deviation thingy was really useful. I was looking for a library with good rectangle handling.

Llorx avatar Jun 18 '20 14:06 Llorx

i guess when there are 'just' axis aligned rects one could do much better than with a generic polygon lib, is performance your main concern or are you looking for something correct/robust? :)

EDIT: reopened, i accidentaly closed the issue

daef avatar Jun 19 '20 09:06 daef

Both, correctness and performant. I need to merge about 200 hundred rectangles into a single polygon in less than 16ms (for drawing to a canvas at 60 fps) but I also need for it to be drawn correctly. I thought that this new algorithm will help, but nope. I lose a lot of frames, so forgot about this solution and now I'm looking for webgl.

Llorx avatar Jun 19 '20 10:06 Llorx

Was it too slow or incorrect?

w8r avatar Jun 19 '20 10:06 w8r

Seems like rasterizing is a more convenient approach in your case.

w8r avatar Jun 19 '20 10:06 w8r

Yeah, maybe I could draw to a canvas and extract the result image as a mask. That's the next step if webgl gets too complicated haha.

In this case it was slow and incorrect, but the slowness I think is because I'm asking too much, and worse if looking for a JavaScript script instead of native code. About the correctness, I was getting some weird edges. This is the black mask image where you can see all the rectangles/squares, some of them overlap: image

When the algo was passed with union, I was getting something like this (drawn with paint, but you get the point): image

By the way, I noticed that is impossible for a normal computer in the browser to have a decent union performance with that amount of rectangles, so I forgot about it.

Llorx avatar Jun 19 '20 10:06 Llorx

Yes, with "cascading" approach it's very heavy. I have faced that problem before in https://github.com/w8r/ploygon-offset

But if you are dealing with rectangles and they are axis-aligned as I see on the picture, it only makes sense to go for raster approach.

w8r avatar Jun 19 '20 10:06 w8r

I guess loading the rects into the GPU encoded as texture and writing a simple shader should do the trick, 200 rects doesnt sound too bad. Maybe give this or that a shot :)

daef avatar Jun 24 '20 08:06 daef

I guess loading the rects into the GPU encoded as texture and writing a simple shader should do the trick, 200 rects doesnt sound too bad. Maybe give this or that a shot :)

Pretty nice, thank you!

Llorx avatar Jun 24 '20 15:06 Llorx