korlibs / korge-ext

MIT License
1 stars 1 forks source link

Shrinking / Growing Polygons #2

Open hooliooo opened 4 years ago

hooliooo commented 4 years ago

Hello,

I've been going through the API of Korma and it's not entirely clear how you reduce/grow a Polygon's area.

Point of reference: https://stackoverflow.com/questions/1109536/an-algorithm-for-inflating-deflating-offsetting-buffering-polygons

soywiz commented 4 years ago

Guess you should use extend with positive/negative values: https://github.com/korlibs/korma/blob/4273bd8789c6379ef0c68fd69f040a1765a22823/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/Ops.kt#L18

hooliooo commented 4 years ago

It somewhat works where I have VectorPathA with these points: [(1, 1), (15, 1), (15, 10), (10, 10), (10, 5), (7, 5), (7, 10), (1, 10)]

when I call extend(size = -1.0) on its Shape2d, I correctly get these points: [(14, 9), (11, 9), (11, 4), (6, 4), (6, 9), (2, 9), (2, 2), (14, 2)]

However when I call extend(size = -0.5) I get these points instead: [(14, 10), (10, 10), (10, 4), (6, 4), (6, 10), (2, 10), (2, 2), (14, 2)]

I'd expect to get: [(14.5, 9.5), (10.5, 9.5), (10.5, 4.5), (6.5, 4.5), (6.5, 9.5), (1.5, 9.5), (1.5, 1.5), (14.5, 1.5)]