split linear segments as curves
This commit is contained in:
parent
bf7c91536f
commit
7f5b7bab69
@ -235,27 +235,38 @@ export const _generateElementShape = (
|
|||||||
|
|
||||||
// curve is always the first element
|
// curve is always the first element
|
||||||
// this simplifies finding the curve for an element
|
// this simplifies finding the curve for an element
|
||||||
|
const splits = element.segmentSplitIndices || [];
|
||||||
if (!element.roundness) {
|
if (!element.roundness) {
|
||||||
if (options.fill) {
|
if (splits.length === 0) {
|
||||||
shape = [generator.polygon(points as [number, number][], options)];
|
if (options.fill) {
|
||||||
|
shape = [generator.polygon(points as [number, number][], options)];
|
||||||
|
} else {
|
||||||
|
shape = [
|
||||||
|
generator.linearPath(points as [number, number][], options),
|
||||||
|
];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
shape = [generator.linearPath(points as [number, number][], options)];
|
const splitInverse: number[] = [];
|
||||||
|
const splitSet = new Set(splits);
|
||||||
|
for (let i = 0; i < points.length; i++) {
|
||||||
|
if (!splitSet.has(i)) {
|
||||||
|
splitInverse.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shape = [
|
||||||
|
generator.curve(
|
||||||
|
computeMultipleCurvesFromSplits(points, splitInverse),
|
||||||
|
options,
|
||||||
|
),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const pointList: Point[][] = [];
|
shape = [
|
||||||
const splits = element.segmentSplitIndices || [];
|
generator.curve(
|
||||||
let currentIndex = 0;
|
computeMultipleCurvesFromSplits(points, splits),
|
||||||
for (const index of splits) {
|
options,
|
||||||
const slice = points.slice(currentIndex, index + 1);
|
),
|
||||||
if (slice.length) {
|
];
|
||||||
pointList.push([...slice]);
|
|
||||||
}
|
|
||||||
currentIndex = index;
|
|
||||||
}
|
|
||||||
if (currentIndex < points.length - 1) {
|
|
||||||
pointList.push(points.slice(currentIndex));
|
|
||||||
}
|
|
||||||
shape = [generator.curve(pointList as [number, number][][], options)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add lines only in arrow
|
// add lines only in arrow
|
||||||
@ -392,3 +403,22 @@ export const _generateElementShape = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const computeMultipleCurvesFromSplits = (
|
||||||
|
points: readonly Point[],
|
||||||
|
splits: readonly number[],
|
||||||
|
): [number, number][][] => {
|
||||||
|
const pointList: Point[][] = [];
|
||||||
|
let currentIndex = 0;
|
||||||
|
for (const index of splits) {
|
||||||
|
const slice = points.slice(currentIndex, index + 1);
|
||||||
|
if (slice.length) {
|
||||||
|
pointList.push([...slice]);
|
||||||
|
}
|
||||||
|
currentIndex = index;
|
||||||
|
}
|
||||||
|
if (currentIndex < points.length - 1) {
|
||||||
|
pointList.push(points.slice(currentIndex));
|
||||||
|
}
|
||||||
|
return pointList as [number, number][][];
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user