initial diagonal work (unfinished)
This commit is contained in:
@@ -11,48 +11,59 @@ export function vectorize(value) {
|
||||
}
|
||||
|
||||
export function devectorize(value) {
|
||||
return value === null || value.length === 0 ? null : value.length === 1 ? value[0] : value
|
||||
return value === null || value.length === 0 ? null : value.length === 1 ? value[0] : value
|
||||
}
|
||||
|
||||
|
||||
export function vectorIsNull(value) {
|
||||
console.log('vectorIsNull', value, value === null || value.length === 1 && value[0] === null)
|
||||
return value === null || value.length === 1 && value[0] === null
|
||||
return value === null || value.length === 1 && value[0] === null
|
||||
}
|
||||
|
||||
|
||||
export function vectorIsZero(value) {
|
||||
for (let i = 0; i < value.length; i++)
|
||||
if (value[i] !== 0)
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
export function vectorAdd(a, b) {
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for( let i=0; i<a.length; i++ )
|
||||
result.push(a[i]+(scalarB ? b : b[i]))
|
||||
console.log('vectorAdd', a, b, result)
|
||||
return result
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for (let i = 0; i < a.length; i++)
|
||||
result.push(a[i] + (scalarB ? b : b[i]))
|
||||
return result
|
||||
}
|
||||
|
||||
export function vectorSub(a, b) {
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for( let i=0; i<a.length; i++ )
|
||||
result.push(a[i]-(scalarB ? b : b[i]))
|
||||
console.log('vectorSub', a, b, result)
|
||||
return result
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for (let i = 0; i < a.length; i++)
|
||||
result.push(a[i] - (scalarB ? b : b[i]))
|
||||
return result
|
||||
}
|
||||
|
||||
export function vectorMul(a, b) {
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for( let i=0; i<a.length; i++ )
|
||||
result.push(a[i]*(scalarB ? b : b[i]))
|
||||
console.log('vectorMul', a, b, result)
|
||||
return result
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for (let i = 0; i < a.length; i++)
|
||||
result.push(a[i] * (scalarB ? b : b[i]))
|
||||
return result
|
||||
}
|
||||
|
||||
export function vectorDiv(a, b) {
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for( let i=0; i<a.length; i++ )
|
||||
result.push(a[i]/(scalarB ? b : b[i]))
|
||||
console.log('vectorDiv', a, b, result)
|
||||
return result
|
||||
const result = []
|
||||
const scalarB = b.length === undefined
|
||||
for (let i = 0; i < a.length; i++)
|
||||
result.push(a[i] / (scalarB ? b : b[i]))
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
export function vectorInterpolate(a, b, zeroToOne) {
|
||||
const d = vectorSub(b, a)
|
||||
const offset = vectorMul(d, zeroToOne)
|
||||
return vectorAdd(a, offset)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user