nanomath/src/vector/relational.js

21 lines
815 B
JavaScript
Raw Normal View History

2025-04-28 21:25:02 -07:00
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]))))
})
]