From 4b34a53a8122919e53ce2e13627e2007fafec0db Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Fri, 23 Jan 2015 15:39:50 -0500 Subject: improved precision in placing grids and guides. (Bug 1373311) Fixed bugs: - https://launchpad.net/bugs/1373311 (bzr r13868) --- src/sp-guide.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 3eecb2783..890c1f597 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -198,8 +198,15 @@ SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::P SPRoot *root = doc->getRoot(); if( root->viewBox_set ) { - newx = newx * root->viewBox.width() / root->width.computed; - newy = newy * root->viewBox.height() / root->height.computed; + // check to see if scaling is uniform + if(Geom::are_near((root->viewBox.width() * root->height.computed) / (root->width.computed * root->viewBox.height()), 1.0, Geom::EPSILON)) { + double px2vbunit = (root->viewBox.width()/root->width.computed + root->viewBox.height()/root->height.computed)/2.0; + newx = newx * px2vbunit; + newy = newy * px2vbunit; + } else { + newx = newx * root->viewBox.width() / root->width.computed; + newy = newy * root->viewBox.height() / root->height.computed; + } } sp_repr_set_point(repr, "position", Geom::Point( newx, newy )); @@ -341,8 +348,15 @@ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit) SPRoot *root = document->getRoot(); if( root->viewBox_set ) { - newx = newx * root->viewBox.width() / root->width.computed; - newy = newy * root->viewBox.height() / root->height.computed; + // check to see if scaling is uniform + if(Geom::are_near((root->viewBox.width() * root->height.computed) / (root->width.computed * root->viewBox.height()), 1.0, Geom::EPSILON)) { + double px2vbunit = (root->viewBox.width()/root->width.computed + root->viewBox.height()/root->height.computed)/2.0; + newx = newx * px2vbunit; + newy = newy * px2vbunit; + } else { + newx = newx * root->viewBox.width() / root->width.computed; + newy = newy * root->viewBox.height() / root->height.computed; + } } //XML Tree being used here directly while it shouldn't be. -- cgit v1.2.3 From a8ef610e1960c0e0d61f417471e8d2c32b51db9a Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Wed, 28 Jan 2015 19:03:12 -0500 Subject: for snapping to grids and guides, reduce numerical error for the case of uniform scaling of viewbox (bzr r13881) --- src/sp-guide.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 890c1f597..08b055508 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -156,8 +156,15 @@ void SPGuide::set(unsigned int key, const gchar *value) { // If root viewBox set, interpret guides in terms of viewBox (90/96) SPRoot *root = document->getRoot(); if( root->viewBox_set ) { - newx = newx * root->width.computed / root->viewBox.width(); - newy = newy * root->height.computed / root->viewBox.height(); + if(Geom::are_near((root->width.computed * root->viewBox.height()) / (root->viewBox.width() * root->height.computed), 1.0, Geom::EPSILON)) { + // for uniform scaling, try to reduce numerical error + double vbunit2px = (root->width.computed / root->viewBox.width() + root->height.computed / root->viewBox.height())/2.0; + newx = newx * vbunit2px; + newy = newy * vbunit2px; + } else { + newx = newx * root->width.computed / root->viewBox.width(); + newy = newy * root->height.computed / root->viewBox.height(); + } } this->point_on_line = Geom::Point(newx, newy); } else if (success == 1) { -- cgit v1.2.3 From df7828a7a8ba0b7e6c2dd892ca5f0a62ef718bf0 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 24 Feb 2015 19:22:08 -0500 Subject: create SPObject factory (bzr r13939.1.1) --- src/sp-guide.cpp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 08b055508..4e1c5913d 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -47,16 +47,6 @@ using Inkscape::DocumentUndo; using std::vector; -#include "sp-factory.h" - -namespace { - SPObject* createGuide() { - return new SPGuide(); - } - - bool guideRegistered = SPFactory::instance().registerObject("sodipodi:guide", createGuide); -} - SPGuide::SPGuide() : SPObject() , label(NULL) -- cgit v1.2.3