Skip to content

Commit

Permalink
fix: Activate intarval targets on resizing shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
miyanokomiya committed Nov 13, 2024
1 parent 0bdd733 commit 5bb5048
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/composables/shapeSnapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,13 @@ export function getSnappingResultForBoundingBoxResizing(
let snappingResult = snappingResults[0];
const adjustedD = snappingResult ? add(diff, snappingResult.diff) : diff;
const movingPointInfoList: [IVec2, IVec2][] = boundingBoxPath.map((p) => [p, applyAffine(resizingAffine, p)]);
const guidelines = getGuidelinesFromSnappingResult(snappingResult);

// Apply resizing restriction to each snapping candidate
const result = pickMinItem(
snappingResult.targets
.map((target) =>
boundingBoxResizing.getAffineAfterSnapping(adjustedD, movingPointInfoList, target.line, {
guidelines
.map((guideline) =>
boundingBoxResizing.getAffineAfterSnapping(adjustedD, movingPointInfoList, guideline, {
keepAspect,
centralize,
}),
Expand All @@ -788,7 +789,7 @@ export function getSnappingResultForBoundingBoxResizing(
// Pick exact target when it's determined.
snappingResult = {
...snappingResult,
targets: snappingResult.targets.filter((t) => t.line == result[2]),
...filterSnappingTargetsBySecondGuideline(snappingResult, result[2]),
};
} else if (resizingAffine) {
// Need recalculation to get final control lines.
Expand Down Expand Up @@ -856,7 +857,23 @@ export function getSecondGuidelineCandidateInfo(
}),
);

return { candidates: allCandidates, targets: candidateTargets, intervalTargets: candidateIntervals };
const partial = { targets: candidateTargets, intervalTargets: candidateIntervals };
getGuidelinesFromSnappingResult(partial);
return { candidates: getGuidelinesFromSnappingResult(partial), ...partial };
}

function getGuidelinesFromSnappingResult(
snappingResult: Pick<SnappingResult, "targets" | "intervalTargets">,
): ISegment[] {
const allCandidates: ISegment[] = snappingResult.targets.map((t) => t.line);
snappingResult.intervalTargets.forEach((t) =>
t.lines.forEach((l) => {
const v = rotate(sub(l[1], l[0]), Math.PI / 2);
allCandidates.push([l[0], add(l[0], v)], [l[1], add(l[1], v)]);
}),
);

return allCandidates;
}

export function filterSnappingTargetsBySecondGuideline(
Expand Down

0 comments on commit 5bb5048

Please sign in to comment.