import { Diagnose } from "../Diagnose" ; import * as Settings from "../Settings" ; import { PolyBool } from "bp/math" ; import type { Path } from "bp/math" ; /** 特別用來標注某一項計算屬性經過實驗顯示不用進行比較檢查 */ export const noCompare = shrewd ; /** 比較有分順序的陣列 */ export function orderedArray ( msg ? ) ; export function orderedArray ( target , prop ) ; export function orderedArray ( ... p ) { let msg = p . length == 2 ? undefined : p [ 0 ] ; let option = { comparer : ( ov , nv , member ) => { if ( ov === nv ) return true ; let result = Shrewd . comparer . array ( ov , nv ) ; if ( Settings . diagnose && result && msg ) { Diagnose . count ( msg ) ; } return result ; } , } ; if ( p . length == 2 ) shrewd ( option ) ( ... p ) ; else return shrewd ( option ) ; } /** 比較不分順序的陣列 */ export function unorderedArray ( msg ? ) ; export function unorderedArray ( target , prop ) ; export function unorderedArray ( ... p ) { let msg = p . length == 2 ? undefined : p [ 0 ] ; let option = { comparer : ( ov , nv , member ) => { if ( ov === nv ) return true ; let result = Shrewd . comparer . unorderedArray ( ov , nv ) ; if ( Settings . diagnose && result && msg ) { Diagnose . count ( msg ) ; } return result ; } , } ; if ( p . length == 2 ) shrewd ( option ) ( ... p ) ; else return shrewd ( option ) ; } /** 比較  PolyBool shape 一致  export function shape ( msg ? ) ; export function shape ( target , prop ) ; export function shape ( ... p ) { let msg = p . length == 2 ? undefined : p [ 0 ] ; let option = { comparer : ( ov , nv , member ) => { if ( ov === nv ) return true ; if ( ! ov != ! nv ) return false ; if ( ! ov ) return true ; let result = PolyBool . compare ( ov , nv ) ; if ( Settings . diagnose && result && msg ) { Diagnose . count ( msg ) ; } return result ; } , } ; if ( p . length == 2 ) shrewd ( option ) ( ... p ) ; else return shrewd ( option ) ; } /** 比較路徑一致 */ export function path ( msg ? ) ; export function path ( target , prop ) ; export function path ( ... p ) { let msg = p . length == 2 ? undefined : p [ 0 ] ; let option = { comparer : ( ov , nv , member ) => { member . ov = ov ; if ( ov === nv ) return true ; if ( ! ov != ! nv ) return false ; if ( ! ov ) return true ; if ( ov . length != nv . length ) return false ; for ( let i = 0 ; i < ov . length ; i ++ ) { if ( ! ov [ i ] . eq ( nv [ i ] ) ) return false ; } if ( Settings . diagnose && msg ) { Diagnose . count ( msg ) ; } return true ; } , } ; if ( p . length == 2 ) shrewd ( option ) ( ... p ) ; else return shrewd ( option ) ; }