Code

guides: switch from using one position coordinate to Geom::Point point_on_line
authorjohanengelen <johanengelen@users.sourceforge.net>
Wed, 19 Dec 2007 22:42:06 +0000 (22:42 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Wed, 19 Dec 2007 22:42:06 +0000 (22:42 +0000)
12 files changed:
src/desktop-events.cpp
src/dialogs/guidelinedialog.cpp
src/display/guideline.cpp
src/display/guideline.h
src/guide-snapper.cpp
src/satisfied-guide-cns.cpp
src/sp-guide.cpp
src/sp-guide.h
src/sp-item-rm-unsatisfied-cns.cpp
src/ui/widget/ruler.cpp
src/xml/repr-util.cpp
src/xml/repr.h

index fec316bd3687706a6e5ace002c4fd12563fc4d6b..f0561202d191fad31c1d39636d523fdcb021570c 100644 (file)
@@ -63,10 +63,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
                 sp_repr_set_boolean(repr, "showguides", TRUE);
                 sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE);
 
-                double const guide_pos_dt = event_dt[ horiz
-                                                      ? NR::Y
-                                                      : NR::X ];
-                guide = sp_guideline_new(desktop->guides, guide_pos_dt, horiz ? Geom::Point(0.,1.) : Geom::Point(1.,0.));
+                guide = sp_guideline_new(desktop->guides, event_dt.to_2geom(), horiz ? Geom::Point(0.,1.) : Geom::Point(1.,0.));
                 sp_guideline_set_color(SP_GUIDELINE(guide), desktop->namedview->guidehicolor);
                 gdk_pointer_grab(widget->window, FALSE,
                                  (GdkEventMask)(GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ),
@@ -82,11 +79,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
                 SnapManager const &m = desktop->namedview->snap_manager;
                 event_dt = m.guideSnap(event_dt, component_vectors[horiz ? NR::Y : NR::X]).getPoint();
                 
-                double const guide_pos_dt = event_dt[ horiz
-                                                      ? NR::Y
-                                                      : NR::X ];
-                
-                sp_guideline_set_position(SP_GUIDELINE(guide), guide_pos_dt);
+                sp_guideline_set_position(SP_GUIDELINE(guide), event_dt.to_2geom());
                 desktop->set_coordinate_status(event_dt);
                 desktop->setPosition (event_dt);
             }
@@ -107,10 +100,7 @@ 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");
                     repr->setAttribute("orientation", (horiz) ? "horizontal" : "vertical");
-                    double const guide_pos_dt = event_dt[ horiz
-                                                          ? NR::Y
-                                                          : NR::X ];
-                    sp_repr_set_svg_double(repr, "position", guide_pos_dt);
+                    sp_repr_set_svg_point(repr, "position", event_dt.to_2geom());
                     SP_OBJECT_REPR(desktop->namedview)->appendChild(repr);
                     Inkscape::GC::release(repr);
                     sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, 
@@ -167,7 +157,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                 ret = TRUE;
             }
             break;
-       case GDK_MOTION_NOTIFY:
+    case GDK_MOTION_NOTIFY:
             if (dragging) {
                 NR::Point const motion_w(event->motion.x,
                                          event->motion.y);
@@ -185,23 +175,23 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                 ret = TRUE;
             }
             break;
-       case GDK_BUTTON_RELEASE:
+    case GDK_BUTTON_RELEASE:
             if (dragging && event->button.button == 1) {
                 if (moved) {
                     NR::Point const event_w(event->button.x,
                                             event->button.y);
                     NR::Point event_dt(desktop->w2d(event_w));
-                    
+
                     SnapManager const &m = desktop->namedview->snap_manager;
-                       event_dt = m.guideSnap(event_dt, guide->normal_to_line).getPoint();
-                
+                    event_dt = m.guideSnap(event_dt, guide->normal_to_line).getPoint();
+
                     if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {
                         sp_guide_moveto(*guide, sp_guide_position_from_pt(guide, event_dt), true);
                         sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE,
                                      _("Move guide"));
                     } else {
                         /* Undo movement of any attached shapes. */
-                        sp_guide_moveto(*guide, guide->position, false);
+                        sp_guide_moveto(*guide, guide->point_on_line, false);
                         sp_guide_remove(guide);
                         sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE,
                                      _("Delete guide"));
@@ -214,25 +204,20 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                 sp_canvas_item_ungrab(item, event->button.time);
                 ret=TRUE;
             }
-       case GDK_ENTER_NOTIFY:
-       {
-
+    case GDK_ENTER_NOTIFY:
+    {
             sp_guideline_set_color(SP_GUIDELINE(item), guide->hicolor);
 
-            GString *position_string = SP_PX_TO_METRIC_STRING(guide->position, desktop->namedview->getDefaultMetric());
             char *guide_description = sp_guide_description(guide);
-
-            desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, _("%s at %s"), guide_description, position_string->str);
-
+            desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, "%s", guide_description);
             g_free(guide_description);
-            g_string_free(position_string, TRUE);
             break;
-       }
-       case GDK_LEAVE_NOTIFY:
+    }
+    case GDK_LEAVE_NOTIFY:
             sp_guideline_set_color(SP_GUIDELINE(item), guide->color);
             desktop->guidesMessageContext()->clear();
             break;
-       default:
+    default:
             break;
     }
 
index aef0cc473d98d08836e72817c35f8e90e9b8599b..d0cdfdd2ab344de1c652e8a61bccb25b12414893 100644 (file)
@@ -69,10 +69,13 @@ void GuidelinePropertiesDialog::_onApply()
     gdouble const raw_dist = _spin_button.get_value();
     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector->gobj()));
     gdouble const points = sp_units_get_pixels(raw_dist, unit);
-    gdouble const newpos = ( _mode
-                             ? points
-                             : _guide->position + points );
-    sp_guide_moveto(*_guide, newpos, true);
+    if (_guide->normal_to_line[Geom::Y] == 1.) {
+        gdouble const newpos = ( _mode ? points : _guide->point_on_line[Geom::Y] + points );
+        sp_guide_moveto(*_guide, Geom::Point(0, newpos), true);
+    } else {
+        gdouble const newpos = ( _mode ? points : _guide->point_on_line[Geom::Y] + points );
+        sp_guide_moveto(*_guide, Geom::Point(newpos, 0), true);
+    }
     sp_document_done(SP_OBJECT_DOCUMENT(_guide), SP_VERB_NONE, 
                      _("Set guide properties"));
 }
@@ -169,7 +172,11 @@ void GuidelinePropertiesDialog::_setup() {
     signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response));
 
     // initialize dialog
-    _oldpos = _guide->position;
+    if (_guide->normal_to_line[Geom::Y] == 0.) {
+        _oldpos = _guide->point_on_line[Geom::X];
+    } else {
+        _oldpos = _guide->point_on_line[Geom::Y];
+    }
     {
         gchar *guide_description = sp_guide_description(_guide);
         Inkscape::XML::Node *repr = SP_OBJECT_REPR (_guide);
index 154b7c3b8aea59f34781c421644593018e2f5ac7..fcddbb0e6e5fd86e4f25abc8ee16fc99e7060634 100644 (file)
@@ -69,7 +69,8 @@ static void sp_guideline_init(SPGuideLine *gl)
 {
     gl->rgba = 0x0000ff7f;
 
-    gl->normal = Geom::Point(0,1);
+    gl->normal_to_line = Geom::Point(0,1);
+    gl->point_on_line = Geom::Point(0,0);
     gl->sensitive = 0;
 }
 
@@ -89,15 +90,16 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
     unsigned int const b = NR_RGBA32_B (gl->rgba);
     unsigned int const a = NR_RGBA32_A (gl->rgba);
 
-    if (gl->normal[Geom::Y] == 0.) {
-        if (gl->position < buf->rect.x0 || gl->position >= buf->rect.x1) {
+    if (gl->normal_to_line[Geom::Y] == 0.) {
+        int position = gl->point_on_line[Geom::X];
+        if (position < buf->rect.x0 || position >= buf->rect.x1) {
             return;
         }
 
         int p0 = buf->rect.y0;
         int p1 = buf->rect.y1;
         int step = buf->buf_rowstride;
-        unsigned char *d = buf->buf + 3 * (gl->position - buf->rect.x0);
+        unsigned char *d = buf->buf + 3 * (position - buf->rect.x0);
 
         for (int p = p0; p < p1; p++) {
             d[0] = NR_COMPOSEN11_1111(r, a, d[0]);
@@ -105,15 +107,16 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
             d[2] = NR_COMPOSEN11_1111(b, a, d[2]);
             d += step;
         }
-    } else if (gl->normal[Geom::X] == 0.) {
-        if (gl->position < buf->rect.y0 || gl->position >= buf->rect.y1) {
+    } else if (gl->normal_to_line[Geom::X] == 0.) {
+        int position = gl->point_on_line[Geom::Y];
+        if (position < buf->rect.y0 || position >= buf->rect.y1) {
             return;
         }
 
         int p0 = buf->rect.x0;
         int p1 = buf->rect.x1;
         int step = 3;
-        unsigned char *d = buf->buf + (gl->position - buf->rect.y0) * buf->buf_rowstride;
+        unsigned char *d = buf->buf + (position - buf->rect.y0) * buf->buf_rowstride;
 
         for (int p = p0; p < p1; p++) {
             d[0] = NR_COMPOSEN11_1111(r, a, d[0]);
@@ -134,15 +137,17 @@ static void sp_guideline_update(SPCanvasItem *item, NR::Matrix const &affine, un
         ((SPCanvasItemClass *) parent_class)->update(item, affine, flags);
     }
 
-    if (gl->normal[Geom::Y] == 0.) {
-        gl->position = (int) (affine[4] + 0.5);
-        sp_canvas_update_bbox (item, gl->position, -1000000, gl->position + 1, 1000000);
+    gl->point_on_line[Geom::X] = affine[4];
+    gl->point_on_line[Geom::Y] = affine[5];
+
+    if (gl->normal_to_line[Geom::Y] == 1.) {
+        sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000);
     } else {
-        gl->position = (int) (affine[5] - 0.5);
-        sp_canvas_update_bbox (item, -1000000, gl->position, 1000000, gl->position + 1);
+        sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000);
     }
 }
 
+// Returns 0.0 if point is on the guideline
 static double sp_guideline_point(SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item)
 {
     SPGuideLine *gl = SP_GUIDELINE (item);
@@ -153,30 +158,27 @@ static double sp_guideline_point(SPCanvasItem *item, NR::Point p, SPCanvasItem *
 
     *actual_item = item;
 
-    if (gl->normal[Geom::Y] == 0.) {
-        return MAX(fabs(gl->position - p[NR::X])-1, 0);
-    } else {
-        return MAX(fabs(gl->position - p[NR::Y])-1, 0);
-    }
+    double distance = Geom::dot((p.to_2geom() - gl->point_on_line), gl->normal_to_line);
+    return MAX(fabs(distance)-1, 0);
 }
 
-SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, Geom::Point normal)
+SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal)
 {
     SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL);
 
     SPGuideLine *gl = SP_GUIDELINE(item);
 
     normal.normalize();
-    gl->normal = normal;
-    sp_guideline_set_position(gl, position);
+    gl->normal_to_line = normal;
+    sp_guideline_set_position(gl, point_on_line);
 
     return item;
 }
 
-void sp_guideline_set_position(SPGuideLine *gl, double position)
+void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line)
 {
     sp_canvas_item_affine_absolute(SP_CANVAS_ITEM (gl),
-                                   NR::Matrix(NR::translate(position, position)));
+                                   NR::Matrix(NR::translate(point_on_line)));
 }
 
 void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba)
index a9bfc809bf96c1432dba5dd678a2b8aaceda80e7..b3d9bb56b4bf616d0431f382e692c7270f70000a 100644 (file)
@@ -26,8 +26,8 @@ struct SPGuideLine {
 
     guint32 rgba;
 
-    int position;
-    Geom::Point normal;
+    Geom::Point normal_to_line;
+    Geom::Point point_on_line;
 
     unsigned int sensitive : 1;
 };
@@ -38,9 +38,9 @@ struct SPGuideLineClass {
 
 GType sp_guideline_get_type();
 
-SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, Geom::Point normal);
+SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal);
 
-void sp_guideline_set_position(SPGuideLine *gl, double position);
+void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line);
 void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba);
 void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive);
 
index 1e78f609aae0a39934ae578823cb6f44ebe04a00..fb16382d26eddc2862e6171be9d895e286991065 100644 (file)
@@ -32,8 +32,7 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point
 
     for (GSList const *l = _named_view->guides; l != NULL; l = l->next) {
         SPGuide const *g = SP_GUIDE(l->data);
-        NR::Point point_on_line = (g->normal_to_line == component_vectors[NR::X]) ? NR::Point(g->position, 0) : NR::Point(0, g->position);
-        s.push_back(std::make_pair(g->normal_to_line, point_on_line)); 
+        s.push_back(std::make_pair(g->normal_to_line, g->point_on_line)); 
     }
 
     return s;
index ece5118c58297175e3f0dcb25a9b078619b728be..11293092561ddd6f39d520402e2c754605fb5fdc 100644 (file)
@@ -13,7 +13,7 @@ void satisfied_guide_cns(SPDesktop const &desktop,
     for (GSList const *l = nv.guides; l != NULL; l = l->next) {
         SPGuide &g = *SP_GUIDE(l->data);
         for (unsigned int i = 0; i < snappoints.size(); ++i) {
-            if (approx_equal(dot(g.normal_to_line, snappoints[i]), g.position)) {
+            if (approx_equal( sp_guide_distance_from_pt(&g, snappoints[i].to_2geom()), 0) ) {
                 cns.push_back(SPGuideConstraint(&g, i));
             }
         }
index ff16c53819af43c25399f516183531ea486e333b..94f937ff95c304fe9c8f6b2335885abc5e12f7d9 100644 (file)
@@ -20,6 +20,7 @@
 #endif
 #include "display/guideline.h"
 #include "svg/svg.h"
+#include "svg/stringstream.h"
 #include "attributes.h"
 #include "sp-guide.h"
 #include <sp-item-notify-moveto.h>
 #include <glibmm/i18n.h>
 #include <xml/repr.h>
 #include <remove-last.h>
+#include "sp-metrics.h"
+#include "inkscape.h"
+#include "desktop.h"
+#include "sp-namedview.h"
+
 using std::vector;
 
 enum {
@@ -102,9 +108,7 @@ static void sp_guide_class_init(SPGuideClass *gc)
 static void sp_guide_init(SPGuide *guide)
 {
     guide->normal_to_line = component_vectors[NR::Y];
-    /* constrain y coordinate; horizontal line.  I doubt it ever matters what we initialize
-       this to. */
-    guide->position = 0.0;
+    guide->point_on_line = Geom::Point(0.,0.);
     guide->color = 0x0000ff7f;
     guide->hicolor = 0xff00007f;
 }
@@ -215,11 +219,10 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
                     guide->point_on_line = Geom::Point(newx, 0);
                 }
             }
-            sp_svg_number_read_d(value, &guide->position);
 
             // update position in non-committing way
             // fixme: perhaps we need to add an update method instead, and request_update here
-            sp_guide_moveto(*guide, guide->position, false);
+            sp_guide_moveto(*guide, guide->point_on_line, false);
         }
         break;
     default:
@@ -232,10 +235,7 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
 
 void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler)
 {
-    bool const vertical_line_p = ( guide->normal_to_line == component_vectors[NR::X] );
-    g_assert(( guide->normal_to_line == component_vectors[NR::X] )  ||
-             ( guide->normal_to_line == component_vectors[NR::Y] ) );
-    SPCanvasItem *item = sp_guideline_new(group, guide->position, vertical_line_p ? Geom::Point(1.,0.) : Geom::Point(0.,1.));
+    SPCanvasItem *item = sp_guideline_new(group, guide->point_on_line, guide->normal_to_line.to_2geom());
     sp_guideline_set_color(SP_GUIDELINE(item), guide->color);
 
     g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), guide);
@@ -278,32 +278,36 @@ void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive)
     g_assert_not_reached();
 }
 
-double sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt)
+Geom::Point sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt)
+{
+    return -(pt.to_2geom() - guide->point_on_line);
+}
+
+double sp_guide_distance_from_pt(SPGuide const *guide, Geom::Point const &pt)
 {
-    return dot(guide->normal_to_line, pt);
+    return dot(pt - guide->point_on_line, guide->normal_to_line);
 }
 
 /**
  * \arg commit False indicates temporary moveto in response to motion event while dragging,
- *             true indicates a "committing" version: in response to button release event after
- *             dragging a guideline, or clicking OK in guide editing dialog.
+ *      true indicates a "committing" version: in response to button release event after
+ *      dragging a guideline, or clicking OK in guide editing dialog.
  */
-void sp_guide_moveto(SPGuide const &guide, gdouble const position, bool const commit)
+void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool const commit)
 {
     g_assert(SP_IS_GUIDE(&guide));
 
     for (GSList *l = guide.views; l != NULL; l = l->next) {
-        sp_guideline_set_position(SP_GUIDELINE(l->data),
-                                  position);
+        sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line);
     }
 
     /* Calling sp_repr_set_svg_double must precede calling sp_item_notify_moveto in the commit
        case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
     if (commit) {
-        sp_repr_set_svg_double(SP_OBJECT(&guide)->repr,
-                           "position", position);
+        sp_repr_set_svg_point(SP_OBJECT(&guide)->repr, "position", point_on_line);
     }
 
+/*  DISABLED CODE BECAUSE  SPGuideAttachment  IS NOT USE AT THE MOMENT (johan)
     for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()),
              iEnd(guide.attached_items.end());
          i != iEnd; ++i)
@@ -311,6 +315,7 @@ void sp_guide_moveto(SPGuide const &guide, gdouble const position, bool const co
         SPGuideAttachment const &att = *i;
         sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit);
     }
+*/
 }
 
 /**
@@ -322,20 +327,26 @@ char *sp_guide_description(SPGuide const *guide)
 {
     using NR::X;
     using NR::Y;
+            
+    GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], SP_ACTIVE_DESKTOP->namedview->getDefaultMetric());
+    GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], SP_ACTIVE_DESKTOP->namedview->getDefaultMetric());
 
     if ( guide->normal_to_line == component_vectors[X] ) {
-        return g_strdup(_("vertical guideline"));
+        return g_strdup_printf(_("vertical guideline at %s"), position_string_x->str);
     } else if ( guide->normal_to_line == component_vectors[Y] ) {
-        return g_strdup(_("horizontal guideline"));
+        return g_strdup_printf(_("horizontal guideline at %s"), position_string_y->str);
     } else {
         double const radians = atan2(guide->normal_to_line[X],
                                      guide->normal_to_line[Y]);
         /* flip y axis and rotate 90 degrees to convert to line angle */
         double const degrees = ( radians / M_PI ) * 180.0;
         int const degrees_int = (int) floor( degrees + .5 );
-        return g_strdup_printf("%d degree guideline", degrees_int);
+        return g_strdup_printf("%d degree guideline at (%s,%s)", degrees_int, position_string_x->str, position_string_y->str);
         /* Alternative suggestion: "angled guideline". */
     }
+
+    g_string_free(position_string_x, TRUE);
+    g_string_free(position_string_y, TRUE);
 }
 
 void sp_guide_remove(SPGuide *guide)
index aa34649184948e93e11281c0ea8514d7f3d40966..48583bbe60411d2d6aed13eac6e011e282c6cf87 100644 (file)
@@ -28,7 +28,7 @@
 struct SPGuide : public SPObject {
     NR::Point normal_to_line;
     Geom::Point point_on_line;
-    gdouble position;
+
     guint32 color;
     guint32 hicolor;
     GSList *views;
@@ -45,8 +45,9 @@ void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler);
 void sp_guide_hide(SPGuide *guide, SPCanvas *canvas);
 void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive);
 
-double sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt);
-void sp_guide_moveto(SPGuide const &guide, gdouble const position, bool const commit);
+Geom::Point sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt);
+double sp_guide_distance_from_pt(SPGuide const *guide, Geom::Point const &pt);
+void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool const commit);
 void sp_guide_remove(SPGuide *guide);
 
 char *sp_guide_description(SPGuide const *guide);
index 1f6a9ebe787a42e675bd53c78218c910e6107d69..7f3f06975ac818308d15513b26218b21c258b229 100644 (file)
@@ -18,7 +18,7 @@ void sp_item_rm_unsatisfied_cns(SPItem &item)
         SPGuideConstraint const &cn = item.constraints[i];
         int const snappoint_ix = cn.snappoint_ix;
         g_assert( snappoint_ix < int(snappoints.size()) );
-        if (!approx_equal(dot(cn.g->normal_to_line, snappoints[snappoint_ix]), cn.g->position)) {
+        if (!approx_equal( sp_guide_distance_from_pt(cn.g, snappoints[snappoint_ix].to_2geom()), 0) ) {
             remove_last(cn.g->attached_items, SPGuideAttachment(&item, cn.snappoint_ix));
             g_assert( i < item.constraints.size() );
             vector<SPGuideConstraint>::iterator const ei(&item.constraints[i]);
index 6a6bd826498349957842e9a595f81c111eda81b9..27c991446b7239718462e3dabc3700416bbee22d 100644 (file)
@@ -105,8 +105,7 @@ Ruler::on_button_press_event(GdkEventButton *evb)
         _dragging = true;
         sp_repr_set_boolean(repr, "showguides", TRUE);
         sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE);
-        double const guide_pos_dt = event_dt[ _horiz_f ? NR::Y : NR::X ];
-        _guide = sp_guideline_new(_dt->guides, guide_pos_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.));
+        _guide = sp_guideline_new(_dt->guides, event_dt.to_2geom(), _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.));
         sp_guideline_set_color(SP_GUIDELINE(_guide), _dt->namedview->guidehicolor);
         (void) get_window()->pointer_grab(false,
                         Gdk::BUTTON_RELEASE_MASK |
@@ -124,8 +123,7 @@ Ruler::on_motion_notify_event(GdkEventMotion *)
     NR::Point const &event_dt = get_event_dt();
 
     if (_dragging) {
-        double const guide_pos_dt = event_dt[ _horiz_f ? NR::Y : NR::X ];
-        sp_guideline_set_position(SP_GUIDELINE(_guide), guide_pos_dt);
+        sp_guideline_set_position(SP_GUIDELINE(_guide), event_dt.to_2geom());
         _dt->set_coordinate_status(event_dt);
         _dt->setPosition(event_dt);
     }
index 693558cf766ee07f19fcae63c89e5f5bd2f4cc5c..560a700041b4f4dd6d27b921fb7384e39852938a 100644 (file)
@@ -576,6 +576,17 @@ sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val)
     return true;
 }
 
+unsigned sp_repr_set_svg_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val)
+{
+    g_return_val_if_fail(repr != NULL, FALSE);
+    g_return_val_if_fail(key != NULL, FALSE);
+
+    Inkscape::SVGOStringStream os;
+    os << val[Geom::X] << "," << val[Geom::Y];
+
+    repr->setAttribute(key, os.str().c_str());
+    return true;
+}
 
 /*
   Local Variables:
index 497cda119778a5846613cc6ba559fd02435e352d..2b5f4ad1e8c1a438301f57e0e75eb228034301a0 100644 (file)
@@ -21,6 +21,8 @@
 #include "xml/document.h"
 #include "xml/sp-css-attr.h"
 
+#include <2geom/point.h>
+
 #define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
 #define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
 #define SP_INKSCAPE_NS_URI "http://www.inkscape.org/namespaces/inkscape"
  * Kees Cook  2004-07-01, updated MenTaLguY 2005-01-25
  */
 
+namespace Geom {
+class Point;
+}
+
 /* SPXMLNs */
 char const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested);
 char const *sp_xml_ns_prefix_uri(gchar const *prefix);
@@ -215,6 +221,7 @@ unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, gchar const *key, unsign
 unsigned sp_repr_set_int(Inkscape::XML::Node *repr, gchar const *key, int val);
 unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, gchar const *key, double val);
 unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val);
+unsigned sp_repr_set_svg_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val);
 
 /// \deprecated !
 double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, double def);