Skip to content

Commit 6fb8449

Browse files
authored
Hipped roof (#1)
* Update BuildingShapeUtils.js * Update utils.test.js * Update utils.test.js * Update buildingpart.test.js * Update BuildingShapeUtils.js * Update buildingpart.test.js * Update index.html * Update buildingpart.js * Update buildingpart.js * Update main.yml * Update main.yml * Update package.json * Update package.json
1 parent 3a31a0e commit 6fb8449

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ jobs:
1010
mkdir ../pyramid
1111
mkdir ../ramp
1212
mkdir ../wedge
13+
mkdir ../hipped
1314
wget -P ../pyramid https://beakerboy.github.io/Threejs-Geometries/src/PyramidGeometry.js
1415
wget -P ../ramp https://beakerboy.github.io/Threejs-Geometries/src/RampGeometry.js
1516
wget -P ../wedge https://beakerboy.github.io/Threejs-Geometries/src/WedgeGeometry.js
17+
wget -P ../hipped https://beakerboy.github.io/Threejs-Geometries/src/HippedGeometry.js
1618
cd ../pyramid
1719
echo '{"name":"pyramid","type":"module","private":true,"scripts":{"test":"npx jest"}}' > "./package.json" && npm init -y
1820
cd ../ramp
1921
echo '{"name":"ramp","type":"module","private":true,"scripts":{"test":"npx jest"}}' > "./package.json" && npm init -y
2022
cd ../wedge
2123
echo '{"name":"wedge","type":"module","private":true,"scripts":{"test":"npx jest"}}' > "./package.json" && npm init -y
24+
cd ../hipped
25+
echo '{"name":"hipped","type":"module","private":true,"scripts":{"test":"npx jest"}}' > "./package.json" && npm init -y
2226
cd ../OSMBuilding
2327
yarn --prod=false
2428
- name: Lint

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"three": "https://unpkg.com/three/build/three.module.js",
1919
"pyramid": "https://beakerboy.github.io/Threejs-Geometries/src/PyramidGeometry.js",
2020
"ramp": "https://beakerboy.github.io/Threejs-Geometries/src/RampGeometry.js",
21-
"wedge": "https://beakerboy.github.io/Threejs-Geometries/src/WedgeGeometry.js"
21+
"wedge": "https://beakerboy.github.io/Threejs-Geometries/src/WedgeGeometry.js",
22+
"hipped": "https://beakerboy.github.io/Threejs-Geometries/src/HippedGeometry.js"
2223
}
2324
}
2425
</script>

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
"jest-fetch-mock": "*",
2020
"jest-matcher-deep-close-to": "*",
2121
"jsdom": "*",
22+
"hipped": "file:../hipped",
2223
"pyramid": "file:../pyramid",
2324
"ramp": "file:../ramp",
24-
"wedge": "file:../wedge"
25+
"wedge": "file:../wedge",
26+
"straight-skeleton": "1.1.0"
2527
},
2628
"scripts": {
2729
"test": "c8 jest"

src/buildingpart.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import {PyramidGeometry} from 'pyramid';
1212
import {RampGeometry} from 'ramp';
1313
import {WedgeGeometry} from 'wedge';
14+
import {HippedGeometry} from 'hipped';
1415
import {BuildingShapeUtils} from './extras/BuildingShapeUtils.js';
1516
/**
1617
* An OSM Building Part
@@ -285,6 +286,15 @@ class BuildingPart {
285286
};
286287
const geometry = new PyramidGeometry(this.shape, options);
287288

289+
material = BuildingPart.getRoofMaterial(this.way);
290+
roof = new Mesh( geometry, material );
291+
roof.rotation.x = -Math.PI / 2;
292+
roof.position.set( 0, this.options.building.height - this.options.roof.height, 0);
293+
} else if (this.options.roof.shape === 'hipped') {
294+
const options = {
295+
depth: this.options.roof.height,
296+
};
297+
const geometry = new HippedGeometry(this.shape, options);
288298
material = BuildingPart.getRoofMaterial(this.way);
289299
roof = new Mesh( geometry, material );
290300
roof.rotation.x = -Math.PI / 2;

test/buildingpart.test.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,7 @@ test('Constructor', () => {
6060
// Gabled with unspecified orientation shal be 'along'
6161
expect(part.options.roof.orientation).toBe('along');
6262

63-
// Troubleshoot Bug
64-
const shape = part.shape.extractPoints().shape;
65-
let value = [shape[0].x, shape[0].y];
66-
expect(value).toStrictEqual([-4.332738077015795, -5.882209888874915]);
67-
value = [shape[1].x, shape[1].y];
68-
expect(value).toStrictEqual([-4.332738077015795, 5.88221335051411]);
69-
value = [shape[2].x, shape[2].y];
70-
expect(value).toStrictEqual([4.332747472106493, 5.88221335051411]);
71-
expect(BuildingShapeUtils.edgeDirection(part.shape)).toStrictEqual([Math.PI / 2, 0, -Math.PI / 2, Math.PI]);
72-
expect(BuildingShapeUtils.longestSideAngle(part.shape)).toBe(Math.PI / 2);
63+
// toDo: Mock BuildingShapeUtils and test options
7364
expect(part.options.roof.direction).toBe(90);
7465
expect(errors.length).toBe(0);
7566
});

test/utils.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ rightTriangle2.lineTo(-1, 1);
124124
rightTriangle2.lineTo(1, -1);
125125
rightTriangle2.lineTo(1, 1);
126126

127+
const rectangle = new Shape();
128+
rectangle.moveTo(-4.332738077015795, -5.882209888874915);
129+
rectangle.lineTo(-4.332738077015795, 5.88221335051411);
130+
rectangle.lineTo(4.332747472106493, 5.88221335051411);
131+
rectangle.lineTo(4.332747472106493, -5.882209888874915);
132+
rectangle.lineTo(-4.332738077015795, -5.882209888874915);
133+
127134
test('Extents no Rotation', () => {
128135
expect(BuildingShapeUtils.extents(rightTriangle)).toStrictEqual([-1, -1, 1, 1]);
129136
});
@@ -152,9 +159,10 @@ test('Vertex Angles counterclockwise', () => {
152159
describe.each([
153160
[rightTriangle, [-Math.PI / 2, 3 * Math.PI / 4, 0], 'CW'],
154161
[rightTriangle2, [Math.PI, -Math.PI / 4, Math.PI / 2], 'CCW'],
162+
[rectangle, [Math.PI / 2, 0, -Math.PI / 2, Math.PI], 'Rect'],
155163
])('Edge Direction', (shape, expected, description) =>{
156164
test(`${description}`, () => {
157-
expect(BuildingShapeUtils.edgeDirection(shape)).toBeDeepCloseTo(expected);
165+
expect(BuildingShapeUtils.edgeDirection(shape)).toStrictEqual(expected);
158166
});
159167
});
160168

0 commit comments

Comments
 (0)