Skip to content

Commit

Permalink
Update point snap logic
Browse files Browse the repository at this point in the history
  • Loading branch information
twangodev committed Jul 28, 2024
1 parent 395739e commit d945528
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/widgets/editor/editor_painter_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,27 @@ class EditorData extends ChangeNotifier {

MapEntry<String, Offset>? nearestPointSnap(
Offset offset, String? ignoreUuid) {

MapEntry<String, Offset>? nearestPointSnap = null;
double nearestDistance = double.infinity;
for (MapEntry<String, Offset> entry in toolData.points.entries) {
if (entry.key == ignoreUuid) continue;
if (EditorLogic.interceptsCircle(entry.value, offset,
EditorConfig.defaultSnapTolerance / 2 * scaleInverse)) {
return entry;

Offset point = entry.value;
Offset delta = point - offset;
double distance = delta.distanceSquared;

bool isNearest = distance < nearestDistance;
bool isSnap = EditorLogic.interceptsCircle(entry.value, offset,
EditorConfig.defaultSnapTolerance / 2 * scaleInverse);

if (isNearest && isSnap) {
nearestPointSnap = entry;
nearestDistance = distance;
}
}

return null;
return nearestPointSnap;
}

Offset effectivePointerCoordinates(Offset offset, {String? ignoreUuid}) {
Expand Down

0 comments on commit d945528

Please sign in to comment.