import { Projection , sphereProjection } from "@here/harp-geoutils" ; import { Vector3 } from "three" ; import { SubdivisionModifier } from "./SubdivisionModifier" ; const VERTEX_POSITION_CACHE = [ new Vector3 ( ) , new Vector3 ( ) , new Vector3 ( ) ] ; /**
 * The [[SphericalGeometrySubdivisionModifier]] subdivides triangle mesh geometries positioned
 * on the surface of a sphere centered at `(0, 0, 0)`.
 */ export class SphericalGeometrySubdivisionModifier extends SubdivisionModifier { param angle param projection constructor ( readonly angle , readonly projection = sphereProjection ) { super ( ) ; } @override  protected shouldSplitTriangle ( a , b , c ) { const aa = sphereProjection . reprojectPoint ( this . projection , a , VERTEX_POSITION_CACHE [ 0 ] ) ; const bb = sphereProjection . reprojectPoint ( this . projection , b , VERTEX_POSITION_CACHE [ 1 ] ) ; const cc = sphereProjection . reprojectPoint ( this . projection , c , VERTEX_POSITION_CACHE [ 2 ] ) ; const alpha = aa . angleTo ( bb ) ; const beta = bb . angleTo ( cc ) ; const gamma = cc . angleTo ( aa ) ; const m = Math . max ( alpha , Math . max ( beta , gamma ) ) ; if ( m < this . angle ) { return undefined ; } if ( m === alpha ) { return 0 ; } else if ( m === beta ) { return 1 ; } else if ( m === gamma ) { return 2 ; } throw new Error ( "failed to split triangle" ) ; } }