summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0a9a46f)
raw | patch | inline | side by side (parent: 0a9a46f)
author | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Tue, 4 Dec 2007 19:09:09 +0000 (19:09 +0000) | ||
committer | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Tue, 4 Dec 2007 19:09:09 +0000 (19:09 +0000) |
src/display/canvas-axonomgrid.cpp | patch | blob | history | |
src/display/canvas-grid.cpp | patch | blob | history | |
src/util/mathfns.h | patch | blob | history |
index 6bb5d47c026855309b23412942727ceae2b2690d..76e081a7215a85e4d3fe5526b7618f78e949e168 100644 (file)
#include "sp-canvas-util.h"
#include "canvas-axonomgrid.h"
+#include "util/mathfns.h"
#include "display-forward.h"
#include <libnr/nr-pixops.h>
}
}
-
-
-
-
-
-
-
-
-
-
-
-/**
- * \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 dimention". We're currently discussing "good" semantics
- * for guide/grid snapping.
- */
-
-/* FIXME: move this somewhere else, perhaps */
-static double round_to_nearest_multiple_plus(double x, double const c1, double const c0)
-{
- return floor((x - c0) / c1 + .5) * c1 + c0;
-}
-
CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d)
{
this->grid = grid;
scaled_spacing /= SP_ACTIVE_DESKTOP->current_zoom();
}
- NR::Coord const rounded = round_to_nearest_multiple_plus(p[0],
+ NR::Coord const rounded = Inkscape::Util::round_to_nearest_multiple_plus(p[0],
scaled_spacing,
grid->origin[0]);
index a2443ca1782b657c5e9ce0ff3a6f9b1511876307..db4648ec08032fc7a1340bef2d609e903bb0b278 100644 (file)
#include "sp-canvas-util.h"
+#include "util/mathfns.h"
#include "display-forward.h"
#include <libnr/nr-pixops.h>
#include "desktop-handles.h"
}
}
-
-
-
-/**
- * \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 dimention". We're currently discussing "good" semantics
- * for guide/grid snapping.
- */
-
-/* FIXME: move this somewhere else, perhaps */
-static double round_to_nearest_multiple_plus(double x, double const c1, double const c0)
-{
- return floor((x - c0) / c1 + .5) * c1 + c0;
-}
-
CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d)
{
this->grid = grid;
scaled_spacing /= SP_ACTIVE_DESKTOP->current_zoom();
}
- NR::Coord const rounded = round_to_nearest_multiple_plus(p[i],
- scaled_spacing,
- grid->origin[i]);
-
+ NR::Coord rounded;
+ rounded = Inkscape::Util::round_to_upper_multiple_plus(p[i], scaled_spacing, grid->origin[i]);
+ s.push_back(std::make_pair(NR::Dim2(i), rounded));
+ rounded = Inkscape::Util::round_to_lower_multiple_plus(p[i], scaled_spacing, grid->origin[i]);
s.push_back(std::make_pair(NR::Dim2(i), rounded));
}
diff --git a/src/util/mathfns.h b/src/util/mathfns.h
index 9ebd8bc2f737b5ed8a7a57d85ee571868215399b..9f22ad11b0568ff631e4b0d1169597e3f703a5c8 100644 (file)
--- a/src/util/mathfns.h
+++ b/src/util/mathfns.h
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;
+}
+
+
}
}