import { EarthConstants , GeoCoordinates , webMercatorProjection } from "@here/harp-geoutils" ; import { Math2D } from "@here/harp-utils" ; import { Vector2 , Vector3 } from "three" ; import { ClippingEdge } from "./ClipPolygon" ; class ClipEdge extends ClippingEdge { readonly p0 : Vector2 ; readonly p1 : Vector2 ; constructor ( p0 , p1 , private readonly isInside ) { super ( ) ; this . p0 = new Vector2 ( ) . fromArray ( p0 ) ; this . p1 = new Vector2 ( ) . fromArray ( p1 ) ; } inside ( point , extent ) { return this . isInside ( point ) ; } remarks https *    | line-line intersection}.
      computeIntersection ( a , b , extent ) { const result = new Vector2 ( ) ; Math2D . intersectLines ( a . x , a . y , b . x , b . y , this . p0 . x , this . p0 . y , this . p1 . x , this . p1 . y , result ) ; return result ; } } const ec = EarthConstants . EQUATORIAL_CIRCUMFERENCE ; const border = ec * 0.05 ; const WRAP_MIDDLE_CLIP_EDGES = [ new ClipEdge ( [ 0 - border , ec ] , [ 0 - border , 0 ] , p => p . x > 0 - border ) , new ClipEdge ( [ ec + border , 0 ] , [ ec + border , ec ] , p => p . x < ec + border ) ] ; const WRAP_LEFT_CLIP_EDGES = [ new ClipEdge ( [ - ec - border , ec ] , [ - ec - border , 0 ] , p => p . x > - ec - border ) , new ClipEdge ( [ 0 + border , 0 ] , [ 0 + border , ec ] , p => p . x < 0 + border ) ] ; const WRAP_RIGHT_CLIP_EDGES = [ new ClipEdge ( [ ec - border , ec ] , [ ec - border , 0 ] , p => p . x > ec - border ) , new ClipEdge ( [ ec * 2 + border , 0 ] , [ ec * 2 + border , ec ] , p => p . x < ec * 2 + border ) ] ; function wrapPolygonHelper ( polygon , edges , offset ) { for ( const clip of edges ) { polygon = clip . clipPolygon ( polygon , 0 ) ; } const worldP = new Vector3 ( ) ; const coordinates = polygon . map ( ( { x , y } ) => { worldP . set ( x , y , 0 ) ; const geoPoint = webMercatorProjection . unprojectPoint ( worldP ) ; geoPoint . longitude += offset ; return geoPoint ; } ) ; return coordinates . length > 0 ? coordinates : undefined ; } interface WrappedPolygon { left : GeoCoordinates [ ] ; middle : GeoCoordinates [ ] ; right : GeoCoordinates [ ] ; } remarks param coordinates export function wrapPolygon ( coordinates ) { const worldP = new Vector3 ( ) ; const projectedPolygon = coordinates . map ( g => { const { x , y } = webMercatorProjection . projectPoint ( g , worldP ) ; return new Vector2 ( x , y ) ; } ) ; return { left : wrapPolygonHelper ( projectedPolygon , WRAP_LEFT_CLIP_EDGES , 360 ) , middle : wrapPolygonHelper ( projectedPolygon , WRAP_MIDDLE_CLIP_EDGES , 0 ) , right : wrapPolygonHelper ( projectedPolygon , WRAP_RIGHT_CLIP_EDGES , - 360 ) } ; }