Rectangle snapping.

This commit is contained in:
Savely Skresanov 2012-08-04 18:39:40 +07:00 committed by Simon Robertshaw
parent 929d99f80c
commit e06d8e4d15

View File

@ -1553,5 +1553,10 @@ ui::Point GameView::lineSnapCoords(ui::Point point1, ui::Point point2)
ui::Point GameView::rectSnapCoords(ui::Point point1, ui::Point point2) ui::Point GameView::rectSnapCoords(ui::Point point1, ui::Point point2)
{ {
return point2; 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;
} }