From ed70cc908f7fe9d5f2d86042e3fe1f758984c03a Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Mon, 11 Aug 2008 04:53:15 +0000 Subject: [PATCH] Move all of the snapper code to 2geom --- src/arc-context.cpp | 4 +- src/box3d-context.cpp | 30 ++++--- src/connector-context.cpp | 12 +-- src/context-fns.cpp | 12 +-- src/desktop-events.cpp | 34 ++++---- src/display/canvas-axonomgrid.cpp | 44 +++++----- src/display/canvas-axonomgrid.h | 6 +- src/display/canvas-grid.cpp | 12 +-- src/display/canvas-grid.h | 6 +- src/draw-context.cpp | 8 +- src/gradient-context.cpp | 6 +- src/gradient-drag.cpp | 2 +- src/guide-snapper.cpp | 6 +- src/guide-snapper.h | 6 +- src/knot-holder-entity.cpp | 4 +- src/libnr/nr-convert2geom.h | 13 +++ src/line-snapper.cpp | 36 ++++---- src/line-snapper.h | 18 ++-- src/nodepath.cpp | 22 ++--- src/object-snapper.cpp | 129 ++++++++++++++-------------- src/object-snapper.h | 44 +++++----- src/pencil-context.cpp | 22 ++--- src/rect-context.cpp | 7 +- src/seltrans.cpp | 53 +++++++----- src/seltrans.h | 4 +- src/snap.cpp | 136 +++++++++++++++--------------- src/snap.h | 70 +++++++-------- src/snapped-curve.cpp | 10 +-- src/snapped-curve.h | 6 +- src/snapped-line.cpp | 20 ++--- src/snapped-line.h | 18 ++-- src/snapped-point.cpp | 22 ++--- src/snapped-point.h | 34 ++++---- src/snapper.cpp | 6 +- src/snapper.h | 32 +++---- src/spiral-context.cpp | 18 ++-- src/star-context.cpp | 19 +++-- 37 files changed, 486 insertions(+), 445 deletions(-) diff --git a/src/arc-context.cpp b/src/arc-context.cpp index f3e46e029..3df9dc4b2 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -266,7 +266,9 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, NULL); //null, because we don't have an item yet - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, ac->center); + Geom::Point pt2g = to_2geom(ac->center); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); + ac->center = from_2geom(pt2g); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 5d8d720b0..6f3b6ee51 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -317,13 +317,13 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven dragging = true; /* */ - NR::Point button_dt(desktop->w2d(button_w)); - bc->drag_origin = button_dt; - bc->drag_ptB = button_dt; - bc->drag_ptC = button_dt; + Geom::Point button_dt(desktop->w2d(button_w)); + bc->drag_origin = from_2geom(button_dt); + bc->drag_ptB = from_2geom(button_dt); + bc->drag_ptC = from_2geom(button_dt); /* Projective preimages of clicked point under current perspective */ - bc->drag_origin_proj = cur_persp->tmat.preimage (button_dt, 0, Proj::Z); + bc->drag_origin_proj = cur_persp->tmat.preimage (from_2geom(button_dt), 0, Proj::Z); bc->drag_ptB_proj = bc->drag_origin_proj; bc->drag_ptC_proj = bc->drag_origin_proj; bc->drag_ptC_proj.normalize(); @@ -333,7 +333,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, bc->item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, button_dt); - bc->center = button_dt; + bc->center = from_2geom(button_dt); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | @@ -360,7 +360,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven NR::Point const motion_w(event->motion.x, event->motion.y); - NR::Point motion_dt(desktop->w2d(motion_w)); + Geom::Point motion_dt(to_2geom(desktop->w2d(motion_w))); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, bc->item); @@ -374,10 +374,10 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven } if (!bc->extruded) { - bc->drag_ptB = motion_dt; - bc->drag_ptC = motion_dt; + bc->drag_ptB = from_2geom(motion_dt); + bc->drag_ptC = from_2geom(motion_dt); - bc->drag_ptB_proj = cur_persp->tmat.preimage (motion_dt, 0, Proj::Z); + bc->drag_ptB_proj = cur_persp->tmat.preimage (from_2geom(motion_dt), 0, Proj::Z); bc->drag_ptC_proj = bc->drag_ptB_proj; bc->drag_ptC_proj.normalize(); bc->drag_ptC_proj[Proj::Z] = 0.25; @@ -387,17 +387,19 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven if (!bc->ctrl_dragged) { /* snapping */ Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, SP_ACTIVE_DOCUMENT->current_persp3d); - bc->drag_ptC = pline.closest_to (motion_dt); + bc->drag_ptC = pline.closest_to (from_2geom(motion_dt)); bc->drag_ptB_proj.normalize(); bc->drag_ptC_proj = cur_persp->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X); } else { - bc->drag_ptC = motion_dt; + bc->drag_ptC = from_2geom(motion_dt); bc->drag_ptB_proj.normalize(); - bc->drag_ptC_proj = cur_persp->tmat.preimage (motion_dt, bc->drag_ptB_proj[Proj::X], Proj::X); + bc->drag_ptC_proj = cur_persp->tmat.preimage (from_2geom(motion_dt), bc->drag_ptB_proj[Proj::X], Proj::X); } - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, bc->drag_ptC); + Geom::Point pt2g = to_2geom(bc->drag_ptC); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); + bc->drag_ptC = from_2geom(pt2g); } sp_box3d_drag(*bc, event->motion.state); diff --git a/src/connector-context.cpp b/src/connector-context.cpp index d58c8a871..8e8c4b066 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -514,27 +514,27 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const case SP_CONNECTOR_CONTEXT_IDLE: { if ( cc->npoints == 0 ) { - /* Set start anchor */ - NR::Point p; - cc_clear_active_conn(cc); SP_EVENT_CONTEXT_DESKTOP(cc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector")); + /* Set start anchor */ /* Create green anchor */ - p = event_dt; + NR::Point p = event_dt; // Test whether we clicked on a connection point cc->sid = conn_pt_handle_test(cc, p); + + Geom::Point pt2g = to_2geom(p); if (!cc->sid) { // This is the first point, so just snap it to the grid // as there's no other points to go off. SnapManager &m = cc->desktop->namedview->snap_manager; m.setup(cc->desktop); - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); } - spcc_connector_set_initial_point(cc, p); + spcc_connector_set_initial_point(cc, from_2geom(pt2g)); } cc->state = SP_CONNECTOR_CONTEXT_DRAGGING; diff --git a/src/context-fns.cpp b/src/context-fns.cpp index 28725c64f..e58476147 100644 --- a/src/context-fns.cpp +++ b/src/context-fns.cpp @@ -132,11 +132,11 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, Inkscape::SnappedPoint s[2]; /* Try to snap p[0] (the opposite corner) along the constraint vector */ - s[0] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[0], + s[0] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(p[0]), Inkscape::Snapper::ConstraintLine(p[0] - p[1])); /* Try to snap p[1] (the dragged corner) along the constraint vector */ - s[1] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1], + s[1] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(p[1]), Inkscape::Snapper::ConstraintLine(p[1] - p[0])); /* Choose the best snap and update points accordingly */ @@ -157,7 +157,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, /* Our origin is the opposite corner. Snap the drag point along the constraint vector */ p[0] = center; - snappoint = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1], + snappoint = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(p[1]), Inkscape::Snapper::ConstraintLine(p[1] - p[0])); if (snappoint.getSnapped()) { p[1] = snappoint.getPoint(); @@ -175,8 +175,8 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, Inkscape::SnappedPoint s[2]; - s[0] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[0]); - s[1] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1]); + s[0] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(p[0])); + s[1] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(p[1])); if (s[0].getDistance() < s[1].getDistance()) { if (s[0].getSnapped()) { @@ -197,7 +197,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, /* There's no constraint on the corner point, so just snap it to anything */ p[0] = center; p[1] = pt; - snappoint = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, pt); + snappoint = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(pt)); if (snappoint.getSnapped()) { p[1] = snappoint.getPoint(); } diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 522bfbdda..f839b6946 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -140,22 +140,22 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge case GDK_MOTION_NOTIFY: if (dragging) { NR::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win)); - NR::Point event_dt(desktop->w2d(event_w)); + Geom::Point event_dt(desktop->w2d(event_w)); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); m.guideSnap(event_dt, normal); - sp_guideline_set_position(SP_GUIDELINE(guide), event_dt); - desktop->set_coordinate_status(event_dt); - desktop->setPosition (event_dt); + sp_guideline_set_position(SP_GUIDELINE(guide), from_2geom(event_dt)); + desktop->set_coordinate_status(to_2geom(event_dt)); + desktop->setPosition(to_2geom(event_dt)); } break; case GDK_BUTTON_RELEASE: if (dragging && event->button.button == 1) { gdk_pointer_ungrab(event->button.time); NR::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win)); - NR::Point event_dt(desktop->w2d(event_w)); + Geom::Point event_dt(desktop->w2d(event_w)); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); @@ -168,13 +168,13 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc()); Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide"); sp_repr_set_point(repr, "orientation", normal); - sp_repr_set_point(repr, "position", event_dt); + sp_repr_set_point(repr, "position", from_2geom(event_dt)); SP_OBJECT_REPR(desktop->namedview)->appendChild(repr); Inkscape::GC::release(repr); sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create guide")); } - desktop->set_coordinate_status(event_dt); + desktop->set_coordinate_status(from_2geom(event_dt)); } default: break; @@ -234,20 +234,20 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) break; case GDK_MOTION_NOTIFY: if (dragging) { - NR::Point const motion_w(event->motion.x, + Geom::Point const motion_w(event->motion.x, event->motion.y); - NR::Point motion_dt(desktop->w2d(motion_w)); + Geom::Point motion_dt(to_2geom(desktop->w2d(from_2geom(motion_w)))); // This is for snapping while dragging existing guidelines. New guidelines, // which are dragged off the ruler, are being snapped in sp_dt_ruler_event SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - m.guideSnap(motion_dt, guide->normal_to_line); + m.guideSnap(motion_dt, to_2geom(guide->normal_to_line)); - sp_guide_moveto(*guide, motion_dt, false); + sp_guide_moveto(*guide, from_2geom(motion_dt), false); moved = true; - desktop->set_coordinate_status(motion_dt); - desktop->setPosition (motion_dt); + desktop->set_coordinate_status(from_2geom(motion_dt)); + desktop->setPosition(from_2geom(motion_dt)); ret = TRUE; } @@ -257,14 +257,14 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) if (moved) { NR::Point const event_w(event->button.x, event->button.y); - NR::Point event_dt(desktop->w2d(event_w)); + Geom::Point event_dt(desktop->w2d(event_w)); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); m.guideSnap(event_dt, guide->normal_to_line); if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) { - sp_guide_moveto(*guide, event_dt, true); + sp_guide_moveto(*guide, from_2geom(event_dt), true); sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Move guide")); } else { @@ -275,8 +275,8 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) _("Delete guide")); } moved = false; - desktop->set_coordinate_status(event_dt); - desktop->setPosition (event_dt); + desktop->set_coordinate_status(from_2geom(event_dt)); + desktop->setPosition (from_2geom(event_dt)); } dragging = false; sp_canvas_item_ungrab(item, event->button.time); diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 49ca07ca7..0c2c627c9 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -654,13 +654,13 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) } } -CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d) +CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, Geom::Coord const d) : LineSnapper(nv, d) { this->grid = grid; } LineSnapper::LineList -CanvasAxonomGridSnapper::_getSnapLines(NR::Point const &p) const +CanvasAxonomGridSnapper::_getSnapLines(Geom::Point const &p) const { LineList s; @@ -685,20 +685,20 @@ CanvasAxonomGridSnapper::_getSnapLines(NR::Point const &p) const // - 2 angled x grid lines, one above and one below the point // Calculate the x coordinate of the vertical grid lines - NR::Coord x_max = Inkscape::Util::round_to_upper_multiple_plus(p[NR::X], scaled_spacing_h, grid->origin[NR::X]); - NR::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[NR::X], scaled_spacing_h, grid->origin[NR::X]); + Geom::Coord x_max = Inkscape::Util::round_to_upper_multiple_plus(p[Geom::X], scaled_spacing_h, grid->origin[Geom::X]); + Geom::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[Geom::X], scaled_spacing_h, grid->origin[Geom::X]); // Calculate the y coordinate of the intersection of the angled grid lines with the y-axis - double y_proj_along_z = p[NR::Y] - grid->tan_angle[Z]*(p[NR::X] - grid->origin[NR::X]); - double y_proj_along_x = p[NR::Y] + grid->tan_angle[X]*(p[NR::X] - grid->origin[NR::X]); - double y_proj_along_z_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[NR::Y]); - double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[NR::Y]); - double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[NR::Y]); - double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[NR::Y]); + double y_proj_along_z = p[Geom::Y] - grid->tan_angle[Z]*(p[Geom::X] - grid->origin[Geom::X]); + double y_proj_along_x = p[Geom::Y] + grid->tan_angle[X]*(p[Geom::X] - grid->origin[Geom::X]); + double y_proj_along_z_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[Geom::Y]); + double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[Geom::Y]); + 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 normal for the angled grid lines - NR::Point norm_x = NR::rot90(NR::Point(1, -grid->tan_angle[X])); - NR::Point norm_z = NR::rot90(NR::Point(1, grid->tan_angle[Z])); + 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])); // The four angled grid lines form a parallellogram, enclosing the point // One of the two vertical grid lines divides this parallellogram in two triangles @@ -708,8 +708,8 @@ CanvasAxonomGridSnapper::_getSnapLines(NR::Point const &p) const // The vertical grid line is at the intersection of two angled grid lines. // Now go find that intersection! Geom::Point result; - Geom::IntersectorKind is = line_intersection(norm_x, norm_x[NR::Y]*y_proj_along_x_max, - norm_z, norm_z[NR::Y]*y_proj_along_z_max, + Geom::IntersectorKind is = 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 @@ -717,7 +717,7 @@ CanvasAxonomGridSnapper::_getSnapLines(NR::Point const &p) const bool use_right_half = true; if (is == Geom::intersects) { - use_left_half = (p[NR::X] - grid->origin[NR::X]) < result[Geom::X]; + use_left_half = (p[Geom::X] - grid->origin[Geom::X]) < result[Geom::X]; use_right_half = !use_left_half; } @@ -726,21 +726,21 @@ CanvasAxonomGridSnapper::_getSnapLines(NR::Point const &p) const // 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) { - s.push_back(std::make_pair(norm_z, NR::Point(grid->origin[NR::X], y_proj_along_z_max))); - s.push_back(std::make_pair(norm_x, NR::Point(grid->origin[NR::X], y_proj_along_x_min))); - s.push_back(std::make_pair(component_vectors[NR::X], NR::Point(x_max, 0))); + s.push_back(std::make_pair(norm_z, Geom::Point(grid->origin[Geom::X], y_proj_along_z_max))); + s.push_back(std::make_pair(norm_x, Geom::Point(grid->origin[Geom::X], y_proj_along_x_min))); + s.push_back(std::make_pair(component_vectors[Geom::X], Geom::Point(x_max, 0))); } if (use_right_half) { - s.push_back(std::make_pair(norm_z, NR::Point(grid->origin[NR::X], y_proj_along_z_min))); - s.push_back(std::make_pair(norm_x, NR::Point(grid->origin[NR::X], y_proj_along_x_max))); - s.push_back(std::make_pair(component_vectors[NR::X], NR::Point(x_min, 0))); + s.push_back(std::make_pair(norm_z, Geom::Point(grid->origin[Geom::X], y_proj_along_z_min))); + s.push_back(std::make_pair(norm_x, Geom::Point(grid->origin[Geom::X], y_proj_along_x_max))); + s.push_back(std::make_pair(component_vectors[Geom::X], Geom::Point(x_min, 0))); } return s; } -void CanvasAxonomGridSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const +void CanvasAxonomGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const { SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line); sc.grid_lines.push_back(dummy); diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index 564d266a6..f5f9019d2 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -71,11 +71,11 @@ private: class CanvasAxonomGridSnapper : public LineSnapper { public: - CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, NR::Coord const d); + CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, Geom::Coord const d); private: - LineList _getSnapLines(NR::Point const &p) const; - void _addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, const NR::Point point_on_line) const; + LineList _getSnapLines(Geom::Point const &p) const; + void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, const Geom::Point point_on_line) const; CanvasAxonomGrid *grid; }; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 81e017f12..84e8bfbf9 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -953,7 +953,7 @@ CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const * } LineSnapper::LineList -CanvasXYGridSnapper::_getSnapLines(NR::Point const &p) const +CanvasXYGridSnapper::_getSnapLines(Geom::Point const &p) const { LineList s; @@ -972,22 +972,22 @@ CanvasXYGridSnapper::_getSnapLines(NR::Point const &p) const scaled_spacing /= SP_ACTIVE_DESKTOP->current_zoom(); } - NR::Coord rounded; - NR::Point point_on_line; + Geom::Coord rounded; + Geom::Point point_on_line; rounded = Inkscape::Util::round_to_upper_multiple_plus(p[i], scaled_spacing, grid->origin[i]); - point_on_line = i ? NR::Point(0, rounded) : NR::Point(rounded, 0); + point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0); s.push_back(std::make_pair(component_vectors[i], point_on_line)); rounded = Inkscape::Util::round_to_lower_multiple_plus(p[i], scaled_spacing, grid->origin[i]); - point_on_line = i ? NR::Point(0, rounded) : NR::Point(rounded, 0); + point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0); s.push_back(std::make_pair(component_vectors[i], point_on_line)); } return s; } -void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const +void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const { SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line); sc.grid_lines.push_back(dummy); diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 5d674bb2d..a734cac84 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -161,12 +161,12 @@ private: class CanvasXYGridSnapper : public LineSnapper { public: - CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d); + CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, Geom::Coord const d); bool ThisSnapperMightSnap() const; private: - LineList _getSnapLines(NR::Point const &p) const; - void _addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, const NR::Point point_on_line) const; + LineList _getSnapLines(Geom::Point const &p) const; + void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, const Geom::Point point_on_line) const; CanvasXYGrid *grid; }; diff --git a/src/draw-context.cpp b/src/draw-context.cpp index b321f0f50..7bf01829d 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -481,7 +481,9 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, N /* Snap it along best vector */ SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL); - m.constrainedSnapReturnByRef( Inkscape::Snapper::SNAPPOINT_NODE, p, Inkscape::Snapper::ConstraintLine(best)); + Geom::Point pt2g = to_2geom(p); + m.constrainedSnapReturnByRef( Inkscape::Snapper::SNAPPOINT_NODE, pt2g, Inkscape::Snapper::ConstraintLine(best)); + p = from_2geom(pt2g); } } } @@ -491,7 +493,9 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guin { SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL); - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p); + Geom::Point pt2g = to_2geom(p); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); + p = from_2geom(pt2g); } static SPCurve * diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index 9101fcee1..f2cd9e03a 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -542,9 +542,9 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) dragging = true; - NR::Point button_dt = desktop->w2d(button_w); + Geom::Point button_dt = to_2geom(desktop->w2d(button_w)); if (event->button.state & GDK_SHIFT_MASK) { - Inkscape::Rubberband::get()->start(desktop, button_dt); + Inkscape::Rubberband::get()->start(desktop, from_2geom(button_dt)); } else { // remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to // enable Ctrl+doubleclick of exactly the selected item(s) @@ -555,7 +555,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, button_dt); - rc->origin = button_dt; + rc->origin = from_2geom(button_dt); } ret = TRUE; diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 1657288cc..5bf2b2575 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -581,7 +581,7 @@ gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpoi SPDesktop *desktop = dragger->parent->desktop; SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p); + Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(p)); if (s.getSnapped()) { p = s.getPoint(); sp_knot_moveto (knot, p); diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index 41e2cdb07..059d99a19 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -17,12 +17,12 @@ #include "sp-namedview.h" #include "sp-guide.h" -Inkscape::GuideSnapper::GuideSnapper(SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d) +Inkscape::GuideSnapper::GuideSnapper(SPNamedView const *nv, Geom::Coord const d) : LineSnapper(nv, d) { } -Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point const &/*p*/) const +Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Point const &/*p*/) const { LineList s; @@ -46,7 +46,7 @@ bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const return _named_view == NULL ? false : (_snap_enabled && _snap_from != 0 && _named_view->showguides); } -void Inkscape::GuideSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const +void Inkscape::GuideSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const { SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line); sc.guide_lines.push_back(dummy); diff --git a/src/guide-snapper.h b/src/guide-snapper.h index 0605bdb97..df6086ccf 100644 --- a/src/guide-snapper.h +++ b/src/guide-snapper.h @@ -28,12 +28,12 @@ namespace Inkscape class GuideSnapper : public LineSnapper { public: - GuideSnapper(SPNamedView const *nv, NR::Coord const d); + GuideSnapper(SPNamedView const *nv, Geom::Coord const d); bool ThisSnapperMightSnap() const; private: - LineList _getSnapLines(NR::Point const &p) const; - void _addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const; + LineList _getSnapLines(Geom::Point const &p) const; + void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const; }; } diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 99aa67052..9d890e2fc 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -90,11 +90,11 @@ Geom::Point KnotHolderEntity::snap_knot_position(Geom::Point const &p) { Geom::Matrix const i2d (sp_item_i2d_affine(item)); - NR::Point s = p * i2d; + Geom::Point s = p * i2d; SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s); - return Geom::Point(s) * i2d.inverse(); + return s * i2d.inverse(); } diff --git a/src/libnr/nr-convert2geom.h b/src/libnr/nr-convert2geom.h index c92c34011..95b9eb6f0 100644 --- a/src/libnr/nr-convert2geom.h +++ b/src/libnr/nr-convert2geom.h @@ -46,6 +46,19 @@ inline NR::Rect from_2geom(Geom::Rect const & rect2geom) { return rect; } +inline NR::scale from_2geom(Geom::Scale const & in) { + return NR::scale(in[Geom::X], in[Geom::Y]); +} +inline Geom::Scale to_2geom(NR::scale const & in) { + return Geom::Scale(in[NR::X], in[NR::Y]); +} + +inline void to_2geom(std::vector const &in_NR, std::vector &out_2geom) { + for (std::vector::const_iterator it = in_NR.begin(); it != in_NR.end(); it++) { + out_2geom.push_back(to_2geom(*it)); + } +} + #endif /* diff --git a/src/line-snapper.cpp b/src/line-snapper.cpp index d06d027e3..db7a20e4f 100644 --- a/src/line-snapper.cpp +++ b/src/line-snapper.cpp @@ -18,18 +18,18 @@ #include "snapped-line.h" #include -Inkscape::LineSnapper::LineSnapper(SPNamedView const *nv, NR::Coord const d) : Snapper(nv, d) +Inkscape::LineSnapper::LineSnapper(SPNamedView const *nv, Geom::Coord const d) : Snapper(nv, d) { } void Inkscape::LineSnapper::freeSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &/*f*/, - boost::optional const &/*bbox_to_snap*/, + boost::optional const &/*bbox_to_snap*/, std::vector const */*it*/, - std::vector */*unselected_nodes*/) const + std::vector */*unselected_nodes*/) const { if (_snap_enabled == false || getSnapFrom(t) == false) { return; @@ -41,13 +41,13 @@ void Inkscape::LineSnapper::freeSnap(SnappedConstraints &sc, // std::cout << "snap point " << p << " to: " << std::endl; for (LineList::const_iterator i = lines.begin(); i != lines.end(); i++) { - NR::Point const p1 = i->second; // point at guide/grid line - NR::Point const p2 = p1 + NR::rot90(i->first); // 2nd point at guide/grid line + Geom::Point const p1 = i->second; // point at guide/grid line + Geom::Point const p2 = p1 + Geom::rot90(i->first); // 2nd point at guide/grid line // std::cout << " line through " << i->second << " with normal " << i->first; - g_assert(i->first != NR::Point(0,0)); // we cannot project on an linesegment of zero length + g_assert(i->first != Geom::Point(0,0)); // we cannot project on an linesegment of zero length - NR::Point const p_proj = project_on_linesegment(p, p1, p2); - NR::Coord const dist = NR::L2(p_proj - p); + Geom::Point const p_proj = project_on_linesegment(p, p1, p2); + Geom::Coord const dist = Geom::L2(p_proj - p); //Store any line that's within snapping range if (dist < getSnapperTolerance()) { _addSnappedLine(sc, p_proj, dist, i->first, i->second); @@ -59,9 +59,9 @@ void Inkscape::LineSnapper::freeSnap(SnappedConstraints &sc, void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &/*f*/, - boost::optional const &/*bbox_to_snap*/, + boost::optional const &/*bbox_to_snap*/, ConstraintLine const &c, std::vector const */*it*/) const @@ -74,24 +74,24 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, const LineList lines = _getSnapLines(p); for (LineList::const_iterator i = lines.begin(); i != lines.end(); i++) { - if (NR::L2(c.getDirection()) > 0) { // Can't do a constrained snap without a constraint + if (Geom::L2(c.getDirection()) > 0) { // Can't do a constrained snap without a constraint /* Normal to the line we're trying to snap along */ - NR::Point const n(NR::rot90(NR::unit_vector(c.getDirection()))); + Geom::Point const n(Geom::rot90(Geom::unit_vector(c.getDirection()))); - NR::Point const point_on_line = c.hasPoint() ? c.getPoint() : p; + Geom::Point const point_on_line = c.hasPoint() ? c.getPoint() : p; /* Constant term of the line we're trying to snap along */ - NR::Coord const q0 = dot(n, point_on_line); + Geom::Coord const q0 = dot(n, point_on_line); /* Constant term of the grid or guide line */ - NR::Coord const q1 = dot(i->first, i->second); + Geom::Coord const q1 = dot(i->first, i->second); /* Try to intersect this line with the target line */ Geom::Point t_2geom(NR_HUGE, NR_HUGE); Geom::IntersectorKind const k = Geom::line_intersection(n, q0, i->first, q1, t_2geom); - NR::Point t(t_2geom); + Geom::Point t(t_2geom); if (k == Geom::intersects) { - const NR::Coord dist = L2(t - p); + const Geom::Coord dist = L2(t - p); if (dist < getSnapperTolerance()) { // When doing a constrained snap, we're already at an intersection. // This snappoint is therefore fully constrained, so there's no need diff --git a/src/line-snapper.h b/src/line-snapper.h index e0adf3845..6af2e87d4 100644 --- a/src/line-snapper.h +++ b/src/line-snapper.h @@ -19,26 +19,26 @@ namespace Inkscape class LineSnapper : public Snapper { public: - LineSnapper(SPNamedView const *nv, NR::Coord const d); + LineSnapper(SPNamedView const *nv, Geom::Coord const d); void freeSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - boost::optional const &bbox_to_snap, + boost::optional const &bbox_to_snap, std::vector const *it, - std::vector *unselected_nodes) const; + std::vector *unselected_nodes) const; void constrainedSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - boost::optional const &bbox_to_snap, + boost::optional const &bbox_to_snap, ConstraintLine const &c, std::vector const *it) const; protected: - typedef std::list > LineList; + typedef std::list > LineList; //first point is a vector normal to the line //second point is a point on the line @@ -47,9 +47,9 @@ private: * \param p Point that we are trying to snap. * \return List of lines that we should try snapping to. */ - virtual LineList _getSnapLines(NR::Point const &p) const = 0; + virtual LineList _getSnapLines(Geom::Point const &p) const = 0; - virtual void _addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const = 0; + virtual void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const = 0; }; } diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 82a5e841c..4132cc5ba 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -1285,7 +1285,7 @@ void sp_node_moveto(Inkscape::NodePath::Node *node, NR::Point p) */ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, NR::Coord dx, NR::Coord dy, bool const snap, bool constrained = false, - Inkscape::Snapper::ConstraintLine const &constraint = NR::Point()) + Inkscape::Snapper::ConstraintLine const &constraint = Geom::Point()) { NR::Coord best = NR_HUGE; NR::Point delta(dx, dy); @@ -1298,13 +1298,13 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, * must provide that information. */ // Build a list of the unselected nodes to which the snapper should snap - std::vector unselected_nodes; + std::vector unselected_nodes; for (GList *spl = nodepath->subpaths; spl != NULL; spl = spl->next) { Inkscape::NodePath::SubPath *subpath = (Inkscape::NodePath::SubPath *) spl->data; for (GList *nl = subpath->nodes; nl != NULL; nl = nl->next) { Inkscape::NodePath::Node *node = (Inkscape::NodePath::Node *) nl->data; if (!node->selected) { - unselected_nodes.push_back(node->pos); + unselected_nodes.push_back(to_2geom(node->pos)); } } } @@ -1318,14 +1318,14 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, if (constrained) { Inkscape::Snapper::ConstraintLine dedicated_constraint = constraint; dedicated_constraint.setPoint(n->pos); - s = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, n->pos + delta, dedicated_constraint); + s = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(n->pos + delta), dedicated_constraint); } else { - s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, n->pos + delta); + s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(n->pos + delta)); } if (s.getSnapped() && (s.getDistance() < best)) { best = s.getDistance(); best_abs = s; - best_pt = s.getPoint() - n->pos; + best_pt = from_2geom(s.getPoint()) - n->pos; } } @@ -3804,20 +3804,22 @@ static gboolean node_handle_request(SPKnot *knot, NR::Point *p, guint state, gpo (*p) = n->pos + (scal / linelen) * ndelta; } if ((state & GDK_SHIFT_MASK) == 0) { - s = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, *p, Inkscape::Snapper::ConstraintLine(*p, ndelta)); + s = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(*p), Inkscape::Snapper::ConstraintLine(*p, ndelta)); } } else { if ((state & GDK_SHIFT_MASK) == 0) { - s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, *p); + s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(*p)); } } } else { if ((state & GDK_SHIFT_MASK) == 0) { - s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, *p); + s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, to_2geom(*p)); } } - s.getPoint(*p); + Geom::Point pt2g = *p; + s.getPoint(pt2g); + *p = pt2g; sp_node_adjust_handle(n, -which); diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index a3f7383db..7582a4c17 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -35,7 +35,7 @@ #include "sp-mask.h" #include "helper/geom-curves.h" -Inkscape::SnapCandidate::SnapCandidate(SPItem* item, bool clip_or_mask, NR::Matrix additional_affine) +Inkscape::SnapCandidate::SnapCandidate(SPItem* item, bool clip_or_mask, Geom::Matrix additional_affine) : item(item), clip_or_mask(clip_or_mask), additional_affine(additional_affine) { } @@ -44,13 +44,13 @@ Inkscape::SnapCandidate::~SnapCandidate() { } -Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, NR::Coord const d) +Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, Geom::Coord const d) : Snapper(nv, d), _snap_to_itemnode(true), _snap_to_itempath(true), _snap_to_bboxnode(true), _snap_to_bboxpath(true), _snap_to_page_border(false), _strict_snapping(true), _include_item_center(false) { _candidates = new std::vector; - _points_to_snap_to = new std::vector; + _points_to_snap_to = new std::vector; _paths_to_snap_to = new std::vector; } @@ -78,10 +78,10 @@ Inkscape::ObjectSnapper::~ObjectSnapper() void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, std::vector const *it, bool const &first_point, - NR::Rect const &bbox_to_snap, + Geom::Rect const &bbox_to_snap, DimensionToSnap const snap_dim, bool const clip_or_mask, - NR::Matrix const additional_affine) const // transformation of the item being clipped / masked + Geom::Matrix const additional_affine) const // transformation of the item being clipped / masked { bool const c1 = (snap_dim == TRANSL_SNAP_XY) && ThisSnapperMightSnap(); bool const c2 = (snap_dim != TRANSL_SNAP_XY) && GuidesMightSnap(); @@ -96,9 +96,8 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, _candidates->clear(); } - boost::optional bbox_of_item = NR::Rect(); // a default NR::Rect is infinitely large - NR::Rect bbox_to_snap_incl = bbox_to_snap; // _incl means: will include the snapper tolerance - bbox_to_snap_incl.growBy(getSnapperTolerance()); // see? + Geom::Rect bbox_to_snap_incl = bbox_to_snap; // _incl means: will include the snapper tolerance + bbox_to_snap_incl.expandBy(getSnapperTolerance()); // see? for (SPObject* o = sp_object_first_child(parent); o != NULL; o = SP_OBJECT_NEXT(o)) { if (SP_IS_ITEM(o) && !SP_ITEM(o)->isLocked() && !(desktop->itemIsHidden(SP_ITEM(o)) && !clip_or_mask)) { @@ -115,14 +114,14 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, if (it == NULL || i == it->end()) { SPItem *item = SP_ITEM(o); - NR::Matrix transform = NR::identity(); + Geom::Matrix transform = Geom::identity(); if (item) { SPObject *obj = NULL; if (clip_or_mask) { // If the current item is a clipping path or a mask // then store the transformation of the clipped path or mask itself // but also take into account the additional affine of the object // being clipped / masked - transform = item->transform * additional_affine; + transform = to_2geom(item->transform) * additional_affine; } else { // cannot clip or mask more than once // The current item is not a clipping path or a mask, but might // still be the subject of clipping or masking itself ; if so, then @@ -139,25 +138,25 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, } if (SP_IS_GROUP(o)) { - _findCandidates(o, it, false, bbox_to_snap, snap_dim, false, NR::identity()); + _findCandidates(o, it, false, bbox_to_snap, snap_dim, false, Geom::identity()); } else { + boost::optional bbox_of_item = NR::Rect(); if (clip_or_mask) { // Oh oh, this will get ugly. We cannot use sp_item_i2d_affine directly because we need to // insert an additional transformation in document coordinates (code copied from sp_item_i2d_affine) sp_item_invoke_bbox(item, &bbox_of_item, - sp_item_i2doc_affine(item) * matrix_to_desktop(additional_affine, item), + from_2geom(to_2geom(sp_item_i2doc_affine(item)) * matrix_to_desktop(additional_affine, item)), true); - } else { sp_item_invoke_bbox(item, &bbox_of_item, sp_item_i2d_affine(item), true); - } - // See if the item is within range + } if (bbox_of_item) { - if (bbox_to_snap_incl.intersects(*bbox_of_item)) { + // See if the item is within range + if (bbox_to_snap_incl.intersects(to_2geom(*bbox_of_item))) { // This item is within snapping range, so record it as a candidate _candidates->push_back(SnapCandidate(item, clip_or_mask, additional_affine)); - } + } } } } @@ -197,7 +196,7 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::Snapper::PointType const & } for (std::vector::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) { - //NR::Matrix i2doc(NR::identity()); + //Geom::Matrix i2doc(Geom::identity()); SPItem *root_item = (*i).item; if (SP_IS_USE((*i).item)) { root_item = sp_use_root(SP_USE((*i).item)); @@ -207,7 +206,9 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::Snapper::PointType const & //Collect all nodes so we can snap to them if (_snap_to_itemnode) { if (!(_strict_snapping && !p_is_a_node) || p_is_a_guide) { - sp_item_snappoints(root_item, _include_item_center, SnapPointsIter(*_points_to_snap_to)); + std::vector dummy_vctr; + sp_item_snappoints(root_item, _include_item_center, SnapPointsIter(dummy_vctr)); + to_2geom(dummy_vctr, *_points_to_snap_to); } } @@ -220,7 +221,7 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::Snapper::PointType const & boost::optional b = sp_item_bbox_desktop(root_item, bbox_type); if (b) { for ( unsigned k = 0 ; k < 4 ; k++ ) { - _points_to_snap_to->push_back(b->corner(k)); + _points_to_snap_to->push_back(to_2geom(b->corner(k))); } } } @@ -232,9 +233,9 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::Snapper::PointType const & void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - std::vector *unselected_nodes) const + std::vector *unselected_nodes) const { // Iterate through all nodes, find out which one is the closest to p, and snap to it! @@ -247,8 +248,8 @@ void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, SnappedPoint s; bool success = false; - for (std::vector::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) { - NR::Coord dist = NR::L2(*k - p); + for (std::vector::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) { + Geom::Coord dist = Geom::L2(*k - p); if (dist < getSnapperTolerance() && dist < s.getDistance()) { s = SnappedPoint(*k, SNAPTARGET_NODE, dist, getSnapperTolerance(), getSnapperAlwaysSnap()); success = true; @@ -262,8 +263,8 @@ void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, - NR::Point const &guide_normal) const + Geom::Point const &p, + Geom::Point const &guide_normal) const { // Iterate through all nodes, find out which one is the closest to this guide, and snap to it! _collectNodes(t, true); @@ -271,13 +272,13 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s SnappedPoint s; bool success = false; - NR::Coord tol = getSnapperTolerance(); + Geom::Coord tol = getSnapperTolerance(); - for (std::vector::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) { + for (std::vector::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) { // Project each node (*k) on the guide line (running through point p) - NR::Point p_proj = project_on_linesegment(*k, p, p + NR::rot90(guide_normal)); - NR::Coord dist = NR::L2(*k - p_proj); // distance from node to the guide - NR::Coord dist2 = NR::L2(p - p_proj); // distance from projection of node on the guide, to the mouse location + Geom::Point p_proj = project_on_linesegment(*k, p, p + Geom::rot90(guide_normal)); + Geom::Coord dist = Geom::L2(*k - p_proj); // distance from node to the guide + Geom::Coord dist2 = Geom::L2(p - p_proj); // distance from projection of node on the guide, to the mouse location if ((dist < tol && dist2 < tol || getSnapperAlwaysSnap()) && dist < s.getDistance()) { s = SnappedPoint(*k, SNAPTARGET_NODE, dist, tol, getSnapperAlwaysSnap()); success = true; @@ -337,7 +338,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const & for (std::vector::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) { /* Transform the requested snap point to this item's coordinates */ - NR::Matrix i2doc(NR::identity()); + Geom::Matrix i2doc(Geom::identity()); SPItem *root_item = NULL; /* We might have a clone at hand, so make sure we get the root item */ if (SP_IS_USE((*i).item)) { @@ -405,9 +406,9 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const & void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - std::vector *unselected_nodes, + std::vector *unselected_nodes, SPPath const *selected_path) const { _collectPaths(t, first_point); @@ -485,7 +486,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, Geom::Point const sp_dt = desktop->doc2dt(sp_doc); if (!being_edited || (c1 && c2)) { - NR::Coord const dist = Geom::distance(sp_doc, p_doc); + Geom::Coord const dist = Geom::distance(sp_doc, p_doc); if (dist < getSnapperTolerance()) { double t = MIN(*np, (*it_pv).size()); // make sure that t is within bounds; Geom::Curve const *curve = &((*it_pv).at_index(int(t))); @@ -498,7 +499,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, } /* Returns true if point is coincident with one of the unselected nodes */ -bool Inkscape::ObjectSnapper::isUnselectedNode(NR::Point const &point, std::vector const *unselected_nodes) const +bool Inkscape::ObjectSnapper::isUnselectedNode(Geom::Point const &point, std::vector const *unselected_nodes) const { if (unselected_nodes == NULL) { return false; @@ -508,8 +509,8 @@ bool Inkscape::ObjectSnapper::isUnselectedNode(NR::Point const &point, std::vect return false; } - for (std::vector::const_iterator i = unselected_nodes->begin(); i != unselected_nodes->end(); i++) { - if (NR::L2(point - *i) < 1e-4) { + for (std::vector::const_iterator i = unselected_nodes->begin(); i != unselected_nodes->end(); i++) { + if (Geom::L2(point - *i) < 1e-4) { return true; } } @@ -519,7 +520,7 @@ bool Inkscape::ObjectSnapper::isUnselectedNode(NR::Point const &point, std::vect void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, ConstraintLine const &c) const { @@ -532,22 +533,22 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, ** in SPDesktop rather than SPNamedView? */ SPDesktop const *desktop = SP_ACTIVE_DESKTOP; - NR::Point const p_doc = desktop->dt2doc(p); + Geom::Point const p_doc = desktop->dt2doc(p); - NR::Point direction_vector = c.getDirection(); + Geom::Point direction_vector = c.getDirection(); if (!is_zero(direction_vector)) { - direction_vector = NR::unit_vector(direction_vector); + direction_vector = Geom::unit_vector(direction_vector); } - NR::Point const p1_on_cl = c.hasPoint() ? c.getPoint() : p; - NR::Point const p2_on_cl = p1_on_cl + direction_vector; + Geom::Point const p1_on_cl = c.hasPoint() ? c.getPoint() : p; + Geom::Point const p2_on_cl = p1_on_cl + direction_vector; // The intersection point of the constraint line with any path, // must lie within two points on the constraintline: p_min_on_cl and p_max_on_cl // The distance between those points is twice the snapping tolerance - NR::Point const p_proj_on_cl = project_on_linesegment(p, p1_on_cl, p2_on_cl); - NR::Point const p_min_on_cl = desktop->dt2doc(p_proj_on_cl - getSnapperTolerance() * direction_vector); - NR::Point const p_max_on_cl = desktop->dt2doc(p_proj_on_cl + getSnapperTolerance() * direction_vector); + Geom::Point const p_proj_on_cl = project_on_linesegment(p, p1_on_cl, p2_on_cl); + Geom::Point const p_min_on_cl = desktop->dt2doc(p_proj_on_cl - getSnapperTolerance() * direction_vector); + Geom::Point const p_max_on_cl = desktop->dt2doc(p_proj_on_cl + getSnapperTolerance() * direction_vector); Geom::Path cl; std::vector clv; @@ -564,10 +565,10 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, for (std::vector::const_iterator m = cs[0].begin(); m != cs[0].end(); m++) { if ((*m).ta >= 0 && (*m).ta <= 1 ) { // Reconstruct the point of intersection - NR::Point p_inters = p_min_on_cl + ((*m).ta) * (p_max_on_cl - p_min_on_cl); + Geom::Point p_inters = p_min_on_cl + ((*m).ta) * (p_max_on_cl - p_min_on_cl); // When it's within snapping range, then return it // (within snapping range == between p_min_on_cl and p_max_on_cl == 0 < ta < 1) - NR::Coord dist = NR::L2(desktop->dt2doc(p_proj_on_cl) - p_inters); + Geom::Coord dist = Geom::L2(desktop->dt2doc(p_proj_on_cl) - p_inters); SnappedPoint s(desktop->doc2dt(p_inters), SNAPTARGET_PATH, dist, getSnapperTolerance(), getSnapperAlwaysSnap()); sc.points.push_back(s); } @@ -580,11 +581,11 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - boost::optional const &bbox_to_snap, + boost::optional const &bbox_to_snap, std::vector const *it, - std::vector *unselected_nodes) const + std::vector *unselected_nodes) const { if (_snap_enabled == false || getSnapFrom(t) == false || _named_view == NULL) { return; @@ -592,8 +593,8 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, /* Get a list of all the SPItems that we will try to snap to */ if (first_point) { - NR::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : NR::Rect(p, p); - _findCandidates(sp_document_root(_named_view->document), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, NR::identity()); + Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(p, p); + _findCandidates(sp_document_root(_named_view->document), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, Geom::identity()); } if (_snap_to_itemnode || _snap_to_bboxnode || _snap_to_page_border) { @@ -623,9 +624,9 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - boost::optional const &bbox_to_snap, + boost::optional const &bbox_to_snap, ConstraintLine const &c, std::vector const *it) const { @@ -635,8 +636,8 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, /* Get a list of all the SPItems that we will try to snap to */ if (first_point) { - NR::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : NR::Rect(p, p); - _findCandidates(sp_document_root(_named_view->document), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, NR::identity()); + Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(p, p); + _findCandidates(sp_document_root(_named_view->document), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, Geom::identity()); } // A constrained snap, is a snap in only one degree of freedom (specified by the constraint line). @@ -656,8 +657,8 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, // This method is used to snap a guide to nodes, while dragging the guide around void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc, - NR::Point const &p, - NR::Point const &guide_normal) const + Geom::Point const &p, + Geom::Point const &guide_normal) const { if ( NULL == _named_view ) { return; @@ -668,9 +669,9 @@ void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc, std::vector const it; //just an empty list DimensionToSnap snap_dim; - if (guide_normal == component_vectors[NR::Y]) { + if (guide_normal == to_2geom(component_vectors[Geom::Y])) { snap_dim = GUIDE_TRANSL_SNAP_Y; - } else if (guide_normal == component_vectors[NR::X]) { + } else if (guide_normal == to_2geom(component_vectors[Geom::X])) { snap_dim = GUIDE_TRANSL_SNAP_X; } else { snap_dim = ANGLED_GUIDE_TRANSL_SNAP; @@ -686,7 +687,7 @@ void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc, // second time on an object; but should this point then be constrained to the // line, or can it be located anywhere?) - _findCandidates(sp_document_root(_named_view->document), &it, true, NR::Rect(p, p), snap_dim, false, NR::identity()); + _findCandidates(sp_document_root(_named_view->document), &it, true, Geom::Rect(p, p), snap_dim, false, Geom::identity()); _snapTranslatingGuideToNodes(sc, Inkscape::Snapper::SNAPPOINT_GUIDE, p, guide_normal); // _snapRotatingGuideToNodes has not been implemented yet. } @@ -731,7 +732,7 @@ Geom::PathVector* Inkscape::ObjectSnapper::_getPathvFromRect(Geom::Rect const re } } -void Inkscape::ObjectSnapper::_getBorderNodes(std::vector *points) const +void Inkscape::ObjectSnapper::_getBorderNodes(std::vector *points) const { Geom::Coord w = sp_document_width(_named_view->document); Geom::Coord h = sp_document_height(_named_view->document); diff --git a/src/object-snapper.h b/src/object-snapper.h index 3784c43d0..2a5aaf884 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -29,7 +29,7 @@ class SnapCandidate { public: - SnapCandidate(SPItem* item, bool clip_or_mask, NR::Matrix _additional_affine); + SnapCandidate(SPItem* item, bool clip_or_mask, Geom::Matrix _additional_affine); ~SnapCandidate(); SPItem* item; // An item that is to be considered for snapping to @@ -39,14 +39,14 @@ public: * the transformation of the clipping path or mask itself, but also the transformation of * the object to which the clip or mask is being applied; that transformation is stored here */ - NR::Matrix additional_affine; + Geom::Matrix additional_affine; }; class ObjectSnapper : public Snapper { public: - ObjectSnapper(SPNamedView const *nv, NR::Coord const d); + ObjectSnapper(SPNamedView const *nv, Geom::Coord const d); ~ObjectSnapper(); enum DimensionToSnap { @@ -70,70 +70,70 @@ public: bool getIncludeItemCenter() const {return _include_item_center;} void setStrictSnapping(bool enabled) {_strict_snapping = enabled;} void guideSnap(SnappedConstraints &sc, - NR::Point const &p, - NR::Point const &guide_normal) const; + Geom::Point const &p, + Geom::Point const &guide_normal) const; bool ThisSnapperMightSnap() const; bool GuidesMightSnap() const; void freeSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - boost::optional const &bbox_to_snap, + boost::optional const &bbox_to_snap, std::vector const *it, - std::vector *unselected_nodes) const; + std::vector *unselected_nodes) const; void constrainedSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - boost::optional const &bbox_to_snap, + boost::optional const &bbox_to_snap, ConstraintLine const &c, std::vector const *it) const; private: //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap std::vector *_candidates; - std::vector *_points_to_snap_to; + std::vector *_points_to_snap_to; std::vector *_paths_to_snap_to; void _findCandidates(SPObject* parent, std::vector const *it, bool const &first_point, - NR::Rect const &bbox_to_snap, + Geom::Rect const &bbox_to_snap, DimensionToSnap snap_dim, bool const _clip_or_mask, - NR::Matrix const additional_affine) const; + Geom::Matrix const additional_affine) const; void _snapNodes(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - std::vector *unselected_nodes) const; + std::vector *unselected_nodes) const; void _snapTranslatingGuideToNodes(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, - NR::Point const &guide_normal) const; + Geom::Point const &p, + Geom::Point const &guide_normal) const; void _collectNodes(Inkscape::Snapper::PointType const &t, bool const &first_point) const; void _snapPaths(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, - std::vector *unselected_nodes, + std::vector *unselected_nodes, SPPath const *selected_path) const; void _snapPathsConstrained(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, - NR::Point const &p, + Geom::Point const &p, bool const &first_point, ConstraintLine const &c) const; - bool isUnselectedNode(NR::Point const &point, std::vector const *unselected_nodes) const; + bool isUnselectedNode(Geom::Point const &point, std::vector const *unselected_nodes) const; void _collectPaths(Inkscape::Snapper::PointType const &t, bool const &first_point) const; @@ -141,7 +141,7 @@ private: void _clear_paths() const; Geom::PathVector* _getBorderPathv() const; Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const; - void _getBorderNodes(std::vector *points) const; + void _getBorderNodes(std::vector *points) const; bool _snap_to_itemnode; bool _snap_to_itempath; diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index f52094ed1..2c97beafe 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -225,7 +225,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve NR::Point const button_w(bevent.x, bevent.y); /* Find desktop coordinates */ - NR::Point p = pc->desktop->w2d(button_w); + Geom::Point p = pc->desktop->w2d(button_w); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(pc, button_w); @@ -241,12 +241,12 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve default: /* Set first point of sequence */ if (bevent.state & GDK_CONTROL_MASK) { - freehand_create_single_dot(event_context, p, "tools.freehand.pencil", bevent.state); + freehand_create_single_dot(event_context, from_2geom(p), "tools.freehand.pencil", bevent.state); ret = true; break; } if (anchor) { - p = anchor->dp; + p = to_2geom(anchor->dp); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path")); } else { @@ -265,7 +265,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve } } pc->sa = anchor; - spdc_set_startpoint(pc, p); + spdc_set_startpoint(pc, from_2geom(p)); ret = TRUE; break; } @@ -303,7 +303,7 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev } /* Find desktop coordinates */ - NR::Point p = dt->w2d(NR::Point(mevent.x, mevent.y)); + Geom::Point p = to_2geom(dt->w2d(NR::Point(mevent.x, mevent.y))); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(pc, NR::Point(mevent.x, mevent.y)); @@ -325,11 +325,13 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev case SP_PENCIL_CONTEXT_ADDLINE: /* Set red endpoint */ if (anchor) { - p = anchor->dp; + p = to_2geom(anchor->dp); } else { - spdc_endpoint_snap(pc, p, mevent.state); + NR::Point ptnr = from_2geom(p); + spdc_endpoint_snap(pc, ptnr, mevent.state); + p = to_2geom(ptnr); } - spdc_set_endpoint(pc, p); + spdc_set_endpoint(pc, from_2geom(p)); ret = TRUE; break; default: @@ -345,14 +347,14 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev * in middle of freehand (Lauris) */ if (anchor) { - p = anchor->dp; + p = to_2geom(anchor->dp); } else if ((mevent.state & GDK_SHIFT_MASK) == 0) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt, NULL); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p); } if ( pc->npoints != 0 ) { // buttonpress may have happened before we entered draw context! - spdc_add_freehand_point(pc, p, mevent.state); + spdc_add_freehand_point(pc, from_2geom(p), mevent.state); ret = TRUE; } diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 67a74ee11..e8d7dc7dd 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -301,13 +301,14 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent dragging = true; /* Position center */ - NR::Point const button_dt(desktop->w2d(button_w)); - rc->center = button_dt; + Geom::Point button_dt(desktop->w2d(button_w)); + rc->center = from_2geom(button_dt); /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, NULL); //null, because we don't have an item yet - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, rc->center); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, button_dt); + rc->center = from_2geom(button_dt); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 562fc760e..49e5d5359 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -291,8 +291,9 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho // Next, get all points to consider for snapping SnapManager const &m = _desktop->namedview->snap_manager; - _snap_points = selection->getSnapPoints(m.getIncludeItemCenter()); - std::vector snap_points_hull = selection->getSnapPointsConvexHull(); + to_2geom(selection->getSnapPoints(m.getIncludeItemCenter()), _snap_points); + std::vector snap_points_hull; + to_2geom(selection->getSnapPointsConvexHull(), snap_points_hull); if (_snap_points.size() > 100) { /* Snapping a huge number of nodes will take way too long, so limit the number of snappable nodes An average user would rarely ever try to snap such a large number of nodes anyway, because @@ -306,7 +307,7 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho // any other special points NR::Rect snap_points_bbox; if ( snap_points_hull.empty() == false ) { - std::vector::iterator i = snap_points_hull.begin(); + std::vector::iterator i = snap_points_hull.begin(); snap_points_bbox = NR::Rect(*i, *i); i++; while (i != snap_points_hull.end()) { @@ -319,7 +320,7 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho if (_bbox) { // ... and add the bbox corners to _bbox_points for ( unsigned i = 0 ; i < 4 ; i++ ) { - _bbox_points.push_back(_bbox->corner(i)); + _bbox_points.push_back(to_2geom(_bbox->corner(i))); } // There are two separate "opposites" (i.e. opposite w.r.t. the handle being dragged): // - one for snapping the boundingbox, which can be either visual or geometric @@ -936,8 +937,10 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state) } // Snap along a suitable constraint vector from the origin. - bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale, _origin_for_bboxpoints); - sn = m.constrainedSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale, _origin_for_specpoints); + Geom::Scale default_scale_2geom = to_2geom(default_scale); + Geom::Scale geom_scale_2geom = to_2geom(geom_scale); + bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale_2geom, to_2geom(_origin_for_bboxpoints)); + sn = m.constrainedSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale_2geom, to_2geom(_origin_for_specpoints)); /* Choose the smaller difference in scale. Since s[X] == s[Y] we can ** just compare difference in s[X]. @@ -946,8 +949,10 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state) sd = sn.getSnapped() ? fabs(sn.getTransformation()[NR::X] - geom_scale[NR::X]) : NR_HUGE; } else { /* Scale aspect ratio is unlocked */ - bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale, _origin_for_bboxpoints); - sn = m.freeSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale, _origin_for_specpoints); + Geom::Scale default_scale_2geom = to_2geom(default_scale); + Geom::Scale geom_scale_2geom = to_2geom(geom_scale); + bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale_2geom, to_2geom(_origin_for_bboxpoints)); + sn = m.freeSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale_2geom, to_2geom(_origin_for_specpoints)); /* Pick the snap that puts us closest to the original scale */ bd = bb.getSnapped() ? fabs(NR::L2(bb.getTransformation()) - NR::L2(default_scale.point())) : NR_HUGE; @@ -1035,8 +1040,10 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR:: bool symmetrical = state & GDK_CONTROL_MASK; - bb = m.constrainedSnapStretch(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale[axis], _origin_for_bboxpoints, axis, symmetrical); - sn = m.constrainedSnapStretch(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale[axis], _origin_for_specpoints, axis, symmetrical); + Geom::Scale default_scale_2geom = to_2geom(default_scale); + Geom::Scale geom_scale_2geom = to_2geom(geom_scale); + bb = m.constrainedSnapStretch(Snapper::SNAPPOINT_BBOX, _bbox_points, Geom::Coord(default_scale_2geom[axis]), to_2geom(_origin_for_bboxpoints), Geom::Dim2(axis), symmetrical); + sn = m.constrainedSnapStretch(Snapper::SNAPPOINT_NODE, _snap_points, Geom::Coord(geom_scale_2geom[axis]), to_2geom(_origin_for_specpoints), Geom::Dim2(axis), symmetrical); if (bb.getSnapped()) { // We snapped the bbox (which is either visual or geometric) @@ -1151,8 +1158,8 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi Inkscape::Snapper::ConstraintLine const constraint(component_vectors[dim_b]); NR::Point const s(skew[dim_a], scale[dim_a]); - Inkscape::SnappedPoint bb = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, constraint, s, _origin, dim_b); - Inkscape::SnappedPoint sn = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, constraint, s, _origin, dim_b); + Inkscape::SnappedPoint bb = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, constraint, to_2geom(s), to_2geom(_origin), Geom::Dim2(dim_b)); + Inkscape::SnappedPoint sn = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, constraint, to_2geom(s), to_2geom(_origin), Geom::Dim2(dim_b)); if (bb.getSnapped() || sn.getSnapped()) { // We snapped something, so change the skew to reflect it @@ -1260,7 +1267,9 @@ gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state) { SnapManager &m = _desktop->namedview->snap_manager; m.setup(_desktop); - m.freeSnapReturnByRef(Snapper::SNAPPOINT_NODE, pt); + Geom::Point pt2g = to_2geom(pt); + m.freeSnapReturnByRef(Snapper::SNAPPOINT_NODE, pt2g); + pt = from_2geom(pt2g); if (state & GDK_CONTROL_MASK) { if ( fabs(_point[NR::X] - pt[NR::X]) > fabs(_point[NR::Y] - pt[NR::Y]) ) { @@ -1356,7 +1365,7 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state) m.setup(_desktop, _items_const); /* The amount that we've moved by during this drag */ - NR::Point dxy = xy - _point; + Geom::Point dxy = to_2geom(xy - _point); bool const alt = (state & GDK_MOD1_MASK); bool const control = (state & GDK_CONTROL_MASK); @@ -1437,22 +1446,22 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state) // If we didn't snap, then we should still constrain horizontally or vertically // (When we did snap, then this constraint has already been enforced by // calling constrainedSnapTranslation() above) - if (fabs(dxy[NR::X]) > fabs(dxy[NR::Y])) { - dxy[NR::Y] = 0; + if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) { + dxy[Geom::Y] = 0; } else { - dxy[NR::X] = 0; + dxy[Geom::X] = 0; } } } } - NR::Matrix const move((NR::translate(dxy))); - NR::Point const norm(0, 0); - transform(move, norm); + Geom::Matrix const move((Geom::Translate(dxy))); + Geom::Point const norm(0, 0); + transform(from_2geom(move), from_2geom(norm)); // status text - GString *xs = SP_PX_TO_METRIC_STRING(dxy[NR::X], _desktop->namedview->getDefaultMetric()); - GString *ys = SP_PX_TO_METRIC_STRING(dxy[NR::Y], _desktop->namedview->getDefaultMetric()); + GString *xs = SP_PX_TO_METRIC_STRING(dxy[Geom::X], _desktop->namedview->getDefaultMetric()); + GString *ys = SP_PX_TO_METRIC_STRING(dxy[Geom::Y], _desktop->namedview->getDefaultMetric()); _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move by %s, %s; with Ctrl to restrict to horizontal/vertical; with Shift to disable snapping"), xs->str, ys->str); g_string_free(xs, TRUE); g_string_free(ys, TRUE); diff --git a/src/seltrans.h b/src/seltrans.h index 3a7f6f4b2..65da0fa56 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -115,8 +115,8 @@ private: std::vector _items_affines; std::vector _items_centers; - std::vector _snap_points; - std::vector _bbox_points; + std::vector _snap_points; + std::vector _bbox_points; Inkscape::SelCue _selcue; diff --git a/src/snap.cpp b/src/snap.cpp index 778294711..9ae330b77 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -181,9 +181,9 @@ bool SnapManager::getSnapModeGuide() const */ void SnapManager::freeSnapReturnByRef(Inkscape::Snapper::PointType point_type, - NR::Point &p, + Geom::Point &p, bool first_point, - boost::optional const &bbox_to_snap) const + boost::optional const &bbox_to_snap) const { Inkscape::SnappedPoint const s = freeSnap(point_type, p, first_point, bbox_to_snap); s.getPoint(p); @@ -201,9 +201,9 @@ void SnapManager::freeSnapReturnByRef(Inkscape::Snapper::PointType point_type, */ Inkscape::SnappedPoint SnapManager::freeSnap(Inkscape::Snapper::PointType point_type, - NR::Point const &p, + Geom::Point const &p, bool first_point, - boost::optional const &bbox_to_snap) const + boost::optional const &bbox_to_snap) const { if (!SomeSnapperMightSnap()) { return Inkscape::SnappedPoint(p, Inkscape::SNAPTARGET_UNDEFINED, NR_HUGE, 0, false); @@ -249,8 +249,8 @@ Geom::Point SnapManager::multipleOfGridPitch(Geom::Point const &t) const if (desktop && desktop->gridsEnabled()) { bool success = false; - NR::Point nearest_multiple; - NR::Coord nearest_distance = NR_HUGE; + Geom::Point nearest_multiple; + Geom::Coord nearest_distance = NR_HUGE; // It will snap to the grid for which we find the closest snap. This might be a different // grid than to which the objects were initially aligned. I don't see an easy way to fix @@ -266,15 +266,15 @@ Geom::Point SnapManager::multipleOfGridPitch(Geom::Point const &t) const // will use the grid snapper. Simply snapping the value t to the grid will do, but // only if the origin of the grid is at (0,0). If it's not then compensate for this // in the translation t - NR::Point const t_offset = from_2geom(t) + grid->origin; + Geom::Point const t_offset = from_2geom(t) + grid->origin; SnappedConstraints sc; // Only the first three parameters are being used for grid snappers - snapper->freeSnap(sc, Inkscape::Snapper::SNAPPOINT_NODE, t_offset, TRUE, boost::optional(), NULL, NULL); + snapper->freeSnap(sc, Inkscape::Snapper::SNAPPOINT_NODE, t_offset, TRUE, boost::optional(), NULL, NULL); // Find the best snap for this grid, including intersections of the grid-lines Inkscape::SnappedPoint s = findBestSnap(t_offset, sc, false); if (s.getSnapped() && (s.getDistance() < nearest_distance)) { success = true; - nearest_multiple = s.getPoint() - grid->origin; + nearest_multiple = s.getPoint() - to_2geom(grid->origin); nearest_distance = s.getDistance(); } } @@ -300,10 +300,10 @@ Geom::Point SnapManager::multipleOfGridPitch(Geom::Point const &t) const */ void SnapManager::constrainedSnapReturnByRef(Inkscape::Snapper::PointType point_type, - NR::Point &p, + Geom::Point &p, Inkscape::Snapper::ConstraintLine const &constraint, bool first_point, - boost::optional const &bbox_to_snap) const + boost::optional const &bbox_to_snap) const { Inkscape::SnappedPoint const s = constrainedSnap(point_type, p, constraint, first_point, bbox_to_snap); s.getPoint(p); @@ -322,10 +322,10 @@ void SnapManager::constrainedSnapReturnByRef(Inkscape::Snapper::PointType point_ */ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::Snapper::PointType point_type, - NR::Point const &p, + Geom::Point const &p, Inkscape::Snapper::ConstraintLine const &constraint, bool first_point, - boost::optional const &bbox_to_snap) const + boost::optional const &bbox_to_snap) const { if (!SomeSnapperMightSnap()) { return Inkscape::SnappedPoint(p, Inkscape::SNAPTARGET_UNDEFINED, NR_HUGE, 0, false); @@ -354,7 +354,7 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::Snapper::PointType return findBestSnap(p, sc, true); } -void SnapManager::guideSnap(NR::Point &p, NR::Point const &guide_normal) const +void SnapManager::guideSnap(Geom::Point &p, Geom::Point const &guide_normal) const { // This method is used to snap a guide to nodes, while dragging the guide around @@ -388,13 +388,13 @@ void SnapManager::guideSnap(NR::Point &p, NR::Point const &guide_normal) const Inkscape::SnappedPoint SnapManager::_snapTransformed( Inkscape::Snapper::PointType type, - std::vector const &points, + std::vector const &points, bool constrained, Inkscape::Snapper::ConstraintLine const &constraint, Transformation transformation_type, - NR::Point const &transformation, - NR::Point const &origin, - NR::Dim2 dim, + Geom::Point const &transformation, + Geom::Point const &origin, + Geom::Dim2 dim, bool uniform) const { /* We have a list of points, which we are proposing to transform in some way. We need to see @@ -410,25 +410,25 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed( return Inkscape::SnappedPoint(); } - std::vector transformed_points; - NR::Rect bbox; + std::vector transformed_points; + Geom::Rect bbox; - for (std::vector::const_iterator i = points.begin(); i != points.end(); i++) { + for (std::vector::const_iterator i = points.begin(); i != points.end(); i++) { /* Work out the transformed version of this point */ - NR::Point transformed; + Geom::Point transformed; switch (transformation_type) { case TRANSLATION: transformed = *i + transformation; break; case SCALE: - transformed = (*i - origin) * NR::scale(transformation[NR::X], transformation[NR::Y]) + origin; + transformed = (*i - origin) * Geom::Scale(transformation[Geom::X], transformation[Geom::Y]) + origin; break; case STRETCH: { - NR::scale s(1, 1); + Geom::Scale s(1, 1); if (uniform) - s[NR::X] = s[NR::Y] = transformation[dim]; + s[Geom::X] = s[Geom::Y] = transformation[dim]; else { s[dim] = transformation[dim]; s[1 - dim] = 1; @@ -449,7 +449,7 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed( // add the current transformed point to the box hulling all transformed points if (i == points.begin()) { - bbox = NR::Rect(transformed, transformed); + bbox = Geom::Rect(transformed, transformed); } else { bbox.expandTo(transformed); } @@ -458,22 +458,22 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed( } /* The current best transformation */ - NR::Point best_transformation = transformation; + Geom::Point best_transformation = transformation; /* The current best metric for the best transformation; lower is better, NR_HUGE ** means that we haven't snapped anything. */ - NR::Coord best_metric = NR_HUGE; - NR::Coord best_second_metric = NR_HUGE; - NR::Point best_scale_metric(NR_HUGE, NR_HUGE); + Geom::Coord best_metric = NR_HUGE; + Geom::Coord best_second_metric = NR_HUGE; + Geom::Point best_scale_metric(NR_HUGE, NR_HUGE); Inkscape::SnappedPoint best_snapped_point; g_assert(best_snapped_point.getAlwaysSnap() == false); // Check initialization of snapped point g_assert(best_snapped_point.getAtIntersection() == false); - std::vector::const_iterator j = transformed_points.begin(); + std::vector::const_iterator j = transformed_points.begin(); // std::cout << std::endl; - for (std::vector::const_iterator i = points.begin(); i != points.end(); i++) { + for (std::vector::const_iterator i = points.begin(); i != points.end(); i++) { /* Snap it */ Inkscape::SnappedPoint snapped_point; @@ -502,17 +502,17 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed( snapped_point = freeSnap(type, *j, i == points.begin(), bbox); } - NR::Point result; - NR::Coord metric = NR_HUGE; - NR::Coord second_metric = NR_HUGE; - NR::Point scale_metric(NR_HUGE, NR_HUGE); + Geom::Point result; + Geom::Coord metric = NR_HUGE; + Geom::Coord second_metric = NR_HUGE; + Geom::Point scale_metric(NR_HUGE, NR_HUGE); if (snapped_point.getSnapped()) { /* We snapped. Find the transformation that describes where the snapped point has ** ended up, and also the metric for this transformation. */ - NR::Point const a = (snapped_point.getPoint() - origin); // vector to snapped point - NR::Point const b = (*i - origin); // vector to original point + Geom::Point const a = (snapped_point.getPoint() - origin); // vector to snapped point + Geom::Point const b = (*i - origin); // vector to original point switch (transformation_type) { case TRANSLATION: @@ -521,17 +521,17 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed( * horizontal and vertical directions. The distance to the intersection of * the grid lines will always be larger then the distance to a single grid * line. If we prefer snapping to an intersection instead of to a single - * grid line, then we cannot use "metric = NR::L2(result)". Therefore the + * grid line, then we cannot use "metric = Geom::L2(result)". Therefore the * snapped distance will be used as a metric. Please note that the snapped * distance is defined as the distance to the nearest line of the intersection, * and not to the intersection itself! */ - metric = snapped_point.getDistance(); //used to be: metric = NR::L2(result); + metric = snapped_point.getDistance(); //used to be: metric = Geom::L2(result); second_metric = snapped_point.getSecondDistance(); break; case SCALE: { - result = NR::Point(NR_HUGE, NR_HUGE); + result = Geom::Point(NR_HUGE, NR_HUGE); // If this point *i is horizontally or vertically aligned with // the origin of the scaling, then it will scale purely in X or Y // We can therefore only calculate the scaling in this direction @@ -551,7 +551,7 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed( break; } case STRETCH: - result = NR::Point(NR_HUGE, NR_HUGE); + result = Geom::Point(NR_HUGE, NR_HUGE); if (fabs(b[dim]) > 1e-6) { // if STRETCHING will occur for this point result[dim] = a[dim] / b[dim]; result[1-dim] = uniform ? result[dim] : 1; @@ -650,10 +650,10 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed( */ Inkscape::SnappedPoint SnapManager::freeSnapTranslation(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::Point const &tr) const + std::vector const &p, + Geom::Point const &tr) const { - return _snapTransformed(point_type, p, false, NR::Point(), TRANSLATION, tr, NR::Point(), NR::X, false); + return _snapTransformed(point_type, p, false, Geom::Point(), TRANSLATION, tr, Geom::Point(), Geom::X, false); } @@ -670,11 +670,11 @@ Inkscape::SnappedPoint SnapManager::freeSnapTranslation(Inkscape::Snapper::Point */ Inkscape::SnappedPoint SnapManager::constrainedSnapTranslation(Inkscape::Snapper::PointType point_type, - std::vector const &p, + std::vector const &p, Inkscape::Snapper::ConstraintLine const &constraint, - NR::Point const &tr) const + Geom::Point const &tr) const { - return _snapTransformed(point_type, p, true, constraint, TRANSLATION, tr, NR::Point(), NR::X, false); + return _snapTransformed(point_type, p, true, constraint, TRANSLATION, tr, Geom::Point(), Geom::X, false); } @@ -690,11 +690,11 @@ Inkscape::SnappedPoint SnapManager::constrainedSnapTranslation(Inkscape::Snapper */ Inkscape::SnappedPoint SnapManager::freeSnapScale(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::scale const &s, - NR::Point const &o) const + std::vector const &p, + Geom::Scale const &s, + Geom::Point const &o) const { - return _snapTransformed(point_type, p, false, NR::Point(), SCALE, NR::Point(s[NR::X], s[NR::Y]), o, NR::X, false); + return _snapTransformed(point_type, p, false, Geom::Point(), SCALE, Geom::Point(s[Geom::X], s[Geom::Y]), o, Geom::X, false); } @@ -711,12 +711,12 @@ Inkscape::SnappedPoint SnapManager::freeSnapScale(Inkscape::Snapper::PointType p */ Inkscape::SnappedPoint SnapManager::constrainedSnapScale(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::scale const &s, - NR::Point const &o) const + std::vector const &p, + Geom::Scale const &s, + Geom::Point const &o) const { // When constrained scaling, only uniform scaling is supported. - return _snapTransformed(point_type, p, true, NR::Point(), SCALE, NR::Point(s[NR::X], s[NR::Y]), o, NR::X, true); + return _snapTransformed(point_type, p, true, Geom::Point(), SCALE, Geom::Point(s[Geom::X], s[Geom::Y]), o, Geom::X, true); } @@ -734,13 +734,13 @@ Inkscape::SnappedPoint SnapManager::constrainedSnapScale(Inkscape::Snapper::Poin */ Inkscape::SnappedPoint SnapManager::constrainedSnapStretch(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::Coord const &s, - NR::Point const &o, - NR::Dim2 d, + std::vector const &p, + Geom::Coord const &s, + Geom::Point const &o, + Geom::Dim2 d, bool u) const { - return _snapTransformed(point_type, p, true, NR::Point(), STRETCH, NR::Point(s, s), o, d, u); + return _snapTransformed(point_type, p, true, Geom::Point(), STRETCH, Geom::Point(s, s), o, d, u); } @@ -757,17 +757,17 @@ Inkscape::SnappedPoint SnapManager::constrainedSnapStretch(Inkscape::Snapper::Po */ Inkscape::SnappedPoint SnapManager::constrainedSnapSkew(Inkscape::Snapper::PointType point_type, - std::vector const &p, + std::vector const &p, Inkscape::Snapper::ConstraintLine const &constraint, - NR::Point const &s, - NR::Point const &o, - NR::Dim2 d) const + Geom::Point const &s, + Geom::Point const &o, + Geom::Dim2 d) const { // "s" contains skew factor in s[0], and scale factor in s[1] return _snapTransformed(point_type, p, true, constraint, SKEW, s, o, d, false); } -Inkscape::SnappedPoint SnapManager::findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const +Inkscape::SnappedPoint SnapManager::findBestSnap(Geom::Point const &p, SnappedConstraints &sc, bool constrained) const { /* std::cout << "Type and number of snapped constraints: " << std::endl; @@ -883,7 +883,7 @@ Inkscape::SnappedPoint SnapManager::findBestSnap(NR::Point const &p, SnappedCons return bestSnappedPoint; } -void SnapManager::setup(SPDesktop const *desktop_for_snapindicator, SPItem const *item_to_ignore, std::vector *unselected_nodes) +void SnapManager::setup(SPDesktop const *desktop_for_snapindicator, SPItem const *item_to_ignore, std::vector *unselected_nodes) { _item_to_ignore = item_to_ignore; _items_to_ignore = NULL; @@ -891,7 +891,7 @@ void SnapManager::setup(SPDesktop const *desktop_for_snapindicator, SPItem const _unselected_nodes = unselected_nodes; } -void SnapManager::setup(SPDesktop const *desktop_for_snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes) +void SnapManager::setup(SPDesktop const *desktop_for_snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes) { _item_to_ignore = NULL; _items_to_ignore = &items_to_ignore; diff --git a/src/snap.h b/src/snap.h index 2ed786a63..e4f9aaddf 100644 --- a/src/snap.h +++ b/src/snap.h @@ -47,71 +47,71 @@ public: bool SomeSnapperMightSnap() const; - void setup(SPDesktop const *desktop_for_snapindicator = NULL, SPItem const *item_to_ignore = NULL, std::vector *unselected_nodes = NULL); - void setup(SPDesktop const *desktop_for_snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes = NULL); + void setup(SPDesktop const *desktop_for_snapindicator = NULL, SPItem const *item_to_ignore = NULL, std::vector *unselected_nodes = NULL); + void setup(SPDesktop const *desktop_for_snapindicator, std::vector &items_to_ignore, std::vector *unselected_nodes = NULL); // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a // point if snapping has occured (by overwriting p); otherwise p is untouched void freeSnapReturnByRef(Inkscape::Snapper::PointType point_type, - NR::Point &p, + Geom::Point &p, bool first_point = true, - boost::optional const &bbox_to_snap = boost::optional()) const; + boost::optional const &bbox_to_snap = boost::optional()) const; Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType point_type, - NR::Point const &p, + Geom::Point const &p, bool first_point = true, - boost::optional const &bbox_to_snap = boost::optional() ) const; + boost::optional const &bbox_to_snap = boost::optional() ) const; Geom::Point multipleOfGridPitch(Geom::Point const &t) const; // constrainedSnapReturnByRef() is preferred over constrainedSnap(), because it only returns a // point, by overwriting p, if snapping has occured; otherwise p is untouched void constrainedSnapReturnByRef(Inkscape::Snapper::PointType point_type, - NR::Point &p, + Geom::Point &p, Inkscape::Snapper::ConstraintLine const &constraint, bool first_point = true, - boost::optional const &bbox_to_snap = boost::optional()) const; + boost::optional const &bbox_to_snap = boost::optional()) const; Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType point_type, - NR::Point const &p, + Geom::Point const &p, Inkscape::Snapper::ConstraintLine const &constraint, bool first_point = true, - boost::optional const &bbox_to_snap = boost::optional()) const; + boost::optional const &bbox_to_snap = boost::optional()) const; - void guideSnap(NR::Point &p, NR::Point const &guide_normal) const; + void guideSnap(Geom::Point &p, Geom::Point const &guide_normal) const; Inkscape::SnappedPoint freeSnapTranslation(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::Point const &tr) const; + std::vector const &p, + Geom::Point const &tr) const; Inkscape::SnappedPoint constrainedSnapTranslation(Inkscape::Snapper::PointType point_type, - std::vector const &p, + std::vector const &p, Inkscape::Snapper::ConstraintLine const &constraint, - NR::Point const &tr) const; + Geom::Point const &tr) const; Inkscape::SnappedPoint freeSnapScale(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::scale const &s, - NR::Point const &o) const; + std::vector const &p, + Geom::Scale const &s, + Geom::Point const &o) const; Inkscape::SnappedPoint constrainedSnapScale(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::scale const &s, - NR::Point const &o) const; + std::vector const &p, + Geom::Scale const &s, + Geom::Point const &o) const; Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::Snapper::PointType point_type, - std::vector const &p, - NR::Coord const &s, - NR::Point const &o, - NR::Dim2 d, + std::vector const &p, + Geom::Coord const &s, + Geom::Point const &o, + Geom::Dim2 d, bool uniform) const; Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::Snapper::PointType point_type, - std::vector const &p, + std::vector const &p, Inkscape::Snapper::ConstraintLine const &constraint, - NR::Point const &s, // s[0] = skew factor, s[1] = scale factor - NR::Point const &o, - NR::Dim2 d) const; + Geom::Point const &s, // s[0] = skew factor, s[1] = scale factor + Geom::Point const &o, + Geom::Dim2 d) const; Inkscape::GuideSnapper guide; ///< guide snapper Inkscape::ObjectSnapper object; ///< snapper to other objects @@ -173,19 +173,19 @@ private: std::vector *_items_to_ignore; SPItem const *_item_to_ignore; SPDesktop const *_desktop_for_snapindicator; - std::vector *_unselected_nodes; + std::vector *_unselected_nodes; Inkscape::SnappedPoint _snapTransformed(Inkscape::Snapper::PointType type, - std::vector const &points, + std::vector const &points, bool constrained, Inkscape::Snapper::ConstraintLine const &constraint, Transformation transformation_type, - NR::Point const &transformation, - NR::Point const &origin, - NR::Dim2 dim, + Geom::Point const &transformation, + Geom::Point const &origin, + Geom::Dim2 dim, bool uniform) const; - Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const; + Inkscape::SnappedPoint findBestSnap(Geom::Point const &p, SnappedConstraints &sc, bool constrained) const; }; #endif /* !SEEN_SNAP_H */ diff --git a/src/snapped-curve.cpp b/src/snapped-curve.cpp index c6b7edc8a..17d417d40 100644 --- a/src/snapped-curve.cpp +++ b/src/snapped-curve.cpp @@ -18,7 +18,7 @@ #include "desktop.h" #include "inkscape.h" -Inkscape::SnappedCurve::SnappedCurve(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, Geom::Curve const *curve) +Inkscape::SnappedCurve::SnappedCurve(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Curve const *curve) { _distance = snapped_distance; _tolerance = snapped_tolerance; @@ -40,7 +40,7 @@ Inkscape::SnappedCurve::SnappedCurve() _second_distance = NR_HUGE; _second_tolerance = 0; _second_always_snap = false; - _point = NR::Point(0,0); + _point = Geom::Point(0,0); _at_intersection = false; } @@ -48,7 +48,7 @@ Inkscape::SnappedCurve::~SnappedCurve() { } -Inkscape::SnappedPoint Inkscape::SnappedCurve::intersect(SnappedCurve const &curve, NR::Point const &p) const +Inkscape::SnappedPoint Inkscape::SnappedCurve::intersect(SnappedCurve const &curve, Geom::Point const &p) const { // Calculate the intersections of two curves, which are both within snapping range, and // return only the closest intersection @@ -87,7 +87,7 @@ Inkscape::SnappedPoint Inkscape::SnappedCurve::intersect(SnappedCurve const &cur } // No intersection - return SnappedPoint(NR::Point(NR_HUGE, NR_HUGE), SNAPTARGET_UNDEFINED, NR_HUGE, 0, false, false, NR_HUGE, 0, false); + return SnappedPoint(Geom::Point(NR_HUGE, NR_HUGE), SNAPTARGET_UNDEFINED, NR_HUGE, 0, false, false, NR_HUGE, 0, false); } // search for the closest snapped line @@ -106,7 +106,7 @@ bool getClosestCurve(std::list const &list, Inkscape::Sn } // search for the closest intersection of two snapped curves, which are both member of the same collection -bool getClosestIntersectionCS(std::list const &list, NR::Point const &p, Inkscape::SnappedPoint &result) +bool getClosestIntersectionCS(std::list const &list, Geom::Point const &p, Inkscape::SnappedPoint &result) { bool success = false; diff --git a/src/snapped-curve.h b/src/snapped-curve.h index 28908c42f..e6e71e648 100644 --- a/src/snapped-curve.h +++ b/src/snapped-curve.h @@ -27,9 +27,9 @@ class SnappedCurve : public SnappedPoint { public: SnappedCurve(); - SnappedCurve(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, Geom::Curve const *curve); + SnappedCurve(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Curve const *curve); ~SnappedCurve(); - Inkscape::SnappedPoint intersect(SnappedCurve const &curve, NR::Point const &p) const; //intersect with another SnappedCurve + Inkscape::SnappedPoint intersect(SnappedCurve const &curve, Geom::Point const &p) const; //intersect with another SnappedCurve private: Geom::Curve const *_curve; @@ -38,7 +38,7 @@ private: } bool getClosestCurve(std::list const &list, Inkscape::SnappedCurve &result); -bool getClosestIntersectionCS(std::list const &list, NR::Point const &p, Inkscape::SnappedPoint &result); +bool getClosestIntersectionCS(std::list const &list, Geom::Point const &p, Inkscape::SnappedPoint &result); #endif /* !SEEN_SNAPPEDCURVE_H */ diff --git a/src/snapped-line.cpp b/src/snapped-line.cpp index 11298bf25..f35c7a81c 100644 --- a/src/snapped-line.cpp +++ b/src/snapped-line.cpp @@ -12,7 +12,7 @@ #include <2geom/geom.h> #include "libnr/nr-values.h" -Inkscape::SnappedLineSegment::SnappedLineSegment(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, NR::Point const &start_point_of_line, NR::Point const &end_point_of_line) +Inkscape::SnappedLineSegment::SnappedLineSegment(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Point const &start_point_of_line, Geom::Point const &end_point_of_line) : _start_point_of_line(start_point_of_line), _end_point_of_line(end_point_of_line) { _point = snapped_point; @@ -27,9 +27,9 @@ Inkscape::SnappedLineSegment::SnappedLineSegment(NR::Point const &snapped_point, Inkscape::SnappedLineSegment::SnappedLineSegment() { - _start_point_of_line = NR::Point(0,0); - _end_point_of_line = NR::Point(0,0); - _point = NR::Point(0,0); + _start_point_of_line = Geom::Point(0,0); + _end_point_of_line = Geom::Point(0,0); + _point = Geom::Point(0,0); _distance = NR_HUGE; _tolerance = 0; _always_snap = false; @@ -50,7 +50,7 @@ Inkscape::SnappedPoint Inkscape::SnappedLineSegment::intersect(SnappedLineSegmen Geom::IntersectorKind result = segment_intersect(_start_point_of_line, _end_point_of_line, line._start_point_of_line, line._end_point_of_line, intersection_2geom); - NR::Point intersection(intersection_2geom); + Geom::Point intersection(intersection_2geom); if (result == Geom::intersects) { /* If a snapper has been told to "always snap", then this one should be preferred @@ -77,7 +77,7 @@ Inkscape::SnappedPoint Inkscape::SnappedLineSegment::intersect(SnappedLineSegmen -Inkscape::SnappedLine::SnappedLine(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, NR::Point const &normal_to_line, NR::Point const &point_on_line) +Inkscape::SnappedLine::SnappedLine(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Point const &normal_to_line, Geom::Point const &point_on_line) : _normal_to_line(normal_to_line), _point_on_line(point_on_line) { _distance = snapped_distance; @@ -92,15 +92,15 @@ Inkscape::SnappedLine::SnappedLine(NR::Point const &snapped_point, NR::Coord con Inkscape::SnappedLine::SnappedLine() { - _normal_to_line = NR::Point(0,0); - _point_on_line = NR::Point(0,0); + _normal_to_line = Geom::Point(0,0); + _point_on_line = Geom::Point(0,0); _distance = NR_HUGE; _tolerance = 0; _always_snap = false; _second_distance = NR_HUGE; _second_tolerance = 0; _second_always_snap = false; - _point = NR::Point(0,0); + _point = Geom::Point(0,0); _at_intersection = false; } @@ -117,7 +117,7 @@ Inkscape::SnappedPoint Inkscape::SnappedLine::intersect(SnappedLine const &line) Geom::Point intersection_2geom(NR_HUGE, NR_HUGE); Geom::IntersectorKind result = Geom::line_intersection(getNormal(), getConstTerm(), line.getNormal(), line.getConstTerm(), intersection_2geom); - NR::Point intersection(intersection_2geom); + Geom::Point intersection(intersection_2geom); if (result == Geom::intersects) { /* If a snapper has been told to "always snap", then this one should be preferred diff --git a/src/snapped-line.h b/src/snapped-line.h index 4713d9626..ea18baefc 100644 --- a/src/snapped-line.h +++ b/src/snapped-line.h @@ -26,13 +26,13 @@ class SnappedLineSegment : public SnappedPoint { public: SnappedLineSegment(); - SnappedLineSegment(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, NR::Point const &start_point_of_line, NR::Point const &end_point_of_line); + SnappedLineSegment(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Point const &start_point_of_line, Geom::Point const &end_point_of_line); ~SnappedLineSegment(); Inkscape::SnappedPoint intersect(SnappedLineSegment const &line) const; //intersect with another SnappedLineSegment private: - NR::Point _start_point_of_line; - NR::Point _end_point_of_line; + Geom::Point _start_point_of_line; + Geom::Point _end_point_of_line; }; @@ -41,18 +41,18 @@ class SnappedLine : public SnappedPoint { public: SnappedLine(); - SnappedLine(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, NR::Point const &normal_to_line, NR::Point const &point_on_line); + SnappedLine(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Point const &normal_to_line, Geom::Point const &point_on_line); ~SnappedLine(); Inkscape::SnappedPoint intersect(SnappedLine const &line) const; //intersect with another SnappedLine // This line is described by this equation: // a*x + b*y = c <-> nx*px + ny+py = c <-> n.p = c - NR::Point getNormal() const {return _normal_to_line;} // n = (nx, ny) - NR::Point getPointOnLine() const {return _point_on_line;} // p = (px, py) - NR::Coord getConstTerm() const {return dot(_normal_to_line, _point_on_line);} // c = n.p = nx*px + ny*py; + Geom::Point getNormal() const {return _normal_to_line;} // n = (nx, ny) + Geom::Point getPointOnLine() const {return _point_on_line;} // p = (px, py) + Geom::Coord getConstTerm() const {return dot(_normal_to_line, _point_on_line);} // c = n.p = nx*px + ny*py; private: - NR::Point _normal_to_line; - NR::Point _point_on_line; + Geom::Point _normal_to_line; + Geom::Point _point_on_line; }; } diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp index 02f7ed165..3a3595a80 100644 --- a/src/snapped-point.cpp +++ b/src/snapped-point.cpp @@ -12,26 +12,26 @@ #include "snapped-point.h" // overloaded constructor -Inkscape::SnappedPoint::SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a) +Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a) : _point(p), _target(target), _distance(d), _tolerance(t), _always_snap(a) { _at_intersection = false; _second_distance = NR_HUGE; _second_tolerance = 0; _second_always_snap = false; - _transformation = NR::Point(1,1); + _transformation = Geom::Point(1,1); } -Inkscape::SnappedPoint::SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a, bool const &at_intersection, NR::Coord const &d2, NR::Coord const &t2, bool const &a2) +Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2) : _point(p), _target(target), _at_intersection(at_intersection), _distance(d), _tolerance(t), _always_snap(a), _second_distance(d2), _second_tolerance(t2), _second_always_snap(a2) { - _transformation = NR::Point(1,1); + _transformation = Geom::Point(1,1); } Inkscape::SnappedPoint::SnappedPoint() { - _point = NR::Point(0,0); + _point = Geom::Point(0,0); _target = SNAPTARGET_UNDEFINED, _distance = NR_HUGE; _tolerance = 0; @@ -40,7 +40,7 @@ Inkscape::SnappedPoint::SnappedPoint() _second_distance = NR_HUGE; _second_tolerance = 0; _second_always_snap = false; - _transformation = NR::Point(1,1); + _transformation = Geom::Point(1,1); } @@ -49,12 +49,12 @@ Inkscape::SnappedPoint::~SnappedPoint() { } -NR::Coord Inkscape::SnappedPoint::getDistance() const +Geom::Coord Inkscape::SnappedPoint::getDistance() const { return _distance; } -NR::Coord Inkscape::SnappedPoint::getTolerance() const +Geom::Coord Inkscape::SnappedPoint::getTolerance() const { return _tolerance; } @@ -64,12 +64,12 @@ bool Inkscape::SnappedPoint::getAlwaysSnap() const return _always_snap; } -NR::Coord Inkscape::SnappedPoint::getSecondDistance() const +Geom::Coord Inkscape::SnappedPoint::getSecondDistance() const { return _second_distance; } -NR::Coord Inkscape::SnappedPoint::getSecondTolerance() const +Geom::Coord Inkscape::SnappedPoint::getSecondTolerance() const { return _second_tolerance; } @@ -80,7 +80,7 @@ bool Inkscape::SnappedPoint::getSecondAlwaysSnap() const } -void Inkscape::SnappedPoint::getPoint(NR::Point &p) const +void Inkscape::SnappedPoint::getPoint(Geom::Point &p) const { // When we have snapped if (getSnapped()) { diff --git a/src/snapped-point.h b/src/snapped-point.h index 2c74025c8..4999a2aae 100644 --- a/src/snapped-point.h +++ b/src/snapped-point.h @@ -42,23 +42,23 @@ class SnappedPoint public: SnappedPoint(); - SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a, bool const &at_intersection, NR::Coord const &d2, NR::Coord const &t2, bool const &a2); - SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a); + SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2); + SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a); ~SnappedPoint(); - NR::Coord getDistance() const; - void setDistance(NR::Coord const d) {_distance = d;} - NR::Coord getTolerance() const; + Geom::Coord getDistance() const; + void setDistance(Geom::Coord const d) {_distance = d;} + Geom::Coord getTolerance() const; bool getAlwaysSnap() const; - NR::Coord getSecondDistance() const; - NR::Coord getSecondTolerance() const; + Geom::Coord getSecondDistance() const; + Geom::Coord getSecondTolerance() const; bool getSecondAlwaysSnap() const; /* This is the preferred method to find out which point we have snapped, * to because it only returns a point if snapping has actually occured * (by overwriting p) */ - void getPoint(NR::Point &p) const; + void getPoint(Geom::Point &p) const; /* This method however always returns a point, even if no snapping * has occured; A check should be implemented in the calling code @@ -66,38 +66,38 @@ public: * when the calling code is trying to snap multiple points and must * determine itself which point is most appropriate */ - NR::Point getPoint() const {return _point;} + Geom::Point getPoint() const {return _point;} bool getAtIntersection() const {return _at_intersection;} bool getSnapped() const {return _distance < NR_HUGE;} - NR::Point getTransformation() const {return _transformation;} - void setTransformation(NR::Point const t) {_transformation = t;} + Geom::Point getTransformation() const {return _transformation;} + void setTransformation(Geom::Point const t) {_transformation = t;} void setTarget(SnapTargetType const target) {_target = target;} SnapTargetType getTarget() {return _target;} protected: - NR::Point _point; // Location of the snapped point + Geom::Point _point; // Location of the snapped point SnapTargetType _target; // Describes to what we've snapped to bool _at_intersection; // If true, the snapped point is at an intersection /* Distance from original point to snapped point. If the snapped point is at an intersection of e.g. two lines, then this is the distance to the closest line */ - NR::Coord _distance; + Geom::Coord _distance; /* The snapping tolerance in screen pixels (depends on zoom)*/ - NR::Coord _tolerance; + Geom::Coord _tolerance; /* If true then "Always snap" is on */ bool _always_snap; /* If the snapped point is at an intersection of e.g. two lines, then this is the distance to the fartest line */ - NR::Coord _second_distance; + Geom::Coord _second_distance; /* The snapping tolerance in screen pixels (depends on zoom)*/ - NR::Coord _second_tolerance; + Geom::Coord _second_tolerance; /* If true then "Always snap" is on */ bool _second_always_snap; /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */ - NR::Point _transformation; + Geom::Point _transformation; }; } diff --git a/src/snapper.cpp b/src/snapper.cpp index 4dfb9042e..35aa012dc 100644 --- a/src/snapper.cpp +++ b/src/snapper.cpp @@ -23,7 +23,7 @@ Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_GUIDE = 0x4; * \param nv Named view. * \param d Snap tolerance. */ -Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const t) : _named_view(nv), _snap_enabled(true), _snapper_tolerance(t) +Inkscape::Snapper::Snapper(SPNamedView const *nv, Geom::Coord const t) : _named_view(nv), _snap_enabled(true), _snapper_tolerance(t) { g_assert(_named_view != NULL); g_assert(SP_IS_NAMEDVIEW(_named_view)); @@ -35,7 +35,7 @@ Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const t) : _named_vi * Set snap tolerance. * \param d New snap tolerance (desktop coordinates) */ -void Inkscape::Snapper::setSnapperTolerance(NR::Coord const d) +void Inkscape::Snapper::setSnapperTolerance(Geom::Coord const d) { _snapper_tolerance = d; } @@ -43,7 +43,7 @@ void Inkscape::Snapper::setSnapperTolerance(NR::Coord const d) /** * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels */ -NR::Coord Inkscape::Snapper::getSnapperTolerance() const +Geom::Coord Inkscape::Snapper::getSnapperTolerance() const { return _snapper_tolerance / SP_ACTIVE_DESKTOP->current_zoom(); } diff --git a/src/snapper.h b/src/snapper.h index a63ea14c5..18967ebd9 100644 --- a/src/snapper.h +++ b/src/snapper.h @@ -41,7 +41,7 @@ class Snapper { public: Snapper() {} - Snapper(SPNamedView const *nv, ::NR::Coord const d); + Snapper(SPNamedView const *nv, ::Geom::Coord const d); virtual ~Snapper() {} /// Point types to snap. @@ -53,8 +53,8 @@ public: void setSnapFrom(PointType t, bool s); bool getSnapFrom(PointType t) const; - void setSnapperTolerance(NR::Coord t); - NR::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) + void setSnapperTolerance(Geom::Coord t); + Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance /** @@ -67,31 +67,31 @@ public: virtual void freeSnap(SnappedConstraints &/*sc*/, PointType const &/*t*/, - NR::Point const &/*p*/, + Geom::Point const &/*p*/, bool const &/*first_point*/, - boost::optional const &/*bbox_to_snap*/, + boost::optional const &/*bbox_to_snap*/, std::vector const */*it*/, - std::vector */*unselected_nodes*/) const {}; + std::vector */*unselected_nodes*/) const {}; class ConstraintLine { public: - ConstraintLine(NR::Point const &d) : _has_point(false), _direction(d) {} - ConstraintLine(NR::Point const &p, NR::Point const &d) : _has_point(true), _point(p), _direction(d) {} + ConstraintLine(Geom::Point const &d) : _has_point(false), _direction(d) {} + ConstraintLine(Geom::Point const &p, Geom::Point const &d) : _has_point(true), _point(p), _direction(d) {} bool hasPoint() const { return _has_point; } - NR::Point getPoint() const { + Geom::Point getPoint() const { return _point; } - NR::Point getDirection() const { + Geom::Point getDirection() const { return _direction; } - void setPoint(NR::Point const &p) { + void setPoint(Geom::Point const &p) { _point = p; _has_point = true; } @@ -99,15 +99,15 @@ public: private: bool _has_point; - NR::Point _point; - NR::Point _direction; + Geom::Point _point; + Geom::Point _direction; }; virtual void constrainedSnap(SnappedConstraints &/*sc*/, PointType const &/*t*/, - NR::Point const &/*p*/, + Geom::Point const &/*p*/, bool const &/*first_point*/, - boost::optional const &/*bbox_to_snap*/, + boost::optional const &/*bbox_to_snap*/, ConstraintLine const &/*c*/, std::vector const */*it*/) const {}; @@ -117,7 +117,7 @@ protected: bool _snap_enabled; ///< true if this snapper is enabled, otherwise false private: - NR::Coord _snapper_tolerance; ///< snap tolerance in desktop coordinates + Geom::Coord _snapper_tolerance; ///< snap tolerance in desktop coordinates // must be private to enforce the usage of getTolerance(), which retrieves // the tolerance in screen pixels (making it zoom independent) diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 3e431667f..b42195c60 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -267,7 +267,9 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, NULL); //null, because we don't have an item yet - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, sc->center); + Geom::Point pt2g = to_2geom(sc->center); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); + sc->center = from_2geom(pt2g); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | @@ -293,12 +295,12 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) event_context->within_tolerance = false; NR::Point const motion_w(event->motion.x, event->motion.y); - NR::Point motion_dt(event_context->desktop->w2d(motion_w)); + Geom::Point motion_dt(to_2geom(event_context->desktop->w2d(motion_w))); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, sc->item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt); - sp_spiral_drag(sc, motion_dt, event->motion.state); + sp_spiral_drag(sc, from_2geom(motion_dt), event->motion.state); gobble_motion_events(GDK_BUTTON1_MASK); @@ -437,16 +439,16 @@ sp_spiral_drag(SPSpiralContext *sc, NR::Point p, guint state) sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5); } - NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center); - NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p); + Geom::Point const p0 = to_2geom(sp_desktop_dt2root_xy_point(desktop, sc->center)); + Geom::Point p1 = to_2geom(sp_desktop_dt2root_xy_point(desktop, p)); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, sc->item); m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p1); SPSpiral *spiral = SP_SPIRAL(sc->item); - NR::Point const delta = p1 - p0; - gdouble const rad = NR::L2(delta); + Geom::Point const delta = p1 - p0; + gdouble const rad = Geom::L2(delta); gdouble arg = NR::atan2(delta) - 2.0*M_PI*spiral->revo; @@ -455,7 +457,7 @@ sp_spiral_drag(SPSpiralContext *sc, NR::Point p, guint state) } /* Fixme: these parameters should be got from dialog box */ - sp_spiral_position_set(spiral, p0[NR::X], p0[NR::Y], + sp_spiral_position_set(spiral, p0[Geom::X], p0[Geom::Y], /*expansion*/ sc->exp, /*revolution*/ sc->revo, rad, arg, diff --git a/src/star-context.cpp b/src/star-context.cpp index 2d4d7b415..824fd53a4 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -283,7 +283,9 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, NULL); //null, because we don't have an item yet - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, sc->center); + Geom::Point pt2g = to_2geom(sc->center); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); + sc->center = from_2geom(pt2g); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | @@ -451,24 +453,25 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state) /* Snap corner point with no constraints */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, sc->item); - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p); + Geom::Point pt2g = to_2geom(p); + m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); - NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center); - NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p); + Geom::Point const p0 = to_2geom(sp_desktop_dt2root_xy_point(desktop, sc->center)); + Geom::Point const p1 = to_2geom(sp_desktop_dt2root_xy_point(desktop, from_2geom(pt2g))); SPStar *star = SP_STAR(sc->item); double const sides = (gdouble) sc->magnitude; - NR::Point const d = p1 - p0; - NR::Coord const r1 = NR::L2(d); - double arg1 = atan2(d); + Geom::Point const d = p1 - p0; + Geom::Coord const r1 = Geom::L2(d); + double arg1 = atan2(from_2geom(d)); if (state & GDK_CONTROL_MASK) { /* Snap angle */ arg1 = sp_round(arg1, M_PI / snaps); } - sp_star_position_set(star, sc->magnitude, p0, r1, r1 * sc->proportion, + sp_star_position_set(star, sc->magnitude, from_2geom(p0), r1, r1 * sc->proportion, arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized); /* status text */ -- 2.30.2