Skip to content

Commit 0ab5e7a

Browse files
authored
Update BuildingShapeUtils.js
1 parent 3ec9668 commit 0ab5e7a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/extras/BuildingShapeUtils.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,12 @@ class BuildingShapeUtils extends ShapeUtils {
276276
}
277277

278278
/**
279-
* Calculate the angle at each of a shape's vertex
279+
* Calculate the angle at each of a shape's vertex.
280+
* The angle will be PI > x >= -PI
281+
*
282+
* @param {THREE.Shape} shape - the shape
283+
*
284+
* @return {[number, ...]} the angles in radians.
280285
*/
281286
static vertexAngle(shape) {
282287
const points = shape.extractPoints().shape;
@@ -288,18 +293,33 @@ class BuildingShapeUtils extends ShapeUtils {
288293
p1 = points[0];
289294
p2 = points[1];
290295
let angle = Math.atan2(p2.y - p1.y, p2.x - p1.x) - Math.atan2(p0.y - p1.y, p0.x - p1.x);
296+
if (angle >= Math.PI) {
297+
angle -= Math.PI;
298+
} else if (angle < -Math.PI) {
299+
angle += Math.PI;
300+
}
291301
angles.push(angle);
292302
for (let i = 1; i < points.length - 1; i++) {
293303
p0 = points[i - 1];
294304
p1 = points[i];
295305
p2 = points[i + 1];
296306
angle = Math.atan2(p2.y - p1.y, p2.x - p1.x) - Math.atan2(p0.y - p1.y, p0.x - p1.x);
307+
if (angle >= Math.PI) {
308+
angle -= Math.PI;
309+
} else if (angle < -Math.PI) {
310+
angle += Math.PI;
311+
}
297312
angles.push(angle);
298313
}
299314
p0 = points[points.length - 2];
300315
p1 = points[points.length - 1];
301316
p2 = points[0];
302317
angle = Math.atan2(p2.y - p1.y, p2.x - p1.x) - Math.atan2(p0.y - p1.y, p0.x - p1.x);
318+
if (angle >= Math.PI) {
319+
angle -= Math.PI;
320+
} else if (angle < -Math.PI) {
321+
angle += Math.PI;
322+
}
303323
angles.push(angle);
304324
return angles;
305325
}

0 commit comments

Comments
 (0)