Skip to content

Commit

Permalink
fix lack of snapping for first point on canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
azmr committed Jan 20, 2018
1 parent 5916705 commit 7b50254
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions geometer.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,20 +684,20 @@ UPDATE_AND_RENDER(UpdateAndRender)

// SNAPPING
v2 CanvasMouseP = V2ScreenToCanvas(BASIS, Mouse.P, ScreenCentre);
SnapMouseP = CanvasMouseP;
poClosest = CanvasMouseP;
{
f32 ClosestDistSq;
f32 ClosestIntersectDistSq = 0.f;
b32 ClosestPtOrIntersect = 0;
SnapMouseP = CanvasMouseP;
poClosest = CanvasMouseP;
ipoClosest = ClosestPointIndex(State, CanvasMouseP, &ClosestDistSq);
// TODO (ui): consider ignoring intersections while selecting
/* if( ! (MODE_START_Select <= State->InputMode && State->InputMode <= MODE_END_Select)) */
{ ipoClosestIntersect = ClosestIntersectIndex(State, CanvasMouseP, &ClosestIntersectDistSq); }

ClosestPtOrIntersect = ipoClosest || ipoClosestIntersect;
DebugReplace("Pt: %u, Isct: %u, Drawing: %u\n", ipoClosest, ipoClosestIntersect, IsDrawing(State));
if(State->iLastPoint && (ClosestPtOrIntersect || IsDrawing(State)))
if(ClosestPtOrIntersect || IsDrawing(State))
{
// decide whether to use point or intersect
if(ipoClosest && ipoClosestIntersect)
Expand Down Expand Up @@ -762,14 +762,13 @@ UPDATE_AND_RENDER(UpdateAndRender)

#define POINT_SNAP_DIST 5000.f
// NOTE: BASIS->Zoom needs to be squared to match ClosestDistSq
if(ClosestDistSq/(BASIS.Zoom * BASIS.Zoom) < POINT_SNAP_DIST)
{ // closest point within range
if( ! C_NoSnap.EndedDown)
{ // point snapping still on
SnapMouseP = poClosest;
DebugAdd("SnapMouseP: %.2f, %.2f\n", SnapMouseP.X, SnapMouseP.Y);
IsSnapped = 1;
}
if(ClosestDistSq/(BASIS.Zoom * BASIS.Zoom) < POINT_SNAP_DIST && // closest point is within range
! C_NoSnap.EndedDown && // point snapping is still on
! V2Equals(poClosest, CanvasMouseP)) // found something to snap to
{
SnapMouseP = poClosest;
DebugAdd("SnapMouseP: %.2f, %.2f\n", SnapMouseP.X, SnapMouseP.Y);
IsSnapped = 1;
}
}

Expand Down

0 comments on commit 7b50254

Please sign in to comment.