21 lines
815 B
JavaScript
21 lines
815 B
JavaScript
|
import {Vector} from './Vector.js'
|
||
|
import {NotAType, Returns} from '#core/Type.js'
|
||
|
import {Any, match} from '#core/TypePatterns.js'
|
||
|
import {BooleanT} from '#boolean/BooleanT.js'
|
||
|
|
||
|
export const deepEqual = [
|
||
|
match([Vector, Any], Returns(BooleanT, () => false)),
|
||
|
match([Any, Vector], Returns(BooleanT, () => false)),
|
||
|
match([Vector, Vector], (math, [V, W]) => {
|
||
|
if (V.Component === NotAType || W.Component === NotAType) {
|
||
|
return Returns(BooleanT, (v, w) => v === w
|
||
|
|| (v.length === w.length
|
||
|
&& v.every((e, i) => math.deepEqual(e, w[i]))))
|
||
|
}
|
||
|
const compDeep = math.deepEqual.resolve([V.Component, W.Component])
|
||
|
return Returns(BooleanT, (v,w) => v === w
|
||
|
|| (v.length === w.length
|
||
|
&& v.every((e, i) => compDeep(e, w[i]))))
|
||
|
})
|
||
|
]
|