From 29588b36d47fb8a52c294b95825163d3775f24dc Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Thu, 18 Dec 2025 15:43:41 -0800 Subject: [PATCH] Simplify code --- html/images/space.svg | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/html/images/space.svg b/html/images/space.svg index ab6c7f8..73adb55 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -153,21 +153,19 @@ const delim = ' '; const className = 'clockwise-orientation'; - triangles.forEach(triangle => { - const attr = triangle.getAttribute('points').split(delim); - const [[xa, ya], [xb, yb], [xc, yc]] = attr.map(t => t.split(',').map(n => +n)); - const det = (xb - xa) * (yc - ya) - (xc - xa) * (yb - ya); + triangles.forEach(t => { + const attr = t.getAttribute('points').split(delim); + const [[xa, ya], [xb, yb], [xc, yc]] = attr.map(t => t.split(',')); + const det = (+xb - +xa) * (+yc - +ya) - (+xc - +xa) * (+yb - +ya); const pos = `${positionX},${positionY}`; - const list = triangle.classList; - const clockwiseOrientation = det < 0; + const cwOrientation = det < 0; if (pos !== attr.pop()) { attr.push(pos); - triangle.setAttribute('points', attr.join(delim)); + t.setAttribute('points', attr.join(delim)); } - clockwiseOrientation ? list.add(className) : list.remove(className); - + t.classList[cwOrientation ? "add" : "remove"](className); // i think i can also discard obtuse triangles? // if all the triangles are obtuse, i only need to check the nearest corner for a collision