simplify
This commit is contained in:
parent
02dc00a47e
commit
de32256466
@ -519,13 +519,13 @@ const randomNumInBetween = (start: number, end: number) => {
|
|||||||
return Math.random() * (end - start) + start;
|
return Math.random() * (end - start) + start;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateFractionalIndex = ({
|
export const generateFractionalIndex = (
|
||||||
start = FRACTIONAL_INDEX_FLOOR,
|
predecessorElement: ExcalidrawElement | undefined,
|
||||||
end = FRACTIONAL_INDEX_CEILING,
|
successorElement: ExcalidrawElement | undefined,
|
||||||
}: {
|
) => {
|
||||||
start?: number;
|
const start = getFractionalIndex(predecessorElement, FRACTIONAL_INDEX_FLOOR);
|
||||||
end?: number;
|
const end = getFractionalIndex(successorElement, FRACTIONAL_INDEX_CEILING);
|
||||||
}) => {
|
|
||||||
const nextTemp = randomNumInBetween(start, end);
|
const nextTemp = randomNumInBetween(start, end);
|
||||||
return (
|
return (
|
||||||
(randomNumInBetween(nextTemp, end) + randomNumInBetween(start, nextTemp)) /
|
(randomNumInBetween(nextTemp, end) + randomNumInBetween(start, nextTemp)) /
|
||||||
@ -533,12 +533,24 @@ export const generateFractionalIndex = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const getNextFractionalIndexAt = (
|
||||||
|
index: number,
|
||||||
|
allElements: ExcalidrawElement[],
|
||||||
|
) => {
|
||||||
|
const predecessor = allElements[index - 1];
|
||||||
|
const successor = allElements[index + 1];
|
||||||
|
|
||||||
|
return generateFractionalIndex(predecessor, successor);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* normalize the fractional indicies of the elements in the given array such that
|
* normalize the fractional indicies of the elements in the given array such that
|
||||||
* a. all elements have a fraction index between floor and ceiling as defined above
|
* a. all elements have a fraction index between floor and ceiling as defined above
|
||||||
* b. for every element, its fractional index is greater than its predecessor's and smaller than its successor's
|
* b. for every element, its fractional index is greater than its predecessor's and smaller than its successor's
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const normalizeFractionalIndexing = (
|
export const normalizeFractionalIndexing = (
|
||||||
allElements: readonly ExcalidrawElement[],
|
allElements: readonly ExcalidrawElement[],
|
||||||
) => {
|
) => {
|
||||||
@ -558,10 +570,10 @@ export const normalizeFractionalIndexing = (
|
|||||||
successorElement,
|
successorElement,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
const nextFractionalIndex = generateFractionalIndex({
|
const nextFractionalIndex = generateFractionalIndex(
|
||||||
start: getFractionalIndex(predecessorElement, FRACTIONAL_INDEX_FLOOR),
|
predecessorElement,
|
||||||
end: getFractionalIndex(successorElement, FRACTIONAL_INDEX_CEILING),
|
successorElement,
|
||||||
});
|
);
|
||||||
|
|
||||||
normalizedElements.push({
|
normalizedElements.push({
|
||||||
...element,
|
...element,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user