diff --git a/src/buildingpart.js b/src/buildingpart.js index 1e7cdd3..25d4838 100644 --- a/src/buildingpart.js +++ b/src/buildingpart.js @@ -162,7 +162,7 @@ class BuildingPart { (calculatedOptions.roof.shape === 'flat' ? 0 : null) ?? (calculatedOptions.roof.shape === 'dome' || calculatedOptions.roof.shape === 'pyramidal' ? BuildingShapeUtils.calculateRadius(this.shape) : null) ?? (calculatedOptions.roof.shape === 'onion' ? BuildingShapeUtils.calculateRadius(this.shape) * 1.5 : null) ?? - (calculatedOptions.roof.shape === 'skillion' ? (calculatedOptions.roof.angle ? Math.cos(calculatedOptions.roof.angle / 360 * 2 * Math.PI) * shapeHeight : 22.5) : null); + (calculatedOptions.roof.shape === 'skillion' ? (calculatedOptions.roof.angle ? Math.cos(calculatedOptions.roof.angle / 360 * 2 * Math.PI) * shapeHeight : Math.cos(22.5 / 360 * 2 * Math.PI) * shapeHeight) : null); calculatedOptions.building.height = this.options.specified.building.height ?? (isNaN(calculatedOptions.building.levels) ? null : (calculatedOptions.building.levels * 3) + calculatedOptions.roof.height) ?? diff --git a/test/skillion_slope.test.js b/test/skillion_slope.test.js new file mode 100644 index 0000000..dfe26d6 --- /dev/null +++ b/test/skillion_slope.test.js @@ -0,0 +1,614 @@ +/** + * @jest-environment jsdom + */ + +import { Shape, Mesh } from 'three'; +import { TextEncoder } from 'node:util'; +import {expect, test, beforeEach, describe} from '@jest/globals'; +global.TextEncoder = TextEncoder; + +import {apis} from '../src/apis.js'; +global.apis = apis; + +import { Building } from '../src/building.js'; + +import fetchMock from 'jest-fetch-mock'; +fetchMock.enableMocks(); + +// Step 1: get the full data for the buiding from the API +const initialData = ` + + + + + + + + + + + + + + + + + +`; + +// Step 2: get the bounding box data for the buiding from the API +// Paste the same data as above to get the real URL and then fetch and paste that here. +const mapData = ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +`; + +// Describe Issue +test('Diagnose Skillion Issue', async() => { + fetch.mockResponses( + [initialData], // /way/1426868383/full + [mapData], // /map call + ); + let wayId = '1426868383'; + const innerData = await Building.downloadDataAroundBuilding('way', wayId); + const building = new Building(wayId, innerData); + expect(building.id).toBe(wayId); + const urlBase = 'https://api.openstreetmap.org/api/0.6/'; + expect(global.fetch.mock.calls[0][0]).toBe(urlBase + 'way/' + wayId + '/full'); + expect(global.fetch.mock.calls[1][0]).toBe(urlBase + 'map?bbox=-4.3314236,55.8550736,-4.3312202,55.8551787'); + // get building part + const parts = building.parts; + let found = false; + for (const part of parts){ + // Get the building part + if (part.id === '1426868384'){ + expect(part.options.roof.height).toBe(5.284715476364045); + found = true; + } + } + expect(found).toBe(true); +}); + +window.printError = printError; + +var errors = []; + +function printError(txt) { + errors.push[txt]; +}