summaryrefslogtreecommitdiffstats
path: root/src/display/canvas-axonomgrid.cpp
diff options
context:
space:
mode:
authorDiederik van Lierop <mail@diedenrezi.nl>2009-04-12 12:59:26 +0000
committerdvlierop2 <dvlierop2@users.sourceforge.net>2009-04-12 12:59:26 +0000
commitf917248c6e109da63a0703e85520bac7318d4f39 (patch)
tree693d3357e750f360ae68791f3c093ea090567c81 /src/display/canvas-axonomgrid.cpp
parentFix snapping during constrained translation, when only snapping the node clos... (diff)
downloadinkscape-f917248c6e109da63a0703e85520bac7318d4f39.tar.gz
inkscape-f917248c6e109da63a0703e85520bac7318d4f39.zip
Use the line intersection routines in 2geom/line.h instead of the deprecated ones in 2geom/geom.h. (I know we're in a refactoring freeze, but this one I was already working on before this freeze was announced and it's quite safe IMHO. It's only a small change in 2geom's API and can hardly do any real harm. I will not refactor anything else until after the v0.47 release, promised!)
(bzr r7688)
Diffstat (limited to 'src/display/canvas-axonomgrid.cpp')
-rw-r--r--src/display/canvas-axonomgrid.cpp44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp
index 9c6126b7c..1a7c01c16 100644
--- a/src/display/canvas-axonomgrid.cpp
+++ b/src/display/canvas-axonomgrid.cpp
@@ -20,7 +20,7 @@
#include "sp-canvas-util.h"
#include "canvas-axonomgrid.h"
#include "util/mathfns.h"
-#include "2geom/geom.h"
+#include "2geom/line.h"
#include "display-forward.h"
#include <libnr/nr-pixops.h>
@@ -713,33 +713,47 @@ CanvasAxonomGridSnapper::_getSnapLines(Geom::Point const &p) const
double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[Geom::Y]);
double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[Geom::Y]);
+ // Calculate the versor for the angled grid lines
+ Geom::Point vers_x = Geom::Point(1, -grid->tan_angle[X]);
+ Geom::Point vers_z = Geom::Point(1, grid->tan_angle[Z]);
+
// Calculate the normal for the angled grid lines
- Geom::Point norm_x = Geom::rot90(Geom::Point(1, -grid->tan_angle[X]));
- Geom::Point norm_z = Geom::rot90(Geom::Point(1, grid->tan_angle[Z]));
+ Geom::Point norm_x = Geom::rot90(vers_x);
+ Geom::Point norm_z = Geom::rot90(vers_z);
- // The four angled grid lines form a parallellogram, enclosing the point
- // One of the two vertical grid lines divides this parallellogram in two triangles
+ // The four angled grid lines form a parallelogram, enclosing the point
+ // One of the two vertical grid lines divides this parallelogram in two triangles
// We will now try to find out in which half (i.e. triangle) our point is, and return
// only the three grid lines defining that triangle
// The vertical grid line is at the intersection of two angled grid lines.
// Now go find that intersection!
- Geom::Point result;
- Geom::IntersectorKind is = Geom::line_intersection(norm_x, norm_x[Geom::Y]*y_proj_along_x_max,
- norm_z, norm_z[Geom::Y]*y_proj_along_z_max,
- result);
-
- // Determine which half of the parallellogram to use
+ Geom::Point p_x(0, y_proj_along_x_max);
+ Geom::Line line_x(p_x, p_x + vers_x);
+ Geom::Point p_z(0, y_proj_along_z_max);
+ Geom::Line line_z(p_z, p_z + vers_z);
+
+ Geom::OptCrossing inters = Geom::OptCrossing(); // empty by default
+ try
+ {
+ inters = Geom::intersection(line_x, line_z);
+ }
+ catch (Geom::InfiniteSolutions e)
+ {
+ // We're probably dealing with parallel lines; this is useless!
+ return s;
+ }
+
+ // Determine which half of the parallelogram to use
bool use_left_half = true;
bool use_right_half = true;
- if (is == Geom::intersects) {
- use_left_half = (p[Geom::X] - grid->origin[Geom::X]) < result[Geom::X];
+ if (inters) {
+ Geom::Point inters_pt = line_x.pointAt((*inters).ta);
+ use_left_half = (p[Geom::X] - grid->origin[Geom::X]) < inters_pt[Geom::X];
use_right_half = !use_left_half;
}
- //std::cout << "intersection at " << result << " leads to use_left_half = " << use_left_half << " and use_right_half = " << use_right_half << std::endl;
-
// Return the three grid lines which define the triangle that encloses our point
// If we didn't find an intersection above, all 6 grid lines will be returned
if (use_left_half) {