Skip to content

Commit

Permalink
Dev (#66)
Browse files Browse the repository at this point in the history
* Remove Extra 'round' Roof Type

* Remove extranious round roof from list; add cardinal directions to roofs; removing warning of direction=0 for skillion roofs

* Update main.yml

* Extraneous round roof (#64)

* Remove Extra 'round' Roof Type

* Remove extranious round roof from list; add cardinal directions to roofs; removing warning of direction=0 for skillion roofs

* Update main.yml

---------

Co-authored-by: Justin Ormont <[email protected]>

* added lang to html tag
  • Loading branch information
Beakerboy authored Dec 4, 2024
1 parent 228874c commit a00fe4e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI
on: push
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>

<head>
<head lang="en">
<title>OpenStreetMap Building 3D Render</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="style.css">
Expand Down
28 changes: 20 additions & 8 deletions src/buildingpart.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class BuildingPart {
// Should Skillion be included here?
const directionalRoofs = ['gabled', 'round'];
calculatedOptions.roof.direction = this.options.specified.roof.direction ?? this.options.inherited.roof.direction;
if (!calculatedOptions.roof.direction && directionalRoofs.includes(calculatedOptions.roof.shape)) {
if (calculatedOptions.roof.direction === undefined && directionalRoofs.includes(calculatedOptions.roof.shape)) {
// Radians pi > x >= -pi
let longestSide = BuildingShapeUtils.longestSideAngle(this.shape);
if (longestSide < 0) {
Expand Down Expand Up @@ -176,7 +176,7 @@ class BuildingPart {
window.printError('Way ' + this.id + ' is taller than building. (' + this.options.building.height + '>' + this.options.inherited.building.height + ')');
}
// Should skillion automatically calculate a direction perpendicular to the longest outside edge if unspecified?
if (this.options.roof.shape === 'skillion' && !this.options.roof.direction) {
if (this.options.roof.shape === 'skillion' && this.options.roof.direction === undefined) {
window.printError('Part ' + this.id + ' requires a direction. (https://wiki.openstreetmap.org/wiki/Key:roof:direction)');
}
this.extrusionHeight = this.options.building.height - this.options.building.minHeight - this.options.roof.height;
Expand Down Expand Up @@ -388,10 +388,10 @@ class BuildingPart {
* Direction. In degrees, 0-360
*/
static normalizeDirection(direction) {
// if (cardinal) {
// convert to degrees
// return degrees;
// }
const degrees = this.cardinalToDegree(direction);
if (degrees !== undefined) {
return degrees;
}
if (direction) {
return parseFloat(direction);
}
Expand All @@ -407,10 +407,22 @@ class BuildingPart {
}

/**
* Convert a cardinal direction (ESE) to degrees 112°.
* North is zero.
* Convert a cardinal direction to degrees.
* North is zero and values increase clockwise.
*
* @param {string} cardinal - the direction.
*
* @return {int} degrees
*/
static cardinalToDegree(cardinal) {
const cardinalUpperCase = `${cardinal}`.toUpperCase();
const index = 'N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW'.split(' ').indexOf(cardinalUpperCase);
if (index === -1) {
return undefined;
}
const degreesTimesTwo = index * 45;
// integer floor
return degreesTimesTwo % 2 === 0 ? degreesTimesTwo / 2 : (degreesTimesTwo - 1) / 2;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function createFolders(folder, options) {
if (property === 'colour') {
roofFolder.addColor(options.roof, property);
} else if (property === 'shape') {
const roofTypesAvailable = ['dome', 'flat', 'gabled', 'onion', 'pyramidal', 'skillion', 'hipped', 'round', 'gambrel', 'round'];
const roofTypesAvailable = ['dome', 'flat', 'gabled', 'onion', 'pyramidal', 'skillion', 'hipped', 'round', 'gambrel'];
// If this roof is not supported, add it to the list for sanity.
if (!roofTypesAvailable.includes(options.roof.shape)) {
roofTypesAvailable.push(options.roof.shape);
Expand Down
7 changes: 7 additions & 0 deletions test/buildingpart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BuildingPart } from '../src/buildingpart.js';

test('Test Cardinal to Degree', () => {
expect(BuildingPart.cardinalToDegree('N')).toBe(0);
expect(BuildingPart.cardinalToDegree('sSw')).toBe(202);
expect(BuildingPart.cardinalToDegree('Wse')).toBeUndefined();
});

0 comments on commit a00fe4e

Please sign in to comment.