Skip to content

Commit 84b619d

Browse files
Beakerboydeevroman
andauthored
Dev (#137)
* Update BuildingShapeUtils.js * Update utils.test.js * Update utils.test.js * Update buildingpart.test.js * Update BuildingShapeUtils.js * Update buildingpart.test.js * Update from main (#133) * Split data downloading and building creating (#118) * Outer building visibility (#119) * Visibility (#120) * Update building.js (#121) * Tests for API (#122) * check HTTP code status and show alert with error * tests for API errors * Show validation errors (#123) * show validation errors + tests * fix typo * Skip incompleted ways, skip non-way members, prevent global modification of way object (#100) * skip non-way members, skip incompleted ways, prevent global modification of Document with way * add test * better colors for MeshPhysicalMaterial (#126) * Fix crash when processing type=building with outline being a multipolygon (#124) * #88 initial support type=building with multipolygon outline * support multiple ways in inner rings * add test * Hipped roof (#128) * Update BuildingShapeUtils.js (#129) * Update BuildingShapeUtils.js (#130) * Update utils.test.js (#132) --------- Co-authored-by: Roman Deev <roman.deev06@gmail.com> * Update building.test.js * Update buildingpart.js * Fixed direction bug (#136) * Update utils.test.js --------- Co-authored-by: Roman Deev <roman.deev06@gmail.com>
1 parent 872168a commit 84b619d

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

src/buildingpart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class BuildingPart {
270270
const options = {
271271
center: center,
272272
angle: angle / 180 * Math.PI,
273-
depth: this.options.roof.height,
273+
depth: this.options.roof.height ?? 3,
274274
};
275275
const geometry = new WedgeGeometry(this.shape, options);
276276

@@ -434,7 +434,7 @@ class BuildingPart {
434434

435435
/**
436436
* OSM compass degrees are 0-360 clockwise.
437-
*
437+
* 0 degrees is North.
438438
* @return {number} degrees
439439
*/
440440
static atanRadToCompassDeg(rad) {

src/extras/BuildingShapeUtils.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ class BuildingShapeUtils extends ShapeUtils {
287287
*/
288288
static combineCoordinates(shape) {
289289
const points = shape.extractPoints().shape;
290-
points.pop();
291290
var x = [];
292291
var y = [];
293292
var vec;
@@ -337,7 +336,6 @@ class BuildingShapeUtils extends ShapeUtils {
337336
*/
338337
static edgeLength(shape) {
339338
const points = shape.extractPoints().shape;
340-
points.pop();
341339
const lengths = [];
342340
var p1;
343341
var p2;
@@ -359,7 +357,6 @@ class BuildingShapeUtils extends ShapeUtils {
359357
*/
360358
static vertexAngle(shape) {
361359
const points = shape.extractPoints().shape;
362-
points.pop();
363360
const angles = [];
364361
var p0;
365362
var p1;
@@ -394,7 +391,6 @@ class BuildingShapeUtils extends ShapeUtils {
394391
*/
395392
static edgeDirection(shape) {
396393
const points = shape.extractPoints().shape;
397-
points.pop();
398394
const angles = [];
399395
var p1;
400396
var p2;
@@ -418,7 +414,6 @@ class BuildingShapeUtils extends ShapeUtils {
418414
static surrounds(shape, point) {
419415
var count = 0;
420416
const vecs = shape.extractPoints().shape;
421-
vecs.pop();
422417
var vec;
423418
var nextvec;
424419
for (let i = 0; i < vecs.length; i++) {
@@ -468,7 +463,7 @@ class BuildingShapeUtils extends ShapeUtils {
468463
* Return the angle of the longest side of a shape with 90° vertices.
469464
*
470465
* @param {THREE.Shape} shape - the shape
471-
* @return {number}
466+
* @return {number} in radians from Pi > x > -Pi
472467
*/
473468
static longestSideAngle(shape) {
474469
const lengths = BuildingShapeUtils.edgeLength(shape);

test/building.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ test('Test downloading type=building with multipolygon outline and multiple inne
309309
const building = new Building('42', innerData);
310310
expect(building.id).toBe('42');
311311
expect(building.outerElement.shape.holes.length).toBe(1);
312+
const urlBase = 'https://api.openstreetmap.org/api/0.6/';
313+
expect(global.fetch.mock.calls[0][0]).toBe(urlBase + 'relation/42/full');
314+
expect(global.fetch.mock.calls[1][0]).toBe(urlBase + 'relation/40/full');
315+
expect(global.fetch.mock.calls[2][0]).toBe(urlBase + 'map?bbox=30.4980057,59.9380365,30.4993839,59.9385087');
312316
});
313317

314318
window.printError = printError;

test/buildingpart.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ test('Constructor', () => {
6161
expect(part.options.roof.orientation).toBe('along');
6262

6363
// toDo: Mock BuildingShapeUtils and test options
64+
expect(BuildingShapeUtils.edgeDirection(part.shape)).toStrictEqual([1.5707963267948966, 0, -1.5707963267948966, 3.141592653589793]);
65+
expect(BuildingShapeUtils.longestSideAngle(part.shape)).toBe(1.5707963267948966);
6466
expect(part.options.roof.direction).toBe(90);
6567
expect(errors.length).toBe(0);
6668
});

test/utils.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,17 @@ const rightTriangle = new Shape();
115115
rightTriangle.moveTo(1, 1);
116116
rightTriangle.lineTo(1, -1);
117117
rightTriangle.lineTo(-1, 1);
118-
rightTriangle.lineTo(1, 1);
119118

120119
const rightTriangle2 = new Shape();
121120
rightTriangle2.moveTo(1, 1);
122121
rightTriangle2.lineTo(-1, 1);
123122
rightTriangle2.lineTo(1, -1);
124-
rightTriangle2.lineTo(1, 1);
125123

126124
const rectangle = new Shape();
127125
rectangle.moveTo(-4.332738077015795, -5.882209888874915);
128126
rectangle.lineTo(-4.332738077015795, 5.88221335051411);
129127
rectangle.lineTo(4.332747472106493, 5.88221335051411);
130128
rectangle.lineTo(4.332747472106493, -5.882209888874915);
131-
rectangle.lineTo(-4.332738077015795, -5.882209888874915);
132129

133130
test('Extents no Rotation', () => {
134131
expect(BuildingShapeUtils.extents(rightTriangle)).toStrictEqual([-1, -1, 1, 1]);

0 commit comments

Comments
 (0)