vectorized rung builder
This commit is contained in:
@@ -23,7 +23,7 @@ const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const hideDetails = true
|
||||
|
||||
const now = computed(()=>DateTime.fromSeconds(props.modelValue).setZone(s.timeZone))
|
||||
const now = computed(()=>{console.log('ate now',props.modelValue); return DateTime.fromSeconds(props.modelValue).setZone(s.timeZone)})
|
||||
|
||||
const year = computed({
|
||||
get() { return now.value.year },
|
||||
|
||||
@@ -233,16 +233,7 @@ function setModelValue(model, value) {
|
||||
}
|
||||
|
||||
function setValues(values) {
|
||||
// console.log('setValues', values)
|
||||
times.value = values.map((t)=>Math.round(t))
|
||||
/*
|
||||
if (!props.builder.relative)
|
||||
rawTimes.value = values
|
||||
else {
|
||||
const now = s.clock
|
||||
rawTimes.value = values.map((v)=>v-now)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function setWeights(ws) { weights.value = ws }
|
||||
|
||||
@@ -79,6 +79,11 @@ watchEffect(()=>{
|
||||
})
|
||||
|
||||
|
||||
function setEndpoints(a, b) {
|
||||
endpoints.value = [devectorize(a), devectorize(b)]
|
||||
}
|
||||
|
||||
|
||||
const rungs = computed({
|
||||
get() {
|
||||
return props.builder.rungs
|
||||
@@ -89,6 +94,8 @@ const rungs = computed({
|
||||
return
|
||||
}
|
||||
let [a,b] = endpoints.value
|
||||
a = vectorize(a)
|
||||
b = vectorize(b)
|
||||
r = Number(r)
|
||||
const prevR = Number(props.builder.rungs)
|
||||
props.builder.rungs = r
|
||||
@@ -98,13 +105,13 @@ const rungs = computed({
|
||||
// convert single shape to a range
|
||||
if (props.mode===0) {
|
||||
const width = props.stdWidth
|
||||
const mid = a
|
||||
const mid = vectorize(a)
|
||||
a = vectorAdd(mid, -width/2)
|
||||
b = vectorAdd(mid, +width/2)
|
||||
endpoints.value = [a,b]
|
||||
setEndpoints(a,b)
|
||||
}
|
||||
else if (props.mode===1 ) {
|
||||
endpoints.value = [a, vectorAdd(a,props.stdWidth)]
|
||||
setEndpoints(a, vectorAdd(a,props.stdWidth))
|
||||
}
|
||||
else
|
||||
throw Error(`Unknown rung mode ${props.mode}`)
|
||||
@@ -114,14 +121,15 @@ const rungs = computed({
|
||||
if (props.mode===0)
|
||||
a = vectorDiv(vectorAdd(a,b), 2)
|
||||
b = null
|
||||
endpoints.value = [a, b]
|
||||
setEndpoints(a,b)
|
||||
}
|
||||
else {
|
||||
// from multi to multi
|
||||
if (props.mode===1) {
|
||||
console.log('multi-multi mode 1')
|
||||
const width = vectorDiv(vectorSub(b, a), (prevR-1))
|
||||
b = vectorMul(vectorAdd(a, width), (r-1))
|
||||
endpoints.value = [a, b]
|
||||
b = vectorAdd(a, vectorMul(width, (r-1)))
|
||||
setEndpoints(a,b)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,14 +137,15 @@ const rungs = computed({
|
||||
|
||||
|
||||
const values = computed(()=>{
|
||||
const [a, b] = endpoints.value
|
||||
console.log('values', a, b)
|
||||
let [a, b] = endpoints.value
|
||||
a = vectorize(a)
|
||||
b = vectorize(b)
|
||||
const r = props.builder.rungs
|
||||
let result
|
||||
if ( !r || vectorIsNull(a) )
|
||||
result = [] // no data
|
||||
else if (r===1)
|
||||
result = [a] // single shape
|
||||
result = [devectorize(a)] // single shape
|
||||
else {
|
||||
const columns = []
|
||||
for (let i=0; i<a.length; i++)
|
||||
@@ -150,7 +159,6 @@ const values = computed(()=>{
|
||||
result.push(devectorize(vector))
|
||||
}
|
||||
}
|
||||
console.log('vectorized values', result)
|
||||
props.setValues(result)
|
||||
return result;
|
||||
})
|
||||
@@ -226,7 +234,7 @@ function translateOnModel(shape) {
|
||||
a = vectorAdd(a, delta)
|
||||
if (rungs.value > 1)
|
||||
b = vectorAdd(b, delta)
|
||||
endpoints.value = [a, b]
|
||||
setEndpoints(a,b)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +248,7 @@ const shapeA = createShape(endpoints.value[0], {color: defaultColor},
|
||||
function (model) {
|
||||
const value = getModelValue(model);
|
||||
if (value !== endpoints.value[0])
|
||||
endpoints.value = [value, endpoints.value[1]]
|
||||
setEndpoints(value, endpoints.value[1])
|
||||
setModelColor(model)
|
||||
},
|
||||
deleteSelf)
|
||||
@@ -252,7 +260,7 @@ const shapeB = createShape(endpoints.value[1], {color:defaultColor},
|
||||
function (model) {
|
||||
const value = getModelValue(model);
|
||||
if (value !== endpoints.value[1])
|
||||
endpoints.value = [endpoints.value[0], value]
|
||||
setEndpoints(endpoints.value[0], value)
|
||||
setModelColor(model)
|
||||
},
|
||||
deleteSelf)
|
||||
|
||||
Reference in New Issue
Block a user