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