Skip to content

Commit

Permalink
fix: calculate curve with two nodes in the same position
Browse files Browse the repository at this point in the history
  • Loading branch information
hpawa committed Oct 4, 2023
1 parent 95ce004 commit c82e45b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ function calculateCurvePositionAndState(
let position: LinePosition
let curve: EdgeModel.Curve | undefined = undefined

if (shift === 0) {
if (radius === 0) {
return [originPosition, curve]
} else if (shift === 0) {
// The line connecting the centers of the nodes is regarded as a straight line.
if (sourceMargin === 0 && targetMargin === 0) {
position = originPosition
Expand Down
5 changes: 5 additions & 0 deletions src/modules/calculation/2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ export function calculateCircleCenterAndRadiusBy3Points(
const x32 = x3 - x2
const y32 = y3 - y2

if ((x12 === 0 && y12 === 0) || (x32 === 0 && y32 === 0)) {
// Cannot determine the curve if two or more of the three points are in the same position.
return [p1, 0];
}

const x =
(y32 * (x12 * (x1 + x2) + y12 * (y1 + y2)) - y12 * (x32 * (x3 + x2) + y32 * (y3 + y2))) /
(2 * x12 * y32 - 2 * y12 * x32)
Expand Down

0 comments on commit c82e45b

Please sign in to comment.