107 // Snap the given coordinate value on the current grid's given axis. |
107 // Snap the given coordinate value on the current grid's given axis. |
108 // |
108 // |
109 double Grid::Snap (double value, const Grid::Config type) |
109 double Grid::Snap (double value, const Grid::Config type) |
110 { |
110 { |
111 double snapvalue = (type == Coordinate) ? *CurrentGrid().coordinateSnap : *CurrentGrid().angleSnap; |
111 double snapvalue = (type == Coordinate) ? *CurrentGrid().coordinateSnap : *CurrentGrid().angleSnap; |
112 double mult = floor (Abs<double> (value / snapvalue)); |
112 double mult = floor (qAbs<double> (value / snapvalue)); |
113 double out = mult * snapvalue; |
113 double out = mult * snapvalue; |
114 |
114 |
115 if (Abs (value) - (mult * snapvalue) > snapvalue / 2) |
115 if (qAbs (value) - (mult * snapvalue) > snapvalue / 2) |
116 out += snapvalue; |
116 out += snapvalue; |
117 |
117 |
118 if (value < 0) |
118 if (value < 0) |
119 out = -out; |
119 out = -out; |
120 |
120 |