import { Core } from "./Core" ; import { Segment } from "../types" ; import { Epsilon } from "../Epsilon" ; import type { Path , XEvent } from "../types" ; /** performing self-intersection, so deal with regions */ export class SegmentCore extends Core { public addRegion ( region ) { let pt1 ; let pt2 = region [ region . length - 1 ] ; for ( let i = 0 ; i < region . length ; i ++ ) { pt1 = pt2 ; pt2 = region [ i ] ; let forward = Epsilon . $pointsCompare ( pt1 , pt2 ) ; if ( forward === 0 ) continue ; this . events . addSegment ( new Segment ( forward < 0 ? pt1 : pt2 , forward < 0 ? pt2 : pt1 ) , true ) ; } } public calculate ( inverted ) { return super . calculate ( inverted , false ) ; } protected mergeFill ( ev , eve ) { let toggle ; if ( ev . seg . fill . below === null ) toggle = true ; else toggle = ev . seg . fill . above !== ev . seg . fill . below ; if ( toggle ) eve . seg . fill . above = ! eve . seg . fill . above ; } protected calculateFill ( ev , below , polyInverted1 , polyInverted2 ) { let toggle ; if ( ev . seg . fill . below === null ) toggle = true ; else toggle = ev . seg . fill . above !== ev . seg . fill . below ; if ( ! below ) { ev . seg . fill . below = polyInverted1 ; } else { ev . seg . fill . below = below . seg . fill . above ; } if ( toggle ) ev . seg . fill . above = ! ev . seg . fill . below ; else ev . seg . fill . above = ev . seg . fill . below ; } }