Simplify code
This commit is contained in:
@@ -153,21 +153,19 @@
|
|||||||
const delim = ' ';
|
const delim = ' ';
|
||||||
const className = 'clockwise-orientation';
|
const className = 'clockwise-orientation';
|
||||||
|
|
||||||
triangles.forEach(triangle => {
|
triangles.forEach(t => {
|
||||||
const attr = triangle.getAttribute('points').split(delim);
|
const attr = t.getAttribute('points').split(delim);
|
||||||
const [[xa, ya], [xb, yb], [xc, yc]] = attr.map(t => t.split(',').map(n => +n));
|
const [[xa, ya], [xb, yb], [xc, yc]] = attr.map(t => t.split(','));
|
||||||
const det = (xb - xa) * (yc - ya) - (xc - xa) * (yb - ya);
|
const det = (+xb - +xa) * (+yc - +ya) - (+xc - +xa) * (+yb - +ya);
|
||||||
const pos = `${positionX},${positionY}`;
|
const pos = `${positionX},${positionY}`;
|
||||||
const list = triangle.classList;
|
const cwOrientation = det < 0;
|
||||||
const clockwiseOrientation = det < 0;
|
|
||||||
|
|
||||||
if (pos !== attr.pop()) {
|
if (pos !== attr.pop()) {
|
||||||
attr.push(pos);
|
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?
|
// 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
|
// if all the triangles are obtuse, i only need to check the nearest corner for a collision
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user