Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/extras/BuildingShapeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ class BuildingShapeUtils extends ShapeUtils {
p1 = points[i];
p2 = points[i + 1];
let angle = Math.atan2((p2.y - p1.y), (p2.x - p1.x));
if (angle >= Math.PI / 2) {
angle -= Math.PI;
} else if (angle < -Math.PI / 2) {
angle += Math.PI;
if (angle >= Math.PI) {
angle -= 2 * Math.PI;
} else if (angle < -Math.PI) {
angle += 2* Math.PI;
}
angles.push(angle);
}
Expand Down Expand Up @@ -409,14 +409,12 @@ class BuildingShapeUtils extends ShapeUtils {
}

/**
* Calculate the angle of the longest side of a shape with 90° vertices.
* is begining / end duplicated?
* Return the angle of the longest side of a shape with 90° vertices.
*
* @param {THREE.Shape} shape - the shape
* @return {number}
*/
static longestSideAngle(shape) {
const vecs = shape.extractPoints().shape;
const lengths = BuildingShapeUtils.edgeLength(shape);
const directions = BuildingShapeUtils.edgeDirection(shape);
var index;
Expand Down
19 changes: 11 additions & 8 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ rightTriangle.moveTo(1, 1);
rightTriangle.lineTo(1, -1);
rightTriangle.lineTo(-1, 1);

const rightTriangle2 = new Shape();
rightTriangle2.moveTo(1, 1);
rightTriangle2.lineTo(-1, 1);
rightTriangle2.lineTo(1, -1);

test('Extents no Rotation', () => {
expect(BuildingShapeUtils.extents(rightTriangle)).toStrictEqual([-1, -1, 1, 1]);
});
Expand All @@ -67,13 +72,15 @@ test('Edge Lengths', () => {
});

test('Edge Direction', () => {
expect(BuildingShapeUtils.edgeDirection(rightTriangle)).toBeDeepCloseTo([-Math.PI / 2, -Math.PI / 4, 0]);
expect(BuildingShapeUtils.edgeDirection(rightTriangle)).toBeDeepCloseTo([-Math.PI / 2, 3 * Math.PI / 4, 0]);
});

test('Edge Direction2', () => {
expect(BuildingShapeUtils.edgeDirection(rightTriangle2)).toBeDeepCloseTo([-Math.PI, -Math.PI / 4, Math.PI / 2]);
});

test('Longest side angle', () => {
// A three.Shape object does not repeat the fist and last nodes.
expect(rightTriangle.extractPoints().shape.length).toBe(3);
expect(BuildingShapeUtils.longestSideAngle(rightTriangle)).toBe(-Math.PI / 4);
expect(BuildingShapeUtils.longestSideAngle(rightTriangle)).toBe(3 * Math.PI / 4);
});

describe.each([
Expand Down Expand Up @@ -101,10 +108,6 @@ test('Vertex Angles', () => {
expect(BuildingShapeUtils.vertexAngle(rightTriangle)).toStrictEqual([Math.PI / 2, Math.PI / 4, Math.PI / 4]);
});

const rightTriangle2 = new Shape();
rightTriangle2.moveTo(1, 1);
rightTriangle2.lineTo(-1, 1);
rightTriangle2.lineTo(1, -1);
test('Vertex Angles counterclockwise', () => {
expect(BuildingShapeUtils.vertexAngle(rightTriangle2)).toStrictEqual([-Math.PI / 2, -Math.PI / 4, -Math.PI / 4]);
});
Expand Down