Simplify code
This commit is contained in:
@@ -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
|
||||
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user