Open Lecrapouille opened 10 months ago
Tanks you for your answer ! Ok for the JS const not working like C++const ! If I remember well there is also something weird with Julia lang :) I'll test your code and log and compare with me, this will make me practice a little JS ;)
EDIT: I had time to investigate carefully. My code has still bugs (missing kept segments, potential infinite loop, or missing segments detection depending if you use float or double), https://github.com/Lecrapouille/BacASable/tree/master/GameEngine/SFML/Roads
I could just investigate today:
&& int.offset != 1 && int.offset != 0) {
and split segments have a common intersection, so the getIntersection() was always true, and a new segment was added at each iteration and since the for-loops are iterating on a growing array they never stop. BUT this method does not work well if two roads intersect perpendicularly on their semicircles: vertices on circles on both roads are superposed and the offset check make them discarded.
Hi! Last time I made a portage of your road envelope in C++ and SFML (I'm not yet sharing because broken. It almost working but I've some bugs that, by missing time not been fully investigated). When implementing the C++ I noticed an issue in my code concerning the break polygon function. I'm not a JS dev, so I'm not sure to understand how memory is managed, I'm thinking as a C++ dev maybe.
https://github.com/gniziemazity/virtual-world/blob/b9482cf3ec387c9d46b0b7c7a5976e85e91d0f72/4.%20Roads/js/primitives/polygon.js#L42-L65
poly1.segments
how segments are internally implemented? Linked list or array?const segs1 = poly1.segments;
is segs1 a pointer on poly1.segments or a full copy ? I guess this is a pointer since there is nopoly1.segments = segs1
at the end of the function. Whyconst
if it is spliced later in the function?for (let i = 0; i < segs1.length; i++)
should be iterated maybe backward but usingpoly1.segments
and segs a copy of the original array, because when splicing segs1 you add one element in the array and you iterating on the new size. Let's suppose this adds every time a new element, you end with an infinite loop (not your case, but my case). I guess we do not need to iterate on newly split segments for getIntersection, right? I dunno why my C++ code is buggy with your code or my changes. I think I also have different behavior from you when I iterate on an "L" road: the intersection of circles when offset == 0 or 1.this.points
to match segments in the case the polygon is still used for later usage.