-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// TODO snap candidates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:vector_math/vector_math_64.dart'; | ||
|
||
class EditorLogic { | ||
static bool interceptsSquare(Offset parent, Offset child, double size) { | ||
Rect rect = Rect.fromCenter(center: parent, width: size, height: size); | ||
return rect.contains(child); | ||
} | ||
|
||
static bool interceptsCircle(Offset parent, Offset child, double radius) { | ||
double distance = (parent - child).distanceSquared; | ||
return distance < radius * radius; | ||
} | ||
|
||
static Offset nearestPointOnLine(Offset start, Offset end, Offset offset) { | ||
final Vector2 startVector = Vector2(start.dx, start.dy); | ||
final Vector2 endVector = Vector2(end.dx, end.dy); | ||
final Vector2 pointVector = Vector2(offset.dx, offset.dy); | ||
|
||
final Vector2 lineVector = endVector - startVector; | ||
|
||
final Vector2 startToPointVector = pointVector - startVector; | ||
|
||
final double lineLengthSquared = lineVector.length2; | ||
final double t = (lineVector.dot(startToPointVector)) / lineLengthSquared; | ||
|
||
Vector2 nearestPoint; | ||
if (t < 0) { | ||
nearestPoint = startVector; | ||
} else if (t > 1) { | ||
nearestPoint = endVector; | ||
} else { | ||
nearestPoint = startVector + lineVector * t; | ||
} | ||
|
||
return Offset(nearestPoint.x, nearestPoint.y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.