@@ -150,11 +150,9 @@ class BuildingPart {
150150 if ( calculatedOptions . roof . direction === undefined && directionalRoofs . includes ( calculatedOptions . roof . shape ) ) {
151151 // Radians pi > x >= -pi
152152 let longestSide = BuildingShapeUtils . longestSideAngle ( this . shape ) ;
153- if ( longestSide < 0 ) {
154- longestSide += Math . PI ;
155- }
153+
156154 // Convert to angle.
157- calculatedOptions . roof . direction = longestSide / Math . PI * 180 + 90 ;
155+ calculatedOptions . roof . direction = this . atanRadToCompassDeg ( longestSide ) ;
158156 }
159157 const extents = BuildingShapeUtils . extents ( this . shape , calculatedOptions . roof . direction / 360 * 2 * Math . PI ) ;
160158 const shapeHeight = extents [ 3 ] - extents [ 1 ] ;
@@ -278,12 +276,12 @@ class BuildingPart {
278276 } else if ( this . options . roof . shape === 'gabled' ) {
279277 var angle = this . options . roof . direction ;
280278 if ( this . options . roof . orientation === 'across' ) {
281- angle = angle > 90 ? angle - 90 : angle + 90 ;
279+ angle = ( angle + 90 ) % 360 ;
282280 }
283281 const center = BuildingShapeUtils . center ( this . shape , angle / 180 * Math . PI ) ;
284282 const options = {
285283 center : center ,
286- angle : angle / 360 * 2 * Math . PI ,
284+ angle : ( 360 - angle ) / 360 * 2 * Math . PI ,
287285 depth : this . options . roof . height ,
288286 } ;
289287 const geometry = new WedgeGeometry ( this . shape , options ) ;
@@ -425,6 +423,18 @@ class BuildingPart {
425423 return degreesTimesTwo % 2 === 0 ? degreesTimesTwo / 2 : ( degreesTimesTwo - 1 ) / 2 ;
426424 }
427425
426+ /**
427+ * OSM compass degrees are 0-360 clockwise.
428+ *
429+ * @return {number } degrees
430+ */
431+ 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 ;
436+ }
437+
428438 /**
429439 * Get the THREE.material for a given way
430440 *
0 commit comments