diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2007-12-04 19:09:09 +0000 |
|---|---|---|
| committer | dvlierop2 <dvlierop2@users.sourceforge.net> | 2007-12-04 19:09:09 +0000 |
| commit | 41c6a833adf57cfe1b3cf52b499f242bcf4a4174 (patch) | |
| tree | 6b33a3a852cd38463ab5dfbfe8f52fdb045b3422 /src/util/mathfns.h | |
| parent | Implemented use of "short_label" for toolbar items. (diff) | |
| download | inkscape-41c6a833adf57cfe1b3cf52b499f242bcf4a4174.tar.gz inkscape-41c6a833adf57cfe1b3cf52b499f242bcf4a4174.zip | |
When snapping, consider all four grid lines around the current point instead of only the nearest two
(bzr r4168)
Diffstat (limited to 'src/util/mathfns.h')
| -rw-r--r-- | src/util/mathfns.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/util/mathfns.h b/src/util/mathfns.h index 9ebd8bc2f..9f22ad11b 100644 --- a/src/util/mathfns.h +++ b/src/util/mathfns.h @@ -26,6 +26,43 @@ triangle_area (NR::Point p1, NR::Point p2, NR::Point p3) return (p1[NR::X]*p2[NR::Y] + p1[NR::Y]*p3[NR::X] + p2[NR::X]*p3[NR::Y] - p2[NR::Y]*p3[NR::X] - p1[NR::Y]*p2[NR::X] - p1[NR::X]*p3[NR::Y]); } +/** + * \return x rounded to the nearest multiple of c1 plus c0. + * + * \note + * If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero + * mean "ignore the grid in this dimension". + */ +inline double round_to_nearest_multiple_plus(double x, double const c1, double const c0) +{ + return floor((x - c0) / c1 + .5) * c1 + c0; +} + +/** + * \return x rounded to the lower multiple of c1 plus c0. + * + * \note + * If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero + * mean "ignore the grid in this dimension". + */ +inline double round_to_lower_multiple_plus(double x, double const c1, double const c0) +{ + return floor((x - c0) / c1) * c1 + c0; +} + +/** + * \return x rounded to the upper multiple of c1 plus c0. + * + * \note + * If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero + * mean "ignore the grid in this dimension". + */ +inline double round_to_upper_multiple_plus(double x, double const c1, double const c0) +{ + return ceil((x - c0) / c1) * c1 + c0; +} + + } } |
