import { CornerType } from "bp/content/json" ; import { Direction , nextQuadrantOffset , opposite , previousQuadrantOffset , quadrantNumber } from "bp/global" ; import { clone } from "bp/util" ; import type { JJunction , JOverlap , JPartition } from "bp/content/json" ; export namespace ConfigUtil { param i1 param i2 param oriented param reverse returns 連接到別人的那一個  JOverlap export function $joinOverlaps ( o1 , o2 , i1 , i2 , oriented , reverse = false ) { if ( reverse ) { [ o1 , o2 ] = [ o2 , o1 ] ; [ i1 , i2 ] = [ i2 , i1 ] ; } let c = oriented ? Direction . UR : Direction . LL ; let offset = o2 . ox > o1 . ox ? previousQuadrantOffset : nextQuadrantOffset ; let q = ( offset + c ) % quadrantNumber ; o2 . c [ c ] = { type : CornerType . $coincide , e : i1 , q : c } ; o2 . c [ q ] = { type : CornerType . $intersection , e : o1 . c [ opposite ( c ) ] . e } ; o1 . c [ opposite ( q ) ] = { type : CornerType . $coincide , e : i2 , q } ; return o2 ; } /**
     * 把一個  JJunction 垂直或水平切割為二。
     *
     *  param index 這個  JJunction 的自身索引
     *  param id export function $cut ( j , index , id , x , y ) { let o1 = $toOverlap ( j , index ) , o2 = $toOverlap ( j , index ) ; if ( x > 0 ) { o1 . c [ 2 ] = { type : CornerType . $internal , e : id - 1 , q : 3 } ; o1 . c [ 1 ] = { type : CornerType . $socket , e : id - 1 , q : 0 } ; o1 . ox = x ; o2 . c [ 3 ] = { type : CornerType . $socket , e : id , q : 2 } ; o2 . c [ 0 ] = { type : CornerType . $internal , e : id , q : 1 } ; o2 . ox = j . ox - x ; o2 . shift = { x , y : 0 } ; } else { o1 . c [ 2 ] = { type : CornerType . $internal , e : id - 1 , q : 1 } ; o1 . c [ 3 ] = { type : CornerType . $socket , e : id - 1 , q : 0 } ; o1 . oy = y ; o2 . c [ 1 ] = { type : CornerType . $socket , e : id , q : 2 } ; o2 . c [ 0 ] = { type : CornerType . $internal , e : id , q : 3 } ; o2 . oy = j . oy - y ; o2 . shift = { x : 0 , y } ; } return [ { overlaps : [ o1 ] } , { overlaps : [ o2 ] } ] ; } /** 把一個  JJunction 複製出一個對應的  JOverlap export function $toOverlap ( j , index ) { return { c : clone ( j . c ) , ox : j . ox , oy : j . oy , parent : index , } ; } }