From 12d98dada1e8c3ac34dbbbad5e8fce7e05b5b94c Mon Sep 17 00:00:00 2001 From: mniip Date: Fri, 13 Dec 2013 01:19:46 +0400 Subject: [PATCH] oooo wait, rectangle snap too --- src/gui/game/GameView.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index df7477e79..7987000f3 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -2264,10 +2264,9 @@ ui::Point GameView::lineSnapCoords(ui::Point point1, ui::Point point2) ui::Point GameView::rectSnapCoords(ui::Point point1, ui::Point point2) { - ui::Point newPoint(0, 0); - float snapAngle = floor((atan2((float)point2.Y-point1.Y, point2.X-point1.X)+M_PI*0.25)/(M_PI*0.5)+0.5)*M_PI*0.5 - M_PI*0.25; - float lineMag = sqrtf(pow((float)(point2.X-point1.X),2)+pow((float)(point2.Y-point1.Y),2)); - newPoint.X = (int)(lineMag*cos(snapAngle)+point1.X+0.5f); - newPoint.Y = (int)(lineMag*sin(snapAngle)+point1.Y+0.5f); - return newPoint; + ui::Point diff = point2 - point1; + if(diff.X * diff.Y > 0) // NW-SE + return point1 + ui::Point((diff.X + diff.Y)/2, (diff.X + diff.Y)/2); + // SW-NE + return point1 + ui::Point((diff.X - diff.Y)/2, (diff.Y - diff.X)/2); }