File tree Expand file tree Collapse file tree 4 files changed +26
-10
lines changed
Expand file tree Collapse file tree 4 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -429,12 +429,9 @@ class BuildingPart {
429429 * @return {number } degrees
430430 */
431431 static atanRadToCompassDeg ( rad ) {
432- if ( rad > 0 ) {
433- rad = rad - 2 * Math . PI ;
434- }
435- return ( ( rad * - 1 + Math . PI / 2 ) % ( 2 * Math . PI ) ) * 360 ;
432+ return ( ( Math . PI - rad + 3 * Math . PI / 2 ) % ( 2 * Math . PI ) ) * 180 / Math . PI ;
436433 }
437-
434+
438435 /**
439436 * Get the THREE.material for a given way
440437 *
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class BuildingShapeUtils extends ShapeUtils {
99 * Create the shape of this way.
1010 *
1111 * @param {DOM.Element } way - OSM XML way element.
12- * @param {[ number, number] } nodelist - list of all nodes
12+ * @param {number => number[2 ] } nodelist - dictionary of all nodes
1313 *
1414 * @return {THREE.Shape } shape - the shape
1515 */
@@ -27,7 +27,7 @@ class BuildingShapeUtils extends ShapeUtils {
2727 for ( const element of elements ) {
2828 ref = element . getAttribute ( 'ref' ) ;
2929 node = nodelist [ ref ] ;
30- // Th node requires a differnet function call.
30+ // The first node requires a different function call.
3131 if ( first ) {
3232 first = false ;
3333 shape . moveTo ( parseFloat ( node [ 0 ] ) , parseFloat ( node [ 1 ] ) ) ;
Original file line number Diff line number Diff line change @@ -5,3 +5,8 @@ test('Test Cardinal to Degree', () => {
55 expect ( BuildingPart . cardinalToDegree ( 'sSw' ) ) . toBe ( 202 ) ;
66 expect ( BuildingPart . cardinalToDegree ( 'Wse' ) ) . toBeUndefined ( ) ;
77} ) ;
8+
9+ test ( 'radToDeg' , ( ) => {
10+ expect ( BuildingPart . atanRadToCompassDeg ( 0 ) ) . toBe ( 90 ) ;
11+ expect ( BuildingPart . atanRadToCompassDeg ( Math . PI / 2 ) ) . toBe ( 0 ) ;
12+ } ) ;
Original file line number Diff line number Diff line change @@ -15,9 +15,23 @@ import { BuildingShapeUtils } from '../src/extras/BuildingShapeUtils.js';
1515
1616
1717/** Test createShape */
18- // test('', () => {
19- //
20- // });
18+ test ( '' , ( ) => {
19+ var way = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="1"/></way>' ;
20+ let parser = new window . DOMParser ( ) ;
21+ let xmlData = parser . parseFromString ( way , 'text/xml' ) ;
22+ let nodelist = {
23+ 1 : [ 1 , 1 ] ,
24+ 2 : [ 1 , - 1 ] ,
25+ 3 : [ - 1 , 1 ] ,
26+ } ;
27+ const shape = BuildingShapeUtils . createShape ( xmlData , nodelist ) ;
28+ expect ( shape . extractPoints ( ) . shape . length ) . toBe ( 4 ) ;
29+ const points = shape . extractPoints ( ) . shape ;
30+ expect ( [ points [ 0 ] . x , points [ 0 ] . y ] ) . toStrictEqual ( nodelist [ 1 ] ) ;
31+ expect ( [ points [ 1 ] . x , points [ 1 ] . y ] ) . toStrictEqual ( nodelist [ 2 ] ) ;
32+ expect ( [ points [ 2 ] . x , points [ 2 ] . y ] ) . toStrictEqual ( nodelist [ 3 ] ) ;
33+ expect ( [ points [ 0 ] . x , points [ 0 ] . y ] ) . toStrictEqual ( nodelist [ 1 ] ) ;
34+ } ) ;
2135
2236/** Test isClosed */
2337test ( 'Test Closed Way' , ( ) => {
You can’t perform that action at this time.
0 commit comments