From e06d8e4d15d957250079b7744784f0d2af883662 Mon Sep 17 00:00:00 2001 From: Savely Skresanov Date: Sat, 4 Aug 2012 18:39:40 +0700 Subject: [PATCH] Rectangle snapping. --- src/game/GameView.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 838f733ec..f58b14564 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1553,5 +1553,10 @@ ui::Point GameView::lineSnapCoords(ui::Point point1, ui::Point point2) ui::Point GameView::rectSnapCoords(ui::Point point1, ui::Point point2) { - return point2; -} \ No newline at end of file + ui::Point newPoint(0, 0); + float snapAngle = floor((atan2(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; +}