diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2011-06-23 22:22:07 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2011-06-23 22:22:07 +0000 |
| commit | ab143333746e25648b253f13c0539adff089b1b6 (patch) | |
| tree | 5a025875e0e107b07b13970374afbd78cb021af7 /src | |
| parent | Update 2Geom to pull in integer rectangle class (diff) | |
| download | inkscape-ab143333746e25648b253f13c0539adff089b1b6.tar.gz inkscape-ab143333746e25648b253f13c0539adff089b1b6.zip | |
Remove more of libnr
(bzr r10347.1.2)
Diffstat (limited to 'src')
113 files changed, 284 insertions, 2237 deletions
diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index a668a2b3b..08bcbff45 100644 --- a/src/2geom/Makefile_insert +++ b/src/2geom/Makefile_insert @@ -77,8 +77,8 @@ 2geom/quadtree.cpp \ 2geom/quadtree.h \ 2geom/ray.h \ - 2geom/rect.h \ 2geom/rect.cpp \ + 2geom/rect.h \ 2geom/region.cpp \ 2geom/region.h \ 2geom/sbasis-2d.cpp \ diff --git a/src/2geom/d2-sbasis.h b/src/2geom/d2-sbasis.h index 95c0da4ed..e61067e1b 100644 --- a/src/2geom/d2-sbasis.h +++ b/src/2geom/d2-sbasis.h @@ -35,11 +35,11 @@ * */ -#ifdef _2GEOM_D2 /*This is intentional: we don't actually want anyone to - include this, other than D2.h. If somone else tries, D2 - won't be defined. If it is, this will already be included. */ -#ifndef __2GEOM_SBASIS_CURVE_H -#define __2GEOM_SBASIS_CURVE_H +#ifdef SEEN_LIB2GEOM_D2_H /*This is intentional: we don't actually want anyone to + include this, other than D2.h. If somone else tries, D2 + won't be defined. If it is, this will already be included. */ +#ifndef SEEN_LIB2GEOM_D2_SBASIS_H +#define SEEN_LIB2GEOM_D2_SBASIS_H #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> diff --git a/src/2geom/d2.h b/src/2geom/d2.h index 73330295b..4a4f45a63 100644 --- a/src/2geom/d2.h +++ b/src/2geom/d2.h @@ -29,12 +29,13 @@ * */ -#ifndef _2GEOM_D2 //If this is change, change the guard in rect.h as well. -#define _2GEOM_D2 +#ifndef SEEN_LIB2GEOM_D2_H +#define SEEN_LIB2GEOM_D2_H #include <2geom/point.h> #include <2geom/interval.h> #include <2geom/affine.h> +#include <2geom/rect.h> #include <boost/concept_check.hpp> #include <2geom/concepts.h> diff --git a/src/2geom/generic-rect.h b/src/2geom/generic-rect.h index cc0d7d42e..9a839d735 100644 --- a/src/2geom/generic-rect.h +++ b/src/2geom/generic-rect.h @@ -69,7 +69,7 @@ public: /// @name Create rectangles. /// @{ /** @brief Create a rectangle that contains only the point at (0,0). */ - GenericRect() { f[X] = f[Y] = Interval(); } + GenericRect() { f[X] = f[Y] = CInterval(); } /** @brief Create a rectangle from X and Y intervals. */ GenericRect(CInterval const &a, CInterval const &b) { f[X] = a; @@ -102,6 +102,25 @@ public: GenericRect<C> result = GenericRect<C>::from_range(c, c+n); return result; } + /** @brief Create rectangle from origin and dimensions. */ + static GenericRect<C> from_xywh(C x, C y, C w, C h) { + CPoint xy(x, y); + CPoint wh(w, h); + GenericRect<C> result(xy, xy + wh); + return result; + } + /** @brief Create rectangle from origin and dimensions. */ + static GenericRect<C> from_xywh(CPoint const &xy, CPoint const &wh) { + GenericRect<C> result(xy, xy + wh); + return result; + } + /** @brief Create rectangle from two points. */ + static GenericRect<C> from_xyxy(C x0, C x1, C y0, C y1) { + CPoint p0(x0, y0); + CPoint p1(x1, y1); + GenericRect<C> result(p0, p1); + return result; + } /// @} /// @name Inspect dimensions. @@ -183,6 +202,16 @@ public: /// @name Modify the rectangle. /// @{ + /** @brief Set the upper left point of the rectangle. */ + void setMin(CPoint const &p) { + f[X].setMin(p[X]); + f[Y].setMin(p[Y]); + } + /** @brief Set the lower right point of the rectangle. */ + void setMax(CPoint const &p) { + f[X].setMax(p[X]); + f[Y].setMax(p[Y]); + } /** @brief Enlarge the rectangle to contain the given point. */ void expandTo(CPoint const &p) { f[X].expandTo(p[X]); f[Y].expandTo(p[Y]); diff --git a/src/2geom/point-l.h b/src/2geom/point-l.h deleted file mode 100644 index d57314a19..000000000 --- a/src/2geom/point-l.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef SEEN_Geom_POINT_L_H -#define SEEN_Geom_POINT_L_H - -#include <stdexcept> -#include <2geom/point.h> - -namespace Geom { - -typedef long ICoord; - -class IPoint { - ICoord _pt[2]; - - public: - IPoint() { } - - IPoint(ICoord x, ICoord y) { - _pt[X] = x; - _pt[Y] = y; - } - - IPoint(NRPointL const &p) { - _pt[X] = p.x; - _pt[Y] = p.y; - } - - IPoint(IPoint const &p) { - for (unsigned i = 0; i < 2; ++i) { - _pt[i] = p._pt[i]; - } - } - - IPoint &operator=(IPoint const &p) { - for (unsigned i = 0; i < 2; ++i) { - _pt[i] = p._pt[i]; - } - return *this; - } - - operator Point() { - return Point(_pt[X], _pt[Y]); - } - - ICoord operator[](unsigned i) const throw(std::out_of_range) { - if ( i > Y ) throw std::out_of_range("index out of range"); - return _pt[i]; - } - - ICoord &operator[](unsigned i) throw(std::out_of_range) { - if ( i > Y ) throw std::out_of_range("index out of range"); - return _pt[i]; - } - - ICoord operator[](Dim2 d) const throw() { return _pt[d]; } - ICoord &operator[](Dim2 d) throw() { return _pt[d]; } - - IPoint &operator+=(IPoint const &o) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] += o._pt[i]; - } - return *this; - } - - IPoint &operator-=(IPoint const &o) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] -= o._pt[i]; - } - return *this; - } -}; - - -} // namespace Geom - -#endif /* !SEEN_Geom_POINT_L_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/axis-manip.h b/src/axis-manip.h index 835f67a97..d81da4164 100644 --- a/src/axis-manip.h +++ b/src/axis-manip.h @@ -12,8 +12,8 @@ #ifndef SEEN_AXIS_MANIP_H #define SEEN_AXIS_MANIP_H +#include <utility> #include <gtk/gtk.h> -#include "libnr/nr-point.h" namespace Proj { diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 90f1707b9..fad7c0761 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -301,11 +301,11 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven m.setup(desktop, true, bc->item); m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); - bc->center = from_2geom(button_dt); + bc->center = button_dt; - bc->drag_origin = from_2geom(button_dt); - bc->drag_ptB = from_2geom(button_dt); - bc->drag_ptC = from_2geom(button_dt); + bc->drag_origin = button_dt; + bc->drag_ptB = button_dt; + bc->drag_ptC = button_dt; // This can happen after saving when the last remaining perspective was purged and must be recreated. if (!cur_persp) { @@ -314,7 +314,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven } /* Projective preimages of clicked point under current perspective */ - bc->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(button_dt), 0, Proj::Z); + bc->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (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(); @@ -358,10 +358,10 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven } if (!bc->extruded) { - bc->drag_ptB = from_2geom(motion_dt); - bc->drag_ptC = from_2geom(motion_dt); + bc->drag_ptB = motion_dt; + bc->drag_ptC = motion_dt; - bc->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(motion_dt), 0, Proj::Z); + bc->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (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; @@ -371,15 +371,15 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven if (!bc->ctrl_dragged) { /* snapping */ Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, document->getCurrentPersp3D()); - bc->drag_ptC = pline.closest_to (from_2geom(motion_dt)); + bc->drag_ptC = pline.closest_to (motion_dt); bc->drag_ptB_proj.normalize(); bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X); } else { - bc->drag_ptC = from_2geom(motion_dt); + bc->drag_ptC = motion_dt; bc->drag_ptB_proj.normalize(); - bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(motion_dt), bc->drag_ptB_proj[Proj::X], Proj::X); + bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (motion_dt, bc->drag_ptB_proj[Proj::X], Proj::X); } m.freeSnapReturnByRef(bc->drag_ptC, Inkscape::SNAPSOURCE_NODE_HANDLE); } diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index eb2b3a093..df1bf0c7a 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -155,9 +155,9 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge m.unSetup(); } - 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)); + sp_guideline_set_position(SP_GUIDELINE(guide), event_dt); + desktop->set_coordinate_status(event_dt); + desktop->setPosition(event_dt); } break; case GDK_BUTTON_RELEASE: @@ -186,13 +186,13 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide"); sp_repr_set_point(repr, "orientation", normal); - sp_repr_set_point(repr, "position", from_2geom(event_dt)); + sp_repr_set_point(repr, "position", event_dt); desktop->namedview->appendChild(repr); Inkscape::GC::release(repr); DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create guide")); } - desktop->set_coordinate_status(from_2geom(event_dt)); + desktop->set_coordinate_status(event_dt); } default: break; @@ -345,8 +345,8 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) break; } moved = true; - desktop->set_coordinate_status(from_2geom(motion_dt)); - desktop->setPosition(from_2geom(motion_dt)); + desktop->set_coordinate_status(motion_dt); + desktop->setPosition(motion_dt); ret = TRUE; } @@ -429,8 +429,8 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) _("Delete guide")); } moved = false; - desktop->set_coordinate_status(from_2geom(event_dt)); - desktop->setPosition (from_2geom(event_dt)); + desktop->set_coordinate_status(event_dt); + desktop->setPosition (event_dt); } drag_type = SP_DRAG_NONE; sp_canvas_item_ungrab(item, event->button.time); diff --git a/src/desktop.cpp b/src/desktop.cpp index f12f83ca6..181a19e1b 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -57,6 +57,7 @@ #include <sigc++/functors/mem_fun.h> #include <gtkmm.h> +#include <2geom/transforms.h> #include <2geom/rect.h> #include "macros.h" #include "inkscape-private.h" diff --git a/src/dialogs/clonetiler.cpp b/src/dialogs/clonetiler.cpp index 60ec4f9f7..b9e490dcf 100644 --- a/src/dialogs/clonetiler.cpp +++ b/src/dialogs/clonetiler.cpp @@ -17,6 +17,7 @@ #include <glib/gmem.h> #include <gtk/gtk.h> #include <glibmm/i18n.h> +#include <2geom/transforms.h> #include "desktop.h" #include "desktop-handles.h" diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index a9893f09d..daad2d515 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -33,6 +33,7 @@ #include "svg/svg-color.h" #include "util/mathfns.h" #include "xml/node-event-vector.h" +#include "round.h" #define SAFE_SETPIXEL //undefine this when it is certain that setpixel is never called with invalid params @@ -549,13 +550,13 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) // x-axis always goes from topleft to bottomright. (0,0) - (1,1) gdouble const xintercept_y_bc = (buf_tl_gc[Geom::X] * tan_angle[X]) - buf_tl_gc[Geom::Y] ; gdouble const xstart_y_sc = ( xintercept_y_bc - floor(xintercept_y_bc/lyw)*lyw ) + buf->rect.y0; - gint const xlinestart = (gint) Inkscape::round( (xstart_y_sc - buf->rect.x0*tan_angle[X] -ow[Geom::Y]) / lyw ); + gint const xlinestart = round( (xstart_y_sc - buf->rect.x0*tan_angle[X] -ow[Geom::Y]) / lyw ); gint xlinenum = xlinestart; // lines starting on left side. for (y = xstart_y_sc; y < buf->rect.y1; y += lyw, xlinenum++) { gint const x0 = buf->rect.x0; - gint const y0 = (gint) Inkscape::round(y); - gint const x1 = x0 + (gint) Inkscape::round( (buf->rect.y1 - y) / tan_angle[X] ); + gint const y0 = round(y); + gint const x1 = x0 + round( (buf->rect.y1 - y) / tan_angle[X] ); gint const y1 = buf->rect.y1; if (!scaled && (xlinenum % empspacing) != 0) { @@ -570,8 +571,8 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) for (x = xstart_x_sc; x < buf->rect.x1; x += lxw_x, xlinenum--) { gint const y0 = buf->rect.y0; gint const y1 = buf->rect.y1; - gint const x0 = (gint) Inkscape::round(x); - gint const x1 = x0 + (gint) Inkscape::round( (y1 - y0) / tan_angle[X] ); + gint const x0 = round(x); + gint const x1 = x0 + round( (y1 - y0) / tan_angle[X] ); if (!scaled && (xlinenum % empspacing) != 0) { sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); @@ -582,10 +583,10 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) // y-axis lines (vertical) gdouble const ystart_x_sc = floor (buf_tl_gc[Geom::X] / spacing_ylines) * spacing_ylines + ow[Geom::X]; - gint const ylinestart = (gint) Inkscape::round((ystart_x_sc - ow[Geom::X]) / spacing_ylines); + gint const ylinestart = round((ystart_x_sc - ow[Geom::X]) / spacing_ylines); gint ylinenum = ylinestart; for (x = ystart_x_sc; x < buf->rect.x1; x += spacing_ylines, ylinenum++) { - gint const x0 = (gint) Inkscape::round(x); + gint const x0 = round(x); if (!scaled && (ylinenum % empspacing) != 0) { sp_grid_vline (buf, x0, buf->rect.y0, buf->rect.y1 - 1, color); @@ -597,13 +598,13 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) // z-axis always goes from bottomleft to topright. (0,1) - (1,0) gdouble const zintercept_y_bc = (buf_tl_gc[Geom::X] * -tan_angle[Z]) - buf_tl_gc[Geom::Y] ; gdouble const zstart_y_sc = ( zintercept_y_bc - floor(zintercept_y_bc/lyw)*lyw ) + buf->rect.y0; - gint const zlinestart = (gint) Inkscape::round( (zstart_y_sc + buf->rect.x0*tan_angle[Z] - ow[Geom::Y]) / lyw ); + gint const zlinestart = round( (zstart_y_sc + buf->rect.x0*tan_angle[Z] - ow[Geom::Y]) / lyw ); gint zlinenum = zlinestart; // lines starting from left side for (y = zstart_y_sc; y < buf->rect.y1; y += lyw, zlinenum++) { gint const x0 = buf->rect.x0; - gint const y0 = (gint) Inkscape::round(y); - gint const x1 = x0 + (gint) Inkscape::round( (y - buf->rect.y0 ) / tan_angle[Z] ); + gint const y0 = round(y); + gint const x1 = x0 + round( (y - buf->rect.y0 ) / tan_angle[Z] ); gint const y1 = buf->rect.y0; if (!scaled && (zlinenum % empspacing) != 0) { @@ -617,8 +618,8 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) for (x = zstart_x_sc; x < buf->rect.x1; x += lxw_z, zlinenum++) { gint const y0 = buf->rect.y1; gint const y1 = buf->rect.y0; - gint const x0 = (gint) Inkscape::round(x); - gint const x1 = x0 + (gint) Inkscape::round( (buf->rect.y1 - buf->rect.y0) / tan_angle[Z] ); + gint const x0 = round(x); + gint const x1 = x0 + round( (buf->rect.y1 - buf->rect.y0) / tan_angle[Z] ); if (!scaled && (zlinenum % empspacing) != 0) { sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 82ea036f6..52963ce6b 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -918,9 +918,9 @@ void CanvasXYGrid::Render (SPCanvasBuf *buf) { gdouble const sxg = floor ((buf->rect.x0 - ow[Geom::X]) / sw[Geom::X]) * sw[Geom::X] + ow[Geom::X]; - gint const xlinestart = (gint) Inkscape::round((sxg - ow[Geom::X]) / sw[Geom::X]); + gint const xlinestart = round((sxg - ow[Geom::X]) / sw[Geom::X]); gdouble const syg = floor ((buf->rect.y0 - ow[Geom::Y]) / sw[Geom::Y]) * sw[Geom::Y] + ow[Geom::Y]; - gint const ylinestart = (gint) Inkscape::round((syg - ow[Geom::Y]) / sw[Geom::Y]); + gint const ylinestart = round((syg - ow[Geom::Y]) / sw[Geom::Y]); //set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -941,7 +941,7 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) gint ylinenum; gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[Geom::Y], ylinenum++) { - gint const y0 = (gint) Inkscape::round(y); + gint const y0 = round(y); if (!scaled[Geom::Y] && (ylinenum % empspacing) != 0) { grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, color); } else { @@ -952,7 +952,7 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) gint xlinenum; gdouble x; for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[Geom::X], xlinenum++) { - gint const ix = (gint) Inkscape::round(x); + gint const ix = round(x); if (!scaled[Geom::X] && (xlinenum % empspacing) != 0) { grid_vline (buf, ix, buf->rect.y0, buf->rect.y1, color); } else { @@ -963,12 +963,12 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) gint ylinenum; gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[Geom::Y], ylinenum++) { - gint const iy = (gint) Inkscape::round(y); + gint const iy = round(y); gint xlinenum; gdouble x; for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[Geom::X], xlinenum++) { - gint const ix = (gint) Inkscape::round(x); + gint const ix = round(x); if ( (!scaled[Geom::X] && (xlinenum % empspacing) != 0) || (!scaled[Geom::Y] && (ylinenum % empspacing) != 0) || ((scaled[Geom::X] || scaled[Geom::Y]) && no_emp_when_zoomed_out) ) diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index c761fa74e..c1c3e7740 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -112,8 +112,8 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) cairo_set_line_cap(buf->ct, CAIRO_LINE_CAP_SQUARE); cairo_set_font_size(buf->ct, 10); - int px = (int) Inkscape::round(gl->point_on_line[Geom::X]); - int py = (int) Inkscape::round(gl->point_on_line[Geom::Y]); + int px = round(gl->point_on_line[Geom::X]); + int py = round(gl->point_on_line[Geom::Y]); if (gl->label) { cairo_save(buf->ct); @@ -126,12 +126,12 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) } if (gl->is_vertical()) { - int position = (int) Inkscape::round(gl->point_on_line[Geom::X]); + int position = round(gl->point_on_line[Geom::X]); cairo_move_to(buf->ct, position + 0.5, buf->rect.y0 + 0.5); cairo_line_to(buf->ct, position + 0.5, buf->rect.y1 - 0.5); cairo_stroke(buf->ct); } else if (gl->is_horizontal()) { - int position = (int) Inkscape::round(gl->point_on_line[Geom::Y]); + int position = round(gl->point_on_line[Geom::Y]); cairo_move_to(buf->ct, buf->rect.x0 + 0.5, position + 0.5); cairo_line_to(buf->ct, buf->rect.x1 - 0.5, position + 0.5); cairo_stroke(buf->ct); @@ -193,9 +193,9 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, sp_canvas_item_request_update(SP_CANVAS_ITEM (gl->origin)); if (gl->is_horizontal()) { - sp_canvas_update_bbox (item, -1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y] - 16), 1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y] + 1)); + sp_canvas_update_bbox (item, -1000000, round(gl->point_on_line[Geom::Y] - 16), 1000000, round(gl->point_on_line[Geom::Y] + 1)); } else if (gl->is_vertical()) { - sp_canvas_update_bbox (item, (int) Inkscape::round(gl->point_on_line[Geom::X]), -1000000, (int) Inkscape::round(gl->point_on_line[Geom::X] + 16), 1000000); + sp_canvas_update_bbox (item, round(gl->point_on_line[Geom::X]), -1000000, round(gl->point_on_line[Geom::X] + 16), 1000000); } else { //TODO: labels in angled guidelines are not showing up for some reason. sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000); diff --git a/src/display/nr-arena-glyphs.cpp b/src/display/nr-arena-glyphs.cpp index dbac07596..0e20f0ddb 100644 --- a/src/display/nr-arena-glyphs.cpp +++ b/src/display/nr-arena-glyphs.cpp @@ -135,10 +135,10 @@ nr_arena_glyphs_update(NRArenaItem *item, NRRectL */*area*/, NRGC *gc, guint /*s } if (b) { - item->bbox.x0 = static_cast<NR::ICoord>(floor(b->left())); - item->bbox.y0 = static_cast<NR::ICoord>(floor(b->top())); - item->bbox.x1 = static_cast<NR::ICoord>(ceil (b->right())); - item->bbox.y1 = static_cast<NR::ICoord>(ceil (b->bottom())); + item->bbox.x0 = floor(b->left()); + item->bbox.y0 = floor(b->top()); + item->bbox.x1 = ceil (b->right()); + item->bbox.y1 = ceil (b->bottom()); } else { item->bbox.x0 = 0; item->bbox.y0 = 0; diff --git a/src/display/nr-arena-group.cpp b/src/display/nr-arena-group.cpp index 97f92d02d..d1e6869aa 100644 --- a/src/display/nr-arena-group.cpp +++ b/src/display/nr-arena-group.cpp @@ -176,7 +176,7 @@ nr_arena_group_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int } if (beststate & NR_ARENA_ITEM_STATE_BBOX) { - nr_rect_l_set_empty (&item->bbox); + item->bbox = NR_RECT_L_EMPTY; for (NRArenaItem *child = group->children; child != NULL; child = child->next) { if (child->visible) nr_rect_l_union (&item->bbox, &item->bbox, &child->drawbox); diff --git a/src/display/nr-arena-item.h b/src/display/nr-arena-item.h index 0fc4cbe48..d65a75ed8 100644 --- a/src/display/nr-arena-item.h +++ b/src/display/nr-arena-item.h @@ -15,6 +15,8 @@ #include <cairo.h> #include <2geom/affine.h> +#include <2geom/rect.h> +#include "libnr/nr-forward.h" #include "libnr/nr-rect-l.h" #include "libnr/nr-object.h" #include "gc-soft-ptr.h" diff --git a/src/display/nr-arena-shape.cpp b/src/display/nr-arena-shape.cpp index eb7a30e58..ff87b5134 100644 --- a/src/display/nr-arena-shape.cpp +++ b/src/display/nr-arena-shape.cpp @@ -223,10 +223,10 @@ nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, g if (shape->curve) { boundingbox = bounds_exact_transformed(shape->curve->get_pathvector(), gc->transform); if (boundingbox) { - item->bbox.x0 = static_cast<NR::ICoord>(floor((*boundingbox)[0][0])); // Floor gives the coordinate in which the point resides - item->bbox.y0 = static_cast<NR::ICoord>(floor((*boundingbox)[1][0])); - item->bbox.x1 = static_cast<NR::ICoord>(ceil ((*boundingbox)[0][1])); // Ceil gives the first coordinate beyond the point - item->bbox.y1 = static_cast<NR::ICoord>(ceil ((*boundingbox)[1][1])); + item->bbox.x0 = floor((*boundingbox)[0][0]); // Floor gives the coordinate in which the point resides + item->bbox.y0 = floor((*boundingbox)[1][0]); + item->bbox.x1 = ceil ((*boundingbox)[0][1]); // Ceil gives the first coordinate beyond the point + item->bbox.y1 = ceil ((*boundingbox)[1][1]); } else { item->bbox = NR_RECT_L_EMPTY; } @@ -274,10 +274,10 @@ nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, g /// \todo just write item->bbox = boundingbox if (boundingbox) { - shape->approx_bbox.x0 = static_cast<NR::ICoord>(floor((*boundingbox)[0][0])); - shape->approx_bbox.y0 = static_cast<NR::ICoord>(floor((*boundingbox)[1][0])); - shape->approx_bbox.x1 = static_cast<NR::ICoord>(ceil ((*boundingbox)[0][1])); - shape->approx_bbox.y1 = static_cast<NR::ICoord>(ceil ((*boundingbox)[1][1])); + shape->approx_bbox.x0 = floor(boundingbox->left()); + shape->approx_bbox.y0 = floor(boundingbox->top()); + shape->approx_bbox.x1 = ceil (boundingbox->right()); + shape->approx_bbox.y1 = ceil (boundingbox->bottom()); } else { shape->approx_bbox = NR_RECT_L_EMPTY; } diff --git a/src/display/nr-arena-shape.h b/src/display/nr-arena-shape.h index 2ee0d24c8..7b86f7f59 100644 --- a/src/display/nr-arena-shape.h +++ b/src/display/nr-arena-shape.h @@ -22,6 +22,7 @@ #include "forward.h" #include "nr-arena-item.h" #include "nr-style.h" +#include "libnr/nr-rect.h" NRType nr_arena_shape_get_type (void); diff --git a/src/display/nr-arena.cpp b/src/display/nr-arena.cpp index 43edb6918..ce62a81dc 100644 --- a/src/display/nr-arena.cpp +++ b/src/display/nr-arena.cpp @@ -18,6 +18,7 @@ #include "nr-filter-types.h" #include "preferences.h" #include "color.h" +#include "libnr/nr-rect.h" static void nr_arena_class_init (NRArenaClass *klass); static void nr_arena_init (NRArena *arena); diff --git a/src/display/nr-filter-displacement-map.cpp b/src/display/nr-filter-displacement-map.cpp index fdaf2c887..15200223b 100644 --- a/src/display/nr-filter-displacement-map.cpp +++ b/src/display/nr-filter-displacement-map.cpp @@ -28,128 +28,6 @@ FilterPrimitive * FilterDisplacementMap::create() { FilterDisplacementMap::~FilterDisplacementMap() {} -#if 0 -struct pixel_t { - unsigned char channels[4]; - inline unsigned char operator[](int c) const { return channels[c]; } - inline unsigned char& operator[](int c) { return channels[c]; } - static inline pixel_t blank() { - pixel_t p; - for(unsigned int i=0; i<4; i++) { - p[i] = 0; - } - return p; - } -}; - -static inline pixel_t pixelValue(NRPixBlock const* pb, int x, int y) { - if ( x < pb->area.x0 || x >= pb->area.x1 || y < pb->area.y0 || y >= pb->area.y1 ) return pixel_t::blank(); // This assumes anything outside the defined range is (0,0,0,0) - pixel_t const* rowData = reinterpret_cast<pixel_t const*>(NR_PIXBLOCK_PX(pb) + (y-pb->area.y0)*pb->rs); - return rowData[x-pb->area.x0]; -} - -template<bool PREMULTIPLIED> -static pixel_t interpolatePixels(NRPixBlock const* pb, double x, double y) { - // NOTE: The values of x and y are shifted by -0.5 (the "true" values would be x+0.5 and y+0.5). - // This is done because otherwise the pixel values first have to be shifted by +0.5 and then by -0.5 again... - unsigned int const sfl = 8u; - unsigned int const sf = 1u<<sfl; - unsigned int const sf2h = 1u<<(2u*sfl-1); - int xi = (int)floor(x), yi = (int)floor(y); - unsigned int xf = static_cast<unsigned int>(round(sf * (x - xi))), - yf = static_cast<unsigned int>(round(sf * (y - yi))); - pixel_t p00 = pixelValue(pb, xi+0, yi+0); - pixel_t p01 = pixelValue(pb, xi+1, yi+0); - pixel_t p10 = pixelValue(pb, xi+0, yi+1); - pixel_t p11 = pixelValue(pb, xi+1, yi+1); - - /* It's a good idea to interpolate premultiplied colors: - * - * Consider two pixels, one being rgba(255,0,0,0), which is fully transparent, - * and the other being rgba(0,0,255,255), or blue (fully opaque). - * If these two colors are interpolated the expected result would be bluish pixels - * containing no red. - * - * However, if our final alpha value is zero, then the RGB values aren't really determinate. - * We might as well avoid premultiplication in this case, which still gives us a fully - * transparent result, but with interpolated RGB parts. */ - - pixel_t r; - if (PREMULTIPLIED) { - /* Premultiplied, so do simple interpolation. */ - for (unsigned i = 0; i != 4; ++i) { - // y0,y1 have range [0,a*sf] - unsigned const y0 = sf*p00[i] + xf*((unsigned int)p01[i]-(unsigned int)p00[i]); - unsigned const y1 = sf*p10[i] + xf*((unsigned int)p11[i]-(unsigned int)p10[i]); - - unsigned const ri = sf*y0 + yf*(y1-y0); // range [0,a*sf*sf] - r[i] = (ri + sf2h)>>(2*sfl); // range [0,a] - } - } else { - /* First calculate interpolated alpha value. */ - unsigned const y0 = sf*p00[3] + xf*((unsigned int)p01[3]-(unsigned int)p00[3]); // range [0,a*sf] - unsigned const y1 = sf*p10[3] + xf*((unsigned int)p11[3]-(unsigned int)p10[3]); - unsigned const ra = sf*y0 + yf*(y1-y0); // range [0,a*sf*sf] - - if (ra==0) { - /* Fully transparent, so do simple interpolation. */ - for (unsigned i = 0; i != 3; ++i) { - // y0,y1 have range [0,255*sf] - unsigned const y0 = sf*p00[i] + xf*((unsigned int)p01[i]-(unsigned int)p00[i]); - unsigned const y1 = sf*p10[i] + xf*((unsigned int)p11[i]-(unsigned int)p10[i]); - - unsigned const ri = sf*y0 + yf*(y1-y0); // range [0,255*sf*sf] - r[i] = (ri + sf2h)>>(2*sfl); // range [0,255] - } - r[3] = 0; - } else { - /* Do premultiplication ourselves. */ - for (unsigned i = 0; i != 3; ++i) { - // Premultiplied versions. Range [0,255*a]. - unsigned const c00 = p00[i]*p00[3]; - unsigned const c01 = p01[i]*p01[3]; - unsigned const c10 = p10[i]*p10[3]; - unsigned const c11 = p11[i]*p11[3]; - - // Interpolation. - unsigned const y0 = sf*c00 + xf*(c01-c00); // range [0,255*a*sf] - unsigned const y1 = sf*c10 + xf*(c11-c10); // range [0,255*a*sf] - unsigned const ri = sf*y0 + yf*(y1-y0); // range [0,255*a*sf*sf] - r[i] = (ri + ra/2) / ra; // range [0,255] - } - r[3] = (ra + sf2h)>>(2*sfl); // range [0,a] - } - } - - return r; -} - -template<bool MAP_PREMULTIPLIED, bool DATA_PREMULTIPLIED> -static void performDisplacement(NRPixBlock const* texture, NRPixBlock const* map, int Xchannel, int Ychannel, NRPixBlock* out, double scalex, double scaley) { - bool Xneedsdemul = MAP_PREMULTIPLIED && Xchannel<3; - bool Yneedsdemul = MAP_PREMULTIPLIED && Ychannel<3; - if (!Xneedsdemul) scalex /= 255.0; - if (!Yneedsdemul) scaley /= 255.0; - - for (int yout=out->area.y0; yout < out->area.y1; yout++){ - pixel_t const* mapRowData = reinterpret_cast<pixel_t const*>(NR_PIXBLOCK_PX(map) + (yout-map->area.y0)*map->rs); - pixel_t* outRowData = reinterpret_cast<pixel_t*>(NR_PIXBLOCK_PX(out) + (yout-out->area.y0)*out->rs); - for (int xout=out->area.x0; xout < out->area.x1; xout++){ - pixel_t const mapValue = mapRowData[xout-map->area.x0]; - - double xtex = xout + (Xneedsdemul ? // Although the value of the pixel corresponds to the MIDDLE of the pixel, no +0.5 is needed because we're interpolating pixels anyway (so to get the actual pixel locations 0.5 would have to be subtracted again). - (mapValue[3]==0?0:(scalex * (mapValue[Xchannel] - mapValue[3]*0.5) / mapValue[3])) : - (scalex * (mapValue[Xchannel] - 127.5))); - double ytex = yout + (Yneedsdemul ? - (mapValue[3]==0?0:(scaley * (mapValue[Ychannel] - mapValue[3]*0.5) / mapValue[3])) : - (scaley * (mapValue[Ychannel] - 127.5))); - - outRowData[xout-out->area.x0] = interpolatePixels<DATA_PREMULTIPLIED>(texture, xtex, ytex); - } - } -} -#endif - struct Displace { Displace(cairo_surface_t *texture, cairo_surface_t *map, unsigned xch, unsigned ych, double scalex, double scaley) @@ -206,73 +84,6 @@ void FilterDisplacementMap::render_cairo(FilterSlot &slot) cairo_surface_destroy(out); } -/* -int FilterDisplacementMap::render(FilterSlot &slot, FilterUnits const &units) { - NRPixBlock *texture = slot.get(_input); - NRPixBlock *map = slot.get(_input2); - - // Bail out if either one of source images is missing - if (!map || !texture) { - g_warning("Missing source image for feDisplacementMap (map=%d texture=%d)", _input, _input2); - return 1; - } - - NR::IRect area = units.get_pixblock_filterarea_paraller(); - int x0 = std::max(map->area.x0,area.min()[NR::X]); - int y0 = std::max(map->area.y0,area.min()[NR::Y]); - int x1 = std::min(map->area.x1,area.max()[NR::X]); - int y1 = std::min(map->area.y1,area.max()[NR::Y]); - - //TODO: check whether we really need this check: - if (x1 <= x0 || y1 <= y0) return 0; //nothing to do! - - if (texture->mode != NR_PIXBLOCK_MODE_R8G8B8A8N && texture->mode != NR_PIXBLOCK_MODE_R8G8B8A8P) { - g_warning("Source images without an alpha channel are not supported by feDisplacementMap at the moment."); - return 1; - } - - NRPixBlock *out = new NRPixBlock; - nr_pixblock_setup_fast(out, texture->mode, x0, y0, x1, y1, true); - - // convert to a suitable format - bool free_map_on_exit = false; - if (map->mode != NR_PIXBLOCK_MODE_R8G8B8A8N && map->mode != NR_PIXBLOCK_MODE_R8G8B8A8P) { - NRPixBlock *original_map = map; - map = new NRPixBlock; - nr_pixblock_setup_fast(map, NR_PIXBLOCK_MODE_R8G8B8A8N, - original_map->area.x0, original_map->area.y0, - original_map->area.x1, original_map->area.y1, - false); - nr_blit_pixblock_pixblock(map, original_map); - free_map_on_exit = true; - } - bool map_premultiplied = (map->mode == NR_PIXBLOCK_MODE_R8G8B8A8P); - bool data_premultiplied = (out->mode == NR_PIXBLOCK_MODE_R8G8B8A8P); - - Geom::Affine trans = units.get_matrix_primitiveunits2pb(); - double scalex = scale * trans.expansionX(); - double scaley = scale * trans.expansionY(); - - if (map_premultiplied && data_premultiplied) { - performDisplacement<true,true>(texture, map, Xchannel, Ychannel, out, scalex, scaley); - } else if (map_premultiplied && !data_premultiplied) { - performDisplacement<true,false>(texture, map, Xchannel, Ychannel, out, scalex, scaley); - } else if (data_premultiplied) { - performDisplacement<false,true>(texture, map, Xchannel, Ychannel, out, scalex, scaley); - } else { - performDisplacement<false,false>(texture, map, Xchannel, Ychannel, out, scalex, scaley); - } - - if (free_map_on_exit) { - nr_pixblock_release(map); - delete map; - } - - out->empty = FALSE; - slot.set(_output, out); - return 0; -}*/ - void FilterDisplacementMap::set_input(int slot) { _input = slot; } diff --git a/src/display/nr-filter-turbulence.cpp b/src/display/nr-filter-turbulence.cpp index f3b03c024..60d5ce872 100644 --- a/src/display/nr-filter-turbulence.cpp +++ b/src/display/nr-filter-turbulence.cpp @@ -299,7 +299,6 @@ FilterTurbulence::FilterTurbulence() , numOctaves(1) , seed(0) , updated(false) - , updated_area(NR::IPoint(), NR::IPoint()) , fTileWidth(10) //guessed , fTileHeight(10) //guessed , fTileX(1) //guessed diff --git a/src/display/nr-filter-turbulence.h b/src/display/nr-filter-turbulence.h index 50161b6be..8d3639543 100644 --- a/src/display/nr-filter-turbulence.h +++ b/src/display/nr-filter-turbulence.h @@ -64,7 +64,6 @@ private: bool stitchTiles; FilterTurbulenceType type; bool updated; - NR::IRect updated_area; unsigned char *pix_data; double fTileWidth; diff --git a/src/display/nr-filter-units.cpp b/src/display/nr-filter-units.cpp index b1c475c41..a8686545a 100644 --- a/src/display/nr-filter-units.cpp +++ b/src/display/nr-filter-units.cpp @@ -158,22 +158,13 @@ Geom::Affine FilterUnits::get_matrix_user2primitiveunits() const { return get_matrix_user2units(primitiveUnits); } -NR::IRect FilterUnits::get_pixblock_filterarea_paraller() const { +Geom::IntRect FilterUnits::get_pixblock_filterarea_paraller() const { g_assert(filter_area); - int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; Geom::Affine u2pb = get_matrix_user2pb(); - - for (int i = 0 ; i < 4 ; i++) { - Geom::Point p = filter_area->corner(i); - p *= u2pb; - if (p[X] < min_x) min_x = (int)std::floor(p[X]); - if (p[X] > max_x) max_x = (int)std::ceil(p[X]); - if (p[Y] < min_y) min_y = (int)std::floor(p[Y]); - if (p[Y] > max_y) max_y = (int)std::ceil(p[Y]); - } - NR::IRect ret(NR::IPoint(min_x, min_y), NR::IPoint(max_x, max_y)); - return ret; + Geom::Rect r = *filter_area * u2pb; + Geom::IntRect ir = r.roundOutwards(); + return ir; } FilterUnits& FilterUnits::operator=(FilterUnits const &other) { diff --git a/src/display/nr-filter-units.h b/src/display/nr-filter-units.h index 2fc3e5533..1cb4fdbce 100644 --- a/src/display/nr-filter-units.h +++ b/src/display/nr-filter-units.h @@ -133,7 +133,7 @@ public: * NOTE: use only in filters, that define TRAIT_PARALLER in * get_input_traits. The filter effects area may not be representable * by simple rectangle otherwise. */ - NR::IRect get_pixblock_filterarea_paraller() const; + Geom::IntRect get_pixblock_filterarea_paraller() const; FilterUnits& operator=(FilterUnits const &other); diff --git a/src/display/nr-filter.cpp b/src/display/nr-filter.cpp index 55190b00c..a0997cc1b 100644 --- a/src/display/nr-filter.cpp +++ b/src/display/nr-filter.cpp @@ -238,10 +238,10 @@ void Filter::compute_drawbox(NRArenaItem const *item, NRRectL &item_bbox) { Geom::Rect enlarged = filter_effect_area(tmp_bbox); enlarged = enlarged * item->ctm; - item_bbox.x0 = (NR::ICoord) floor(enlarged.min()[X]); - item_bbox.y0 = (NR::ICoord) floor(enlarged.min()[Y]); - item_bbox.x1 = (NR::ICoord) ceil(enlarged.max()[X]); - item_bbox.y1 = (NR::ICoord) ceil(enlarged.max()[Y]); + item_bbox.x0 = floor(enlarged.min()[X]); + item_bbox.y0 = floor(enlarged.min()[Y]); + item_bbox.x1 = ceil(enlarged.max()[X]); + item_bbox.y1 = ceil(enlarged.max()[Y]); } Geom::Rect Filter::filter_effect_area(Geom::Rect const &bbox) diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 472c9ada5..977452834 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -2306,13 +2306,15 @@ Geom::Rect SPCanvas::getViewbox() const } /** - * Return canvas window coordinates as IRect (a rectangle defined by integers). + * Return canvas window coordinates as integer rectangle. */ -NR::IRect SPCanvas::getViewboxIntegers() const +Geom::IntRect SPCanvas::getViewboxIntegers() const { GtkWidget const *w = GTK_WIDGET(this); - return NR::IRect(NR::IPoint(x0, y0), - NR::IPoint(x0 + w->allocation.width, y0 + w->allocation.height)); + Geom::IntRect ret; + ret.setMin(Geom::IntPoint(x0, y0)); + ret.setMax(Geom::IntPoint(x0 + w->allocation.width, y0 + w->allocation.height)); + return ret; } inline int sp_canvas_tile_floor(int x) diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index 7a6b3295e..32747e7c5 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -149,7 +149,7 @@ struct SPCanvas { bool is_scrolling; Geom::Rect getViewbox() const; - NR::IRect getViewboxIntegers() const; + Geom::IntRect getViewboxIntegers() const; }; GtkWidget *sp_canvas_new_aa(); diff --git a/src/document.cpp b/src/document.cpp index 90fc4c635..5bcf1bf40 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -40,6 +40,7 @@ #include <gtk/gtk.h> #include <string> #include <cstring> +#include <2geom/transforms.h> #include "desktop.h" #include "dir-util.h" @@ -647,7 +648,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) Geom::Translate const tr( Geom::Point(0, old_height - rect_with_margins.height()) - - to_2geom(rect_with_margins.min())); + - rect_with_margins.min()); root->translateChildItems(tr); if(nv) { diff --git a/src/draw-context.h b/src/draw-context.h index 4266bdea4..17540649b 100644 --- a/src/draw-context.h +++ b/src/draw-context.h @@ -16,9 +16,9 @@ #include <stddef.h> #include <sigc++/sigc++.h> +#include <2geom/point.h> #include "event-context.h" #include <forward.h> -#include <libnr/nr-point.h> #include "live_effects/effect.h" /* Freehand context */ diff --git a/src/dropper-context.cpp b/src/dropper-context.cpp index e30d6b1e8..9fbbcdc27 100644 --- a/src/dropper-context.cpp +++ b/src/dropper-context.cpp @@ -15,11 +15,10 @@ # include <config.h> #endif -#include <glibmm/i18n.h> -#include <glibmm/ustring.h> -#include <glibmm/refptr.h> -#include <gtkmm/clipboard.h> -#include <gdk/gdkkeysyms.h> +#include <glibmm.h> +#include <gtkmm.h> +#include <gdk/gdk.h> +#include <2geom/transforms.h> #include "macros.h" #include "display/canvas-bpath.h" diff --git a/src/extension/implementation/implementation.h b/src/extension/implementation/implementation.h index b9e417feb..bd3edb43b 100644 --- a/src/extension/implementation/implementation.h +++ b/src/extension/implementation/implementation.h @@ -19,9 +19,9 @@ #include "forward.h" #include "extension/extension-forward.h" #include "libnr/nr-forward.h" -#include "libnr/nr-point.h" #include "xml/node.h" #include <2geom/forward.h> +#include <2geom/point.h> namespace Inkscape { namespace Extension { diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 676e9aa94..642ddba5b 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1013,7 +1013,7 @@ Geom::Point sp_item_gradient_get_coords(SPItem *item, guint point_type, guint po Geom::Point p (0, 0); if (!gradient) - return from_2geom(p); + return p; if (SP_IS_LINEARGRADIENT(gradient)) { SPLinearGradient *lg = SP_LINEARGRADIENT(gradient); @@ -1071,7 +1071,7 @@ Geom::Point sp_item_gradient_get_coords(SPItem *item, guint point_type, guint po } } p *= Geom::Affine(gradient->gradientTransform) * (Geom::Affine)item->i2d_affine(); - return from_2geom(p); + return p; } diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index 922a9b16e..86c86d2dc 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -548,9 +548,9 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) dragging = true; - Geom::Point button_dt = to_2geom(desktop->w2d(button_w)); + Geom::Point button_dt = desktop->w2d(button_w); if (event->button.state & GDK_SHIFT_MASK) { - Inkscape::Rubberband::get(desktop)->start(desktop, from_2geom(button_dt)); + Inkscape::Rubberband::get(desktop)->start(desktop, button_dt); } else { // remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to // enable Ctrl+doubleclick of exactly the selected item(s) @@ -561,7 +561,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) m.setup(desktop); m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); - rc->origin = from_2geom(button_dt); + rc->origin = button_dt; } ret = TRUE; diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index 4f536beb3..41e523b86 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -19,6 +19,7 @@ #include <cstring> #include <cstdlib> #include <float.h> +#include <2geom/transforms.h> #include "desktop.h" #include "inkscape.h" diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 64aa8bc48..fdfbdb9d3 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -511,15 +511,15 @@ namespace Geom { bool transform_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon) { return - NR_DF_TEST_CLOSE(m0[0], m1[0], epsilon) && - NR_DF_TEST_CLOSE(m0[1], m1[1], epsilon) && - NR_DF_TEST_CLOSE(m0[2], m1[2], epsilon) && - NR_DF_TEST_CLOSE(m0[3], m1[3], epsilon); + Geom::are_near(m0[0], m1[0], epsilon) && + Geom::are_near(m0[1], m1[1], epsilon) && + Geom::are_near(m0[2], m1[2], epsilon) && + Geom::are_near(m0[3], m1[3], epsilon); } bool translate_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon) { - return NR_DF_TEST_CLOSE(m0[4], m1[4], epsilon) && NR_DF_TEST_CLOSE(m0[5], m1[5], epsilon); + return Geom::are_near(m0[4], m1[4], epsilon) && Geom::are_near(m0[5], m1[5], epsilon); } diff --git a/src/helper/geom.h b/src/helper/geom.h index b1015b185..630d67aba 100644 --- a/src/helper/geom.h +++ b/src/helper/geom.h @@ -13,8 +13,8 @@ */ #include <2geom/forward.h> -#include <libnr/nr-forward.h> -#include <libnr/nr-coord.h> +#include <2geom/rect.h> +#include <2geom/affine.h> Geom::OptRect bounds_fast_transformed(Geom::PathVector const & pv, Geom::Affine const & t); Geom::OptRect bounds_exact_transformed(Geom::PathVector const & pv, Geom::Affine const & t); diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index f6796f2ad..226042337 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -18,6 +18,7 @@ #include <glib.h> #include <glib/gmessages.h> #include <png.h> +#include <2geom/transforms.h> #include "interface.h" #include "helper/png-write.h" diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 4667f631b..5a20ac363 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -18,6 +18,7 @@ #include "interface.h" #include <2geom/rect.h> +#include <2geom/transforms.h> #include <glib/gmessages.h> #include <png.h> #include "png-write.h" diff --git a/src/libnr/Makefile_insert b/src/libnr/Makefile_insert index 1027e0600..57d82c8ef 100644 --- a/src/libnr/Makefile_insert +++ b/src/libnr/Makefile_insert @@ -3,25 +3,16 @@ ink_common_sources += \ libnr/in-svg-plane.h \ libnr/nr-convert2geom.h \ - libnr/nr-coord.h \ - libnr/nr-dim2.h \ libnr/nr-forward.h \ - libnr/nr-i-coord.h \ libnr/nr-macros.h \ libnr/nr-object.cpp \ libnr/nr-object.h \ - libnr/nr-point-fns.cpp \ - libnr/nr-point-fns.h \ - libnr/nr-point-l.h \ - libnr/nr-point-ops.h \ - libnr/nr-point.h \ + libnr/nr-point-fns.cpp \ + libnr/nr-point-fns.h \ libnr/nr-rect-l.cpp \ libnr/nr-rect-l.h \ libnr/nr-rect.cpp \ libnr/nr-rect.h \ - libnr/nr-rect-ops.h \ - libnr/nr-types.cpp \ - libnr/nr-types.h \ libnr/nr-values.cpp \ libnr/nr-values.h diff --git a/src/libnr/in-svg-plane.h b/src/libnr/in-svg-plane.h index c1937f0fc..68c9e92a0 100644 --- a/src/libnr/in-svg-plane.h +++ b/src/libnr/in-svg-plane.h @@ -1,8 +1,7 @@ #ifndef SEEN_LIBNR_IN_SVG_PLANE_H #define SEEN_LIBNR_IN_SVG_PLANE_H -#include "libnr/nr-point-fns.h" - +#include <2geom/point.h> /** * Returns true iff the coordinates of \a p are finite, non-NaN, and "small enough". Currently we @@ -13,7 +12,7 @@ * in SVG Tiny (which uses fixed-point arithmetic). */ inline bool -in_svg_plane(NR::Point const p) +in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; } diff --git a/src/libnr/libnr.def b/src/libnr/libnr.def deleted file mode 100644 index d8f224ca9..000000000 --- a/src/libnr/libnr.def +++ /dev/null @@ -1,89 +0,0 @@ -EXPORTS - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM - nr_R8G8B8A8_N_EMPTY_A8_RGBA32 - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_A8 - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P - nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_A8 - nr_R8G8B8A8_N_R8G8B8A8_N_A8_RGBA32 - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_A8 - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_TRANSFORM - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P - nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_A8 - nr_R8G8B8A8_P_EMPTY_A8_RGBA32 - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_A8 - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P - nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_A8 - nr_R8G8B8A8_P_R8G8B8A8_P_A8_RGBA32 - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_A8 - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_A8 -; nr_R8G8B8_EMPTY_A8_RGBA32 - nr_R8G8B8_R8G8B8_A8_RGBA32 - nr_R8G8B8_R8G8B8_R8G8B8A8_N - nr_R8G8B8_R8G8B8_R8G8B8A8_P - nr_active_object_add_listener - nr_active_object_get_type - nr_active_object_remove_listener_by_data - nr_blit_pixblock_mask_rgba32 - nr_blit_pixblock_pixblock_alpha - nr_blit_pixblock_pixblock_mask - nr_compose_pixblock_pixblock_pixel - nr_emit_fail_warning - nr_flat_free_list - nr_flat_free_one - nr_flat_insert_sorted - nr_flat_new_full - nr_lgradient_renderer_setup - nr_matrix_invert - nr_matrix_set_rotate - nr_matrix_set_scale - nr_matrix_set_translate - nr_matrix_multiply - nr_object_check_instance_cast - nr_object_check_instance_type - nr_object_delete - nr_object_get_type - nr_object_new - nr_object_ref - nr_object_register_type - nr_object_release - nr_object_setup - nr_object_unref - nr_path_duplicate_transform - nr_path_matrix_bbox_nion - nr_path_matrix_point_bbox_wind_distance - nr_pixblock_draw_line_rgba32 - nr_pixblock_free - nr_pixblock_new - nr_pixblock_release - nr_pixblock_render_gray_noise - nr_pixblock_render_svp_mask_or - nr_pixblock_setup - nr_pixblock_setup_extern - nr_pixblock_setup_fast - nr_pixelstore_16K_free - nr_pixelstore_16K_new - nr_pixelstore_4K_free - nr_pixelstore_4K_new - nr_pixelstore_64K_free - nr_pixelstore_64K_new - nr_rect_d_intersect - nr_rect_d_matrix_transform - nr_rect_d_union - nr_rect_l_intersect - nr_rect_l_union - nr_rgradient_renderer_setup - nr_svp_bbox - nr_svp_free - nr_svp_point_distance - nr_svp_point_wind - nr_type_is_a - nr_vertex_free_list - nr_vertex_free_one - nr_vertex_new - nr_vertex_new_xy - nr_vertex_reverse_list diff --git a/src/libnr/nr-convert2geom.h b/src/libnr/nr-convert2geom.h index 75098ce2b..7e2423ea6 100644 --- a/src/libnr/nr-convert2geom.h +++ b/src/libnr/nr-convert2geom.h @@ -10,34 +10,14 @@ */ #include <libnr/nr-rect.h> -#include <libnr/nr-point.h> -#include <2geom/affine.h> -#include <2geom/d2.h> -#include <2geom/transforms.h> -#include <2geom/point.h> +#include <2geom/rect.h> -inline Geom::Point to_2geom(NR::Point const & _pt) { - return Geom::Point(_pt[0], _pt[1]); -} -inline NR::Point from_2geom(Geom::Point const & _pt) { - return NR::Point(_pt[0], _pt[1]); -} - -inline Geom::Rect to_2geom(NR::Rect const & rect) { - Geom::Rect rect2geom(to_2geom(rect.min()), to_2geom(rect.max())); - return rect2geom; -} -inline NR::Rect from_2geom(Geom::Rect const & rect2geom) { - NR::Rect rect(rect2geom.min(), rect2geom.max()); - return rect; -} -inline Geom::OptRect to_2geom(boost::optional<NR::Rect> const & rect) { - Geom::OptRect rect2geom; - if (!rect) { - return rect2geom; - } - rect2geom = to_2geom(*rect); - return rect2geom; +inline Geom::OptRect to_2geom(NRRect const *nr) { + Geom::OptRect ret; + if (!nr) return ret; + if (nr->x1 < nr->x0 || nr->y1 < nr->y0) return ret; + ret = Geom::Rect(Geom::Point(nr->x0, nr->y0), Geom::Point(nr->x1, nr->y1)); + return ret; } #endif diff --git a/src/libnr/nr-coord.h b/src/libnr/nr-coord.h deleted file mode 100644 index e094caeb3..000000000 --- a/src/libnr/nr-coord.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SEEN_NR_COORD_H -#define SEEN_NR_COORD_H - -namespace NR { - -/** - * A "real" type with sufficient precision for coordinates. - * - * You may safely assume that double (or even float) provides enough precision for storing - * on-canvas points, and hence that double provides enough precision for dot products of - * differences of on-canvas points. - */ -typedef double Coord; - -} /* namespace NR */ - - -#endif /* !SEEN_NR_COORD_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-dim2.h b/src/libnr/nr-dim2.h deleted file mode 100644 index c068bc220..000000000 --- a/src/libnr/nr-dim2.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SEEN_NR_DIM2_H -#define SEEN_NR_DIM2_H - -namespace NR { - -enum Dim2 { X=0, Y }; - -} /* namespace NR */ - - -#endif /* !SEEN_NR_DIM2_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-forward.h b/src/libnr/nr-forward.h index 82e29030c..4895ad407 100644 --- a/src/libnr/nr-forward.h +++ b/src/libnr/nr-forward.h @@ -10,20 +10,10 @@ * This code is in public domain */ -namespace NR { -class Matrix; -class Point; -class Rect; -class rotate; -class scale; -class translate; -} - struct NRPixBlock; struct NRRect; struct NRRectL; - #endif /* diff --git a/src/libnr/nr-i-coord.h b/src/libnr/nr-i-coord.h deleted file mode 100644 index a19d2ca46..000000000 --- a/src/libnr/nr-i-coord.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SEEN_NR_I_COORD_H -#define SEEN_NR_I_COORD_H - -#include <glib/gtypes.h> - -namespace NR { - -/** An integer type with sufficient precision for coordinates. */ -typedef gint32 ICoord; - -} /* namespace NR */ - - -#endif /* !SEEN_NR_I_COORD_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-point-fns-test.h b/src/libnr/nr-point-fns-test.h deleted file mode 100644 index df166660c..000000000 --- a/src/libnr/nr-point-fns-test.h +++ /dev/null @@ -1,139 +0,0 @@ -// nr-point-fns-test.h -#include <cxxtest/TestSuite.h> - -#include <cassert> -#include <cmath> -#include <glib/gmacros.h> -#include <stdlib.h> - -#include "libnr/nr-point-fns.h" -#include "2geom/isnan.h" - -class NrPointFnsTest : public CxxTest::TestSuite -{ -public: - NrPointFnsTest() : - setupValid(true), - p3n4( 3.0, -4.0 ), - p0( 0.0, 0.0 ), - small( pow( 2.0, -1070 ) ), - inf( 1e400 ), - nan( inf - inf ), - small_left( -small, 0.0 ), - small_n3_4( -3.0 * small, 4.0 * small ), - part_nan( 3., nan ), - inf_left( -inf, 5.0 ) - { - TS_ASSERT( IS_NAN(nan) ); - TS_ASSERT( !IS_NAN(small) ); - - setupValid &= IS_NAN(nan); - setupValid &= !IS_NAN(small); - } - virtual ~NrPointFnsTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrPointFnsTest *createSuite() { return new NrPointFnsTest(); } - static void destroySuite( NrPointFnsTest *suite ) { delete suite; } - -// Called before each test in this suite - void setUp() - { - TS_ASSERT( setupValid ); - } - - bool setupValid; - NR::Point const p3n4; - NR::Point const p0; - double const small; - double const inf; - double const nan; - - NR::Point const small_left; - NR::Point const small_n3_4; - NR::Point const part_nan; - NR::Point const inf_left; - - - void testL1(void) - { - TS_ASSERT_EQUALS( NR::L1(p0), 0.0 ); - TS_ASSERT_EQUALS( NR::L1(p3n4), 7.0 ); - TS_ASSERT_EQUALS( NR::L1(small_left), small ); - TS_ASSERT_EQUALS( NR::L1(inf_left), inf ); - TS_ASSERT_EQUALS( NR::L1(small_n3_4), 7.0 * small ); - TS_ASSERT(IS_NAN(NR::L1(part_nan))); - } - - void testL2(void) - { - TS_ASSERT_EQUALS( NR::L2(p0), 0.0 ); - TS_ASSERT_EQUALS( NR::L2(p3n4), 5.0 ); - TS_ASSERT_EQUALS( NR::L2(small_left), small ); - TS_ASSERT_EQUALS( NR::L2(inf_left), inf ); - TS_ASSERT_EQUALS( NR::L2(small_n3_4), 5.0 * small ); - TS_ASSERT( IS_NAN(NR::L2(part_nan)) ); - } - - void testLInfty(void) - { - TS_ASSERT_EQUALS( NR::LInfty(p0), 0.0 ); - TS_ASSERT_EQUALS( NR::LInfty(p3n4), 4.0 ); - TS_ASSERT_EQUALS( NR::LInfty(small_left), small ); - TS_ASSERT_EQUALS( NR::LInfty(inf_left), inf ); - TS_ASSERT_EQUALS( NR::LInfty(small_n3_4), 4.0 * small ); - TS_ASSERT( IS_NAN(NR::LInfty(part_nan)) ); - } - - void testIsZero(void) - { - TS_ASSERT( NR::is_zero(p0) ); - TS_ASSERT( !NR::is_zero(p3n4) ); - TS_ASSERT( !NR::is_zero(small_left) ); - TS_ASSERT( !NR::is_zero(inf_left) ); - TS_ASSERT( !NR::is_zero(small_n3_4) ); - TS_ASSERT( !NR::is_zero(part_nan) ); - } - - void testAtan2(void) - { - TS_ASSERT_EQUALS( NR::atan2(p3n4), atan2(-4.0, 3.0) ); - TS_ASSERT_EQUALS( NR::atan2(small_left), atan2(0.0, -1.0) ); - TS_ASSERT_EQUALS( NR::atan2(small_n3_4), atan2(4.0, -3.0) ); - } - - void testUnitVector(void) - { - TS_ASSERT_EQUALS( NR::unit_vector(p3n4), NR::Point(.6, -0.8) ); - TS_ASSERT_EQUALS( NR::unit_vector(small_left), NR::Point(-1.0, 0.0) ); - TS_ASSERT_EQUALS( NR::unit_vector(small_n3_4), NR::Point(-.6, 0.8) ); - } - - void testIsUnitVector(void) - { - TS_ASSERT( !NR::is_unit_vector(p3n4) ); - TS_ASSERT( !NR::is_unit_vector(small_left) ); - TS_ASSERT( !NR::is_unit_vector(small_n3_4) ); - TS_ASSERT( !NR::is_unit_vector(part_nan) ); - TS_ASSERT( !NR::is_unit_vector(inf_left) ); - TS_ASSERT( !NR::is_unit_vector(NR::Point(.5, 0.5)) ); - TS_ASSERT( NR::is_unit_vector(NR::Point(.6, -0.8)) ); - TS_ASSERT( NR::is_unit_vector(NR::Point(-.6, 0.8)) ); - TS_ASSERT( NR::is_unit_vector(NR::Point(-1.0, 0.0)) ); - TS_ASSERT( NR::is_unit_vector(NR::Point(1.0, 0.0)) ); - TS_ASSERT( NR::is_unit_vector(NR::Point(0.0, -1.0)) ); - TS_ASSERT( NR::is_unit_vector(NR::Point(0.0, 1.0)) ); - } -}; - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-point-fns.cpp b/src/libnr/nr-point-fns.cpp index ac58eddb7..a2e74c112 100644 --- a/src/libnr/nr-point-fns.cpp +++ b/src/libnr/nr-point-fns.cpp @@ -1,72 +1,11 @@ -#include <libnr/nr-point-fns.h> -#include <2geom/math-utils.h> +#include "libnr/nr-point-fns.h" -using NR::Point; - -/** Compute the L infinity, or maximum, norm of \a p. */ -NR::Coord NR::LInfty(Point const &p) { - NR::Coord const a(fabs(p[0])); - NR::Coord const b(fabs(p[1])); - return ( a < b || IS_NAN(b) - ? b - : a ); -} - -/** Returns true iff p is a zero vector, i.e.\ Point(0, 0). - * - * (NaN is considered non-zero.) - */ -bool -NR::is_zero(Point const &p) -{ - return ( p[0] == 0 && - p[1] == 0 ); -} - -bool -NR::is_unit_vector(Point const &p) -{ - return fabs(1.0 - L2(p)) <= 1e-4; - /* The tolerance of 1e-4 is somewhat arbitrary. NR::Point::normalize is believed to return - points well within this tolerance. I'm not aware of any callers that want a small - tolerance; most callers would be ok with a tolerance of 0.25. */ -} - -NR::Coord NR::atan2(Point const p) { - return std::atan2(p[NR::Y], p[NR::X]); -} - -/** Returns a version of \a a scaled to be a unit vector (within rounding error). - * - * The current version tries to handle infinite coordinates gracefully, - * but it's not clear that any callers need that. - * - * \pre a != Point(0, 0). - * \pre Neither coordinate is NaN. - * \post L2(ret) very near 1.0. - */ -Point NR::unit_vector(Point const &a) -{ - Point ret(a); - ret.normalize(); - return ret; -} - -NR::Point abs(NR::Point const &b) -{ - NR::Point ret; - for ( int i = 0 ; i < 2 ; i++ ) { - ret[i] = fabs(b[i]); - } - return ret; -} - -NR::Point -snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap) +Geom::Point +snap_vector_midpoint (Geom::Point const &p, Geom::Point const &begin, Geom::Point const &end, double snap) { - double length = NR::L2(end - begin); - NR::Point be = (end - begin) / length; - double r = NR::dot(p - begin, be); + double length = Geom::distance(begin, end); + Geom::Point be = (end - begin) / length; + double r = Geom::dot(p - begin, be); if (r < 0.0) return begin; if (r > length) return end; @@ -78,11 +17,11 @@ snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap) } double -get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end) +get_offset_between_points (Geom::Point const &p, Geom::Point const &begin, Geom::Point const &end) { - double length = NR::L2(end - begin); - NR::Point be = (end - begin) / length; - double r = NR::dot(p - begin, be); + double length = Geom::distance(begin, end); + Geom::Point be = (end - begin) / length; + double r = Geom::dot(p - begin, be); if (r < 0.0) return 0.0; if (r > length) return 1.0; @@ -90,8 +29,8 @@ get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end) return (r / length); } -NR::Point -project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2) +Geom::Point +project_on_linesegment(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2) { // p_proj = projection of p on the linesegment running from p1 to p2 // p_proj = p1 + u (p2 - p1) @@ -104,9 +43,9 @@ project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2 return p; } - NR::Point const d1(p-p1); // delta 1 - NR::Point const d2(p2-p1); // delta 2 - double const u = (d1[NR::X] * d2[NR::X] + d1[NR::Y] * d2[NR::Y]) / (NR::L2(d2) * NR::L2(d2)); + Geom::Point d1(p-p1); // delta 1 + Geom::Point d2(p2-p1); // delta 2 + double u = Geom::dot(d1, d2) / Geom::L2sq(d2); return (p1 + u*(p2-p1)); } diff --git a/src/libnr/nr-point-fns.h b/src/libnr/nr-point-fns.h index 05c4f718c..b26c969aa 100644 --- a/src/libnr/nr-point-fns.h +++ b/src/libnr/nr-point-fns.h @@ -1,100 +1,13 @@ #ifndef __NR_POINT_OPS_H__ #define __NR_POINT_OPS_H__ -#include <libnr/nr-point-ops.h> -#include <libnr/nr-dim2.h> -#include <libnr/nr-macros.h> +#include <2geom/point.h> -namespace NR { +Geom::Point snap_vector_midpoint (Geom::Point const &p, Geom::Point const &begin, Geom::Point const &end, double snap); -/** Compute the L1 norm, or manhattan distance, of \a p. */ -inline Coord L1(Point const &p) { - Coord d = 0; - for ( int i = 0 ; i < 2 ; i++ ) { - d += fabs(p[i]); - } - return d; -} +double get_offset_between_points (Geom::Point const &p, Geom::Point const &begin, Geom::Point const &end); -/** Compute the L2, or euclidean, norm of \a p. */ -inline Coord L2(Point const &p) { - return hypot(p[0], p[1]); -} - -extern double LInfty(Point const &p); - -bool is_zero(Point const &p); - -bool is_unit_vector(Point const &p); - -extern double atan2(Point const p); - -inline bool point_equalp(Point const &a, Point const &b, double const eps) -{ - return ( NR_DF_TEST_CLOSE(a[X], b[X], eps) && - NR_DF_TEST_CLOSE(a[Y], b[Y], eps) ); -} - -/** Returns p * NR::rotate_degrees(90), but more efficient. - * - * Angle direction in Inkscape code: If you use the traditional mathematics convention that y - * increases upwards, then positive angles are anticlockwise as per the mathematics convention. If - * you take the common non-mathematical convention that y increases downwards, then positive angles - * are clockwise, as is common outside of mathematics. - * - * There is no rot_neg90 function: use -rot90(p) instead. - */ -inline Point rot90(Point const &p) -{ - return Point(-p[Y], p[X]); -} - -/** Given two points and a parameter t \in [0, 1], return a point - * proportionally from a to b by t. */ -inline Point Lerp(double const t, Point const a, Point const b) -{ - return ( ( 1 - t ) * a - + t * b ); -} - -Point unit_vector(Point const &a); - -inline Coord dot(Point const &a, Point const &b) -{ - Coord ret = 0; - for ( int i = 0 ; i < 2 ; i++ ) { - ret += a[i] * b[i]; - } - return ret; -} - -inline Coord distance (Point const &a, Point const &b) -{ - Coord ret = 0; - for ( int i = 0 ; i < 2 ; i++ ) { - ret += (a[i] - b[i]) * (a[i] - b[i]); - } - return sqrt (ret); -} - -/** Defined as dot(a, b.cw()). */ -inline Coord cross(Point const &a, Point const &b) -{ - Coord ret = 0; - ret -= a[0] * b[1]; - ret += a[1] * b[0]; - return ret; -} - -Point abs(Point const &b); - -} /* namespace NR */ - -NR::Point snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap); - -double get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end); - -NR::Point project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2); +Geom::Point project_on_linesegment(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2); #endif /* !__NR_POINT_OPS_H__ */ diff --git a/src/libnr/nr-point-l.h b/src/libnr/nr-point-l.h deleted file mode 100644 index 9bfe2c790..000000000 --- a/src/libnr/nr-point-l.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef SEEN_NR_POINT_L_H -#define SEEN_NR_POINT_L_H - -#include <stdexcept> -#include <libnr/nr-i-coord.h> -#include <libnr/nr-point.h> - -struct NRPointL { - NR::ICoord x, y; -}; - -namespace NR { - -class IPoint { -public: - IPoint() - { } - - IPoint(ICoord x, ICoord y) { - _pt[X] = x; - _pt[Y] = y; - } - - IPoint(NRPointL const &p) { - _pt[X] = p.x; - _pt[Y] = p.y; - } - - IPoint(IPoint const &p) { - for (unsigned i = 0; i < 2; ++i) { - _pt[i] = p._pt[i]; - } - } - - IPoint &operator=(IPoint const &p) { - for (unsigned i = 0; i < 2; ++i) { - _pt[i] = p._pt[i]; - } - return *this; - } - - operator Point() { - return Point(_pt[X], _pt[Y]); - } - - ICoord operator[](unsigned i) const throw(std::out_of_range) { - if ( i > Y ) { - throw std::out_of_range("index out of range"); - } - return _pt[i]; - } - - ICoord &operator[](unsigned i) throw(std::out_of_range) { - if ( i > Y ) { - throw std::out_of_range("index out of range"); - } - return _pt[i]; - } - - ICoord operator[](Dim2 d) const throw() { return _pt[d]; } - ICoord &operator[](Dim2 d) throw() { return _pt[d]; } - - IPoint &operator+=(IPoint const &o) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] += o._pt[i]; - } - return *this; - } - - IPoint &operator-=(IPoint const &o) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] -= o._pt[i]; - } - return *this; - } - - bool operator==(IPoint const &other) const { - return _pt[X] == other[X] && _pt[Y] == other[Y]; - } - - bool operator!=(IPoint const &other) const { - return _pt[X] != other[X] || _pt[Y] != other[Y]; - } - -private: - ICoord _pt[2]; -}; - - -} // namespace NR - -#endif /* !SEEN_NR_POINT_L_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-point-ops.h b/src/libnr/nr-point-ops.h deleted file mode 100644 index aba981803..000000000 --- a/src/libnr/nr-point-ops.h +++ /dev/null @@ -1,88 +0,0 @@ -/* operator functions for NR::Point. */ -#ifndef SEEN_NR_POINT_OPS_H -#define SEEN_NR_POINT_OPS_H - -#include <libnr/nr-point.h> - -namespace NR { - -inline Point operator+(Point const &a, Point const &b) -{ - Point ret; - for (int i = 0; i < 2; i++) { - ret[i] = a[i] + b[i]; - } - return ret; -} - -inline Point operator-(Point const &a, Point const &b) -{ - Point ret; - for (int i = 0; i < 2; i++) { - ret[i] = a[i] - b[i]; - } - return ret; -} - -/** This is a rotation (sort of). */ -inline Point operator^(Point const &a, Point const &b) -{ - Point const ret(a[0] * b[0] - a[1] * b[1], - a[1] * b[0] + a[0] * b[1]); - return ret; -} - -inline Point operator-(Point const &a) -{ - Point ret; - for(unsigned i = 0; i < 2; i++) { - ret[i] = -a[i]; - } - return ret; -} - -inline Point operator*(double const s, Point const &b) -{ - Point ret; - for(int i = 0; i < 2; i++) { - ret[i] = s * b[i]; - } - return ret; -} - -inline Point operator/(Point const &b, double const d) -{ - Point ret; - for(int i = 0; i < 2; i++) { - ret[i] = b[i] / d; - } - return ret; -} - - -inline bool operator==(Point const &a, Point const &b) -{ - return ( ( a[X] == b[X] ) && ( a[Y] == b[Y] ) ); -} - -inline bool operator!=(Point const &a, Point const &b) -{ - return ( ( a[X] != b[X] ) || ( a[Y] != b[Y] ) ); -} - - -} /* namespace NR */ - - -#endif /* !SEEN_NR_POINT_OPS_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-point.h b/src/libnr/nr-point.h deleted file mode 100644 index 19add7dd1..000000000 --- a/src/libnr/nr-point.h +++ /dev/null @@ -1,155 +0,0 @@ -#ifndef SEEN_NR_POINT_H -#define SEEN_NR_POINT_H - -/** \file - * Cartesian point class. - */ - -//#include <math.h> -//#include <stdexcept> -#include <iostream> -//#include <iomanip> - -#include <libnr/nr-coord.h> -#include <libnr/nr-dim2.h> -#include <libnr/nr-forward.h> - -//#include "round.h" -#include "decimal-round.h" - -#include <2geom/point.h> - -namespace NR { - -/// Cartesian point. -class Point { -public: - inline Point() - { _pt[X] = _pt[Y] = 0; } - - inline Point(Coord x, Coord y) { - _pt[X] = x; - _pt[Y] = y; - } - - inline Point(Point const &p) { - for (unsigned i = 0; i < 2; ++i) { - _pt[i] = p._pt[i]; - } - } - - inline Point(Geom::Point const &p) { - _pt[X] = p[Geom::X]; - _pt[Y] = p[Geom::Y]; - } - - inline Point &operator=(Point const &p) { - for (unsigned i = 0; i < 2; ++i) { - _pt[i] = p._pt[i]; - } - return *this; - } - - inline Coord operator[](unsigned i) const { - return _pt[i]; - } - - inline Coord &operator[](unsigned i) { - return _pt[i]; - } - - Coord operator[](Dim2 d) const throw() { return _pt[d]; } - Coord &operator[](Dim2 d) throw() { return _pt[d]; } - - /** Return a point like this point but rotated -90 degrees. - (If the y axis grows downwards and the x axis grows to the - right, then this is 90 degrees counter-clockwise.) - **/ - Point ccw() const { - return Point(_pt[Y], -_pt[X]); - } - - /** Return a point like this point but rotated +90 degrees. - (If the y axis grows downwards and the x axis grows to the - right, then this is 90 degrees clockwise.) - **/ - Point cw() const { - return Point(-_pt[Y], _pt[X]); - } - - /** - \brief A function to lower the precision of the point - \param places The number of decimal places that should be in - the final number. - */ - inline void round (int places = 0) { - _pt[X] = (Coord)(Inkscape::decimal_round((double)_pt[X], places)); - _pt[Y] = (Coord)(Inkscape::decimal_round((double)_pt[Y], places)); - return; - } - - void normalize(); - - inline Point &operator+=(Point const &o) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] += o._pt[i]; - } - return *this; - } - - inline Point &operator-=(Point const &o) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] -= o._pt[i]; - } - return *this; - } - - inline Point &operator/=(double const s) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] /= s; - } - return *this; - } - - inline Point &operator*=(double const s) { - for ( unsigned i = 0 ; i < 2 ; ++i ) { - _pt[i] *= s; - } - return *this; - } - - Point &operator*=(Matrix const &m); - - inline int operator == (const Point &in_pnt) { - return ((_pt[X] == in_pnt[X]) && (_pt[Y] == in_pnt[Y])); - } - - friend inline std::ostream &operator<< (std::ostream &out_file, const NR::Point &in_pnt); - - inline operator Geom::Point() const { return Geom::Point(_pt[X], _pt[Y]); } - -private: - Coord _pt[2]; -}; - -/** A function to print out the Point. It just prints out the coords - on the given output stream */ -inline std::ostream &operator<< (std::ostream &out_file, const NR::Point &in_pnt) { - out_file << "X: " << in_pnt[X] << " Y: " << in_pnt[Y]; - return out_file; -} - -} /* namespace NR */ - -#endif /* !SEEN_NR_POINT_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-rect-l.cpp b/src/libnr/nr-rect-l.cpp index 9d1f80988..08910a1d6 100644 --- a/src/libnr/nr-rect-l.cpp +++ b/src/libnr/nr-rect-l.cpp @@ -1,23 +1,3 @@ -#include <libnr/nr-rect-l.h> - -boost::optional<NR::Rect> NRRectL::upgrade() const { - if (nr_rect_l_test_empty_ptr(this)) { - return boost::optional<NR::Rect>(); - } else { - return NR::Rect(NR::Point(x0, y0), NR::Point(x1, y1)); - } -} - -namespace NR { - -IRect::IRect(Rect const &r) : - _min(int(floor(r.min()[X])), int(floor(r.min()[Y]))), - _max(int(ceil(r.min()[X])), int(ceil(r.min()[Y]))) -{ -} - -} - /* Local Variables: mode:c++ diff --git a/src/libnr/nr-rect-l.h b/src/libnr/nr-rect-l.h index 3493fa8f4..6e82bb790 100644 --- a/src/libnr/nr-rect-l.h +++ b/src/libnr/nr-rect-l.h @@ -1,132 +1,12 @@ #ifndef SEEN_NR_RECT_L_H #define SEEN_NR_RECT_L_H -#include <libnr/nr-i-coord.h> -#include <boost/optional.hpp> -#include <libnr/nr-rect.h> -#include <libnr/nr-point-l.h> +#include <glib.h> struct NRRectL { - boost::optional<NR::Rect> upgrade() const; - NR::ICoord x0, y0, x1, y1; + gint32 x0, y0, x1, y1; }; - -namespace NR { - - -class IRect { -public: - IRect(const NRRectL& r) : _min(r.x0, r.y0), _max(r.x1, r.y1) {} - IRect(const IRect& r) : _min(r._min), _max(r._max) {} - IRect(const IPoint &p0, const IPoint &p1) : _min(p0), _max(p1) {} - - /** as not all Rects are representable by IRects this gives the smallest IRect that contains - * r. */ - IRect(const Rect& r); - - operator Rect() { - return Rect(Point(_min), Point(_max)); - } - - const IPoint &min() const { return _min; } - const IPoint &max() const { return _max; } - - /** returns a vector from min to max. */ - IPoint dimensions() const; - - /** does this rectangle have zero area? */ - bool isEmpty() const { - return isEmpty<X>() && isEmpty<Y>(); - } - - bool intersects(const IRect &r) const { - return intersects<X>(r) && intersects<Y>(r); - } - bool contains(const IRect &r) const { - return contains<X>(r) && contains<Y>(r); - } - bool contains(const IPoint &p) const { - return contains<X>(p) && contains<Y>(p); - } - - ICoord maxExtent() const { - return MAX(extent<X>(), extent<Y>()); - } - - ICoord extent(Dim2 axis) const { - switch (axis) { - case X: return extent<X>(); - case Y: return extent<Y>(); - }; - } - - ICoord extent(unsigned i) const throw(std::out_of_range) { - switch (i) { - case 0: return extent<X>(); - case 1: return extent<Y>(); - default: throw std::out_of_range("Dimension out of range"); - }; - } - - /** Translates the rectangle by p. */ - void offset(IPoint p); - - /** Makes this rectangle large enough to include the point p. */ - void expandTo(IPoint p); - - /** Makes this rectangle large enough to include the rectangle r. */ - void expandTo(const IRect &r); - - /** Returns the set of points shared by both rectangles. */ - static boost::optional<IRect> intersection(const IRect &a, const IRect &b); - - /** Returns the smallest rectangle that encloses both rectangles. */ - static IRect union_bounds(const IRect &a, const IRect &b); - - bool operator==(const IRect &other) const { - return (min() == other.min()) && (max() == other.max()); - } - - bool operator!=(const IRect &other) const { - return (min() != other.min()) || (max() != other.max()); - } - -private: - IRect() {} - - template <NR::Dim2 axis> - ICoord extent() const { - return _max[axis] - _min[axis]; - } - - template <Dim2 axis> - bool isEmpty() const { - return !( _min[axis] < _max[axis] ); - } - - template <Dim2 axis> - bool intersects(const IRect &r) const { - return _max[axis] >= r._min[axis] && _min[axis] <= r._max[axis]; - } - - template <Dim2 axis> - bool contains(const IRect &r) const { - return contains(r._min) && contains(r._max); - } - - template <Dim2 axis> - bool contains(const IPoint &p) const { - return p[axis] >= _min[axis] && p[axis] <= _max[axis]; - } - - IPoint _min, _max; -}; - - - -} // namespace NR - #endif /* !SEEN_NR_RECT_L_H */ /* diff --git a/src/libnr/nr-rect-ops.h b/src/libnr/nr-rect-ops.h deleted file mode 100644 index 870091a94..000000000 --- a/src/libnr/nr-rect-ops.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SEEN_NR_RECT_OPS_H -#define SEEN_NR_RECT_OPS_H - -/* - * Rect operators - * - * Copyright 2004 MenTaLguY <mental@rydia.net>, - * bulia byak <buliabyak@users.sf.net> - * - * This code is licensed under the GNU GPL; see COPYING for more information. - */ - -#include <libnr/nr-rect.h> - -namespace NR { - -inline Rect expand(Rect const &r, double by) { - NR::Point const p(by, by); - return Rect(r.min() + p, r.max() - p); -} - -inline Rect expand(Rect const &r, NR::Point by) { - return Rect(r.min() + by, r.max() - by); -} - -#if 0 -inline ConvexHull operator*(Rect const &r, Matrix const &m) { - /* FIXME: no mention of m. Should probably be made non-inline. */ - ConvexHull points(r.corner(0)); - for ( unsigned i = 1 ; i < 4 ; i++ ) { - points.add(r.corner(i)); - } - return points; -} -#endif - -} /* namespace NR */ - - -#endif /* !SEEN_NR_RECT_OPS_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index 8e3672e03..67857ad49 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -9,25 +9,9 @@ * This code is in public domain */ -#include "nr-rect-l.h" #include <algorithm> -#include "nr-point-ops.h" - -NRRect::NRRect(NR::Rect const &rect) -: x0(rect.min()[NR::X]), y0(rect.min()[NR::Y]), - x1(rect.max()[NR::X]), y1(rect.max()[NR::Y]) -{} - -NRRect::NRRect(boost::optional<NR::Rect> const &rect) { - if (rect) { - x0 = rect->min()[NR::X]; - y0 = rect->min()[NR::Y]; - x1 = rect->max()[NR::X]; - y1 = rect->max()[NR::Y]; - } else { - nr_rect_d_set_empty(this); - } -} +#include "nr-rect.h" +#include "nr-rect-l.h" NRRect::NRRect(Geom::OptRect const &rect) { if (rect) { @@ -36,20 +20,12 @@ NRRect::NRRect(Geom::OptRect const &rect) { x1 = rect->max()[Geom::X]; y1 = rect->max()[Geom::Y]; } else { - nr_rect_d_set_empty(this); - } -} - -boost::optional<NR::Rect> NRRect::upgrade() const { - if (nr_rect_d_test_empty_ptr(this)) { - return boost::optional<NR::Rect>(); - } else { - return NR::Rect(NR::Point(x0, y0), NR::Point(x1, y1)); + *this = NR_RECT_EMPTY; } } Geom::OptRect NRRect::upgrade_2geom() const { - if (nr_rect_d_test_empty_ptr(this)) { + if (x0 > x1 || y0 > y1) { return Geom::OptRect(); } else { return Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)); @@ -65,7 +41,7 @@ Geom::OptRect NRRect::upgrade_2geom() const { NRRectL *nr_rect_l_intersect(NRRectL *d, const NRRectL *r0, const NRRectL *r1) { - NR::ICoord t; + gint32 t; t = std::max(r0->x0, r1->x0); d->x1 = std::min(r0->x1, r1->x1); d->x0 = t; @@ -79,7 +55,7 @@ NRRectL *nr_rect_l_intersect(NRRectL *d, const NRRectL *r0, const NRRectL *r1) NRRect * nr_rect_d_intersect (NRRect *d, const NRRect *r0, const NRRect *r1) { - NR::Coord t; + gint32 t; t = MAX (r0->x0, r1->x0); d->x1 = MIN (r0->x1, r1->x1); d->x0 = t; @@ -100,7 +76,7 @@ nr_rect_l_subtract(NRRectL *d, NRRectL const *r0, NRRectL const *r1) bool inside4 = nr_rect_l_test_inside(r1, r0->x0, r0->y1); if (inside1 && inside2 && inside3) { - nr_rect_l_set_empty (d); + *d = NR_RECT_L_EMPTY; } else if (inside1 && inside2) { d->x0 = r0->x0; @@ -136,7 +112,7 @@ nr_rect_l_subtract(NRRectL *d, NRRectL const *r0, NRRectL const *r1) return d; } -NR::ICoord nr_rect_l_area(NRRectL *r) +gint32 nr_rect_l_area(NRRectL *r) { if (!r || NR_RECT_DFLS_TEST_EMPTY (r)) { return 0; @@ -149,7 +125,7 @@ nr_rect_d_union (NRRect *d, const NRRect *r0, const NRRect *r1) { if (NR_RECT_DFLS_TEST_EMPTY (r0)) { if (NR_RECT_DFLS_TEST_EMPTY (r1)) { - nr_rect_d_set_empty (d); + *d = NR_RECT_EMPTY; } else { *d = *r1; } @@ -157,7 +133,7 @@ nr_rect_d_union (NRRect *d, const NRRect *r0, const NRRect *r1) if (NR_RECT_DFLS_TEST_EMPTY (r1)) { *d = *r0; } else { - NR::Coord t; + double t; t = MIN (r0->x0, r1->x0); d->x1 = MAX (r0->x1, r1->x1); d->x0 = t; @@ -174,7 +150,7 @@ nr_rect_l_union (NRRectL *d, const NRRectL *r0, const NRRectL *r1) { if (NR_RECT_DFLS_TEST_EMPTY (r0)) { if (NR_RECT_DFLS_TEST_EMPTY (r1)) { - nr_rect_l_set_empty (d); + *d = NR_RECT_L_EMPTY; } else { *d = *r1; } @@ -182,7 +158,7 @@ nr_rect_l_union (NRRectL *d, const NRRectL *r0, const NRRectL *r1) if (NR_RECT_DFLS_TEST_EMPTY (r1)) { *d = *r0; } else { - NR::ICoord t; + double t; t = MIN (r0->x0, r1->x0); d->x1 = MAX (r0->x1, r1->x1); d->x0 = t; @@ -195,16 +171,13 @@ nr_rect_l_union (NRRectL *d, const NRRectL *r0, const NRRectL *r1) } NRRect * -nr_rect_union_pt(NRRect *dst, NR::Point const &p) +nr_rect_union_pt(NRRect *dst, Geom::Point const &p) { - using NR::X; - using NR::Y; - - return nr_rect_d_union_xy(dst, p[X], p[Y]); + return nr_rect_d_union_xy(dst, p[Geom::X], p[Geom::Y]); } NRRect * -nr_rect_d_union_xy (NRRect *d, NR::Coord x, NR::Coord y) +nr_rect_d_union_xy (NRRect *d, double x, double y) { if ((d->x0 <= d->x1) && (d->y0 <= d->y1)) { d->x0 = MIN (d->x0, x); @@ -218,147 +191,6 @@ nr_rect_d_union_xy (NRRect *d, NR::Coord x, NR::Coord y) return d; } -// TODO investigate for removal: -NRRect *nr_rect_d_matrix_transform(NRRect *d, NRRect const *const /*s*/, NR::Matrix const & /*m*/) -{ - // defunct - /* - using NR::X; - using NR::Y; - - if (nr_rect_d_test_empty_ptr(s)) { - nr_rect_d_set_empty(d); - } else { - NR::Point const c00(NR::Point(s->x0, s->y0) * m); - NR::Point const c01(NR::Point(s->x0, s->y1) * m); - NR::Point const c10(NR::Point(s->x1, s->y0) * m); - NR::Point const c11(NR::Point(s->x1, s->y1) * m); - d->x0 = std::min(std::min(c00[X], c01[X]), - std::min(c10[X], c11[X])); - d->y0 = std::min(std::min(c00[Y], c01[Y]), - std::min(c10[Y], c11[Y])); - d->x1 = std::max(std::max(c00[X], c01[X]), - std::max(c10[X], c11[X])); - d->y1 = std::max(std::max(c00[Y], c01[Y]), - std::max(c10[Y], c11[Y])); - }*/ - return d; -} - -NRRect * -nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NR::Matrix const *m) -{ - return nr_rect_d_matrix_transform(d, s, *m); -} - -/** Enlarges the rectangle given amount of pixels to all directions */ -NRRectL * -nr_rect_l_enlarge(NRRectL *d, int amount) -{ - d->x0 -= amount; - d->y0 -= amount; - d->x1 += amount; - d->y1 += amount; - return d; -} - -namespace NR { - -Rect::Rect(const Point &p0, const Point &p1) -: _min(std::min(p0[X], p1[X]), std::min(p0[Y], p1[Y])), - _max(std::max(p0[X], p1[X]), std::max(p0[Y], p1[Y])) -{} - -/** returns the four corners of the rectangle in the correct winding order */ -Point Rect::corner(unsigned i) const { - switch (i % 4) { - case 0: - return _min; - case 1: - return Point(_max[X], _min[Y]); - case 2: - return _max; - default: /* i.e. 3 */ - return Point(_min[X], _max[Y]); - } -} - -/** returns the midpoint of this rectangle */ -Point Rect::midpoint() const { - return ( _min + _max ) / 2; -} - -Point Rect::cornerFarthestFrom(Point const &p) const { - Point m = midpoint(); - unsigned i = 0; - if (p[X] < m[X]) { - i = 1; - } - if (p[Y] < m[Y]) { - i = 3 - i; - } - return corner(i); -} - -/** returns a vector from topleft to bottom right. */ -Point Rect::dimensions() const { - return _max - _min; -} - -/** Translates the rectangle by p. */ -void Rect::offset(Point p) { - _min += p; - _max += p; -} - -/** Makes this rectangle large enough to include the point p. */ -void Rect::expandTo(Point p) { - for ( int i=0 ; i < 2 ; i++ ) { - _min[i] = std::min(_min[i], p[i]); - _max[i] = std::max(_max[i], p[i]); - } -} - -void Rect::growBy(double size) { - for ( unsigned d = 0 ; d < 2 ; d++ ) { - _min[d] -= size; - _max[d] += size; - if ( _min[d] > _max[d] ) { - _min[d] = _max[d] = ( _min[d] + _max[d] ) / 2; - } - } -} - -/** Returns the set of points shared by both rectangles. */ -boost::optional<Rect> intersection(boost::optional<Rect> const & a, boost::optional<Rect> const & b) { - if ( !a || !b ) { - return boost::optional<Rect>(); - } else { - Rect r; - for ( int i=0 ; i < 2 ; i++ ) { - r._min[i] = std::max(a->_min[i], b->_min[i]); - r._max[i] = std::min(a->_max[i], b->_max[i]); - if ( r._min[i] > r._max[i] ) { - return boost::optional<Rect>(); - } - } - return r; - } -} - -/** returns the smallest rectangle containing both rectangles */ -Rect union_bounds(Rect const &a, Rect const &b) { - Rect r; - for ( int i=0 ; i < 2 ; i++ ) { - r._min[i] = std::min(a._min[i], b._min[i]); - r._max[i] = std::max(a._max[i], b._max[i]); - } - return r; -} - -} // namespace NR - - /* Local Variables: mode:c++ diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h index aa5921309..4931b3e10 100644 --- a/src/libnr/nr-rect.h +++ b/src/libnr/nr-rect.h @@ -3,8 +3,7 @@ /** \file * Definitions of NRRect and NR::Rect types, and some associated functions \& macros. - */ -/* + *//* * Authors: * Lauris Kaplinski <lauris@kaplinski.com> * Nathan Hurst <njh@mail.csse.monash.edu.au> @@ -13,251 +12,33 @@ * This code is in public domain */ - #include <stdexcept> #include <limits> +#include <boost/optional.hpp> #include <glib.h> +#include <2geom/rect.h> +#include "libnr/nr-forward.h" #include "libnr/nr-values.h" -#include <libnr/nr-coord.h> -#include <libnr/nr-i-coord.h> -#include <libnr/nr-dim2.h> -#include <libnr/nr-point.h> -#include "libnr/nr-point-ops.h" #include "libnr/nr-macros.h" -#include <boost/optional.hpp> -#include <libnr/nr-forward.h> -#include <2geom/rect.h> - -namespace NR { - -class Matrix; - -/** A rectangle is always aligned to the X and Y axis. This means it - * can be defined using only 4 coordinates, and determining - * intersection is very efficient. The points inside a rectangle are - * min[dim] <= _pt[dim] <= max[dim]. A rectangle may be empty, in the - * sense of having zero area, but it will always contain at least one - * point. Infinities are also permitted. - */ -class Rect { -public: - Rect() : _min(-_inf(), -_inf()), _max(_inf(), _inf()) {} - Rect(Point const &p0, Point const &p1); - - Point const &min() const { return _min; } - Point const &max() const { return _max; } - - /** returns the four corners of the rectangle in order - * (clockwise if +Y is up, anticlockwise if +Y is down) */ - Point corner(unsigned i) const; - - /** returns a vector from min to max. */ - Point dimensions() const; - - /** returns the midpoint of this rect. */ - Point midpoint() const; - - Point cornerFarthestFrom(Point const &p) const; - - /** True iff either width or height is less than \a epsilon. */ - bool isEmpty(double epsilon=1e-6) const { - return isEmpty<X>(epsilon) || isEmpty<Y>(epsilon); - } - - bool intersects(Rect const &r) const { - return intersects<X>(r) && intersects<Y>(r); - } - bool contains(Rect const &r) const { - return contains<X>(r) && contains<Y>(r); - } - bool contains(Point const &p) const { - return contains<X>(p) && contains<Y>(p); - } - - double area() const { - return extent<X>() * extent<Y>(); - } - - double maxExtent() const { - return MAX(extent<X>(), extent<Y>()); - } - - double extent(Dim2 const axis) const { - switch (axis) { - case X: return extent<X>(); - case Y: return extent<Y>(); - default: g_error("invalid axis value %d", (int) axis); return 0; - }; - } - - double extent(unsigned i) const throw(std::out_of_range) { - switch (i) { - case 0: return extent<X>(); - case 1: return extent<Y>(); - default: throw std::out_of_range("Dimension out of range"); - }; - } - - /** - \brief Remove some precision from the Rect - \param places The number of decimal places left in the end - - This function just calls round on the \c _min and \c _max points. - */ - inline void round(int places = 0) { - _min.round(places); - _max.round(places); - return; - } - - /** Translates the rectangle by p. */ - void offset(Point p); - - /** Makes this rectangle large enough to include the point p. */ - void expandTo(Point p); - - /** Makes this rectangle large enough to include the rectangle r. */ - void expandTo(Rect const &r); - - inline void move_left (gdouble by) { - _min[NR::X] += by; - } - inline void move_right (gdouble by) { - _max[NR::X] += by; - } - inline void move_top (gdouble by) { - _min[NR::Y] += by; - } - inline void move_bottom (gdouble by) { - _max[NR::Y] += by; - } - - void growBy (gdouble by); - - /** Scales the rect by s, with origin at 0, 0 */ - inline Rect operator*(double const s) const { - return Rect(s * min(), s * max()); - } - - inline bool operator==(Rect const &in_rect) { - return ((this->min() == in_rect.min()) && (this->max() == in_rect.max())); - } - - friend inline std::ostream &operator<<(std::ostream &out_file, NR::Rect const &in_rect); - -private: -// Rect(Nothing) : _min(1, 1), _max(-1, -1) {} - - static double _inf() { - return std::numeric_limits<double>::infinity(); - } - - template <NR::Dim2 axis> - double extent() const { - return _max[axis] - _min[axis]; - } - - template <NR::Dim2 axis> - bool isEmpty(double epsilon) const { - return extent<axis>() < epsilon; - } - - template <Dim2 axis> - bool intersects(Rect const &r) const { - return _max[axis] >= r._min[axis] && _min[axis] <= r._max[axis]; - } - - template <Dim2 axis> - bool contains(Rect const &r) const { - return contains(r._min) && contains(r._max); - } - - template <Dim2 axis> - bool contains(Point const &p) const { - return p[axis] >= _min[axis] && p[axis] <= _max[axis]; - } - - Point _min, _max; - - friend boost::optional<Rect> intersection(boost::optional<Rect> const &, boost::optional<Rect> const &); - friend Rect union_bounds(Rect const &, Rect const &); -}; - -/** Returns the set of points shared by both rectangles. */ -boost::optional<Rect> intersection(boost::optional<Rect> const & a, boost::optional<Rect> const & b); - -/** Returns the smallest rectangle that encloses both rectangles. */ -Rect union_bounds(Rect const &a, Rect const &b); -inline Rect union_bounds(boost::optional<Rect> const & a, Rect const &b) { - if (a) { - return union_bounds(*a, b); - } else { - return b; - } -} -inline Rect union_bounds(Rect const &a, boost::optional<Rect> const & b) { - if (b) { - return union_bounds(a, *b); - } else { - return a; - } -} -inline boost::optional<Rect> union_bounds(boost::optional<Rect> const & a, boost::optional<Rect> const & b) -{ - if (!a) { - return b; - } else if (!b) { - return a; - } else { - return union_bounds(*a, *b); - } -} - -/** A function to print out the rectange if sent to an output - stream. */ -inline std::ostream -&operator<<(std::ostream &out_file, NR::Rect const &in_rect) -{ - out_file << "Rectangle:\n"; - out_file << "\tMin Point -> " << in_rect.min() << "\n"; - out_file << "\tMax Point -> " << in_rect.max() << "\n"; - - return out_file; -} - -} /* namespace NR */ /* legacy rect stuff */ - /* NULL rect is infinite */ struct NRRect { NRRect() : x0(0), y0(0), x1(0), y1(0) {} - NRRect(NR::Coord xmin, NR::Coord ymin, NR::Coord xmax, NR::Coord ymax) + NRRect(double xmin, double ymin, double xmax, double ymax) : x0(xmin), y0(ymin), x1(xmax), y1(ymax) {} - explicit NRRect(NR::Rect const &rect); - explicit NRRect(boost::optional<NR::Rect> const &rect); - operator boost::optional<NR::Rect>() const { return upgrade(); } - boost::optional<NR::Rect> upgrade() const; explicit NRRect(Geom::OptRect const &rect); operator Geom::OptRect() const { return upgrade_2geom(); } Geom::OptRect upgrade_2geom() const; - NR::Coord x0, y0, x1, y1; + double x0, y0, x1, y1; }; -#define nr_rect_d_set_empty(r) (*(r) = NR_RECT_EMPTY) -#define nr_rect_l_set_empty(r) (*(r) = NR_RECT_L_EMPTY) - -/** "Empty" here includes the case of zero width or zero height. */ -// TODO convert to static overloaded functions (pointer and ref) once performance can be tested: -#define nr_rect_d_test_empty_ptr(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r)) -#define nr_rect_d_test_empty(r) NR_RECT_DFLS_TEST_EMPTY_REF(r) - // TODO convert to static overloaded functions (pointer and ref) once performance can be tested: #define nr_rect_l_test_empty_ptr(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r)) #define nr_rect_l_test_empty(r) NR_RECT_DFLS_TEST_EMPTY_REF(r) @@ -282,7 +63,7 @@ struct NRRect { NRRectL *nr_rect_l_subtract(NRRectL *d, NRRectL const *r0, NRRectL const *r1); // returns the area of r -NR::ICoord nr_rect_l_area(NRRectL *r); +gint32 nr_rect_l_area(NRRectL *r); /* NULL values are OK for r0 and r1, but not for d */ NRRect *nr_rect_d_intersect(NRRect *d, NRRect const *r0, NRRect const *r1); @@ -291,13 +72,9 @@ NRRectL *nr_rect_l_intersect(NRRectL *d, NRRectL const *r0, NRRectL const *r1); NRRect *nr_rect_d_union(NRRect *d, NRRect const *r0, NRRect const *r1); NRRectL *nr_rect_l_union(NRRectL *d, NRRectL const *r0, NRRectL const *r1); -NRRect *nr_rect_union_pt(NRRect *dst, NR::Point const &p); -NRRect *nr_rect_d_union_xy(NRRect *d, NR::Coord x, NR::Coord y); -NRRectL *nr_rect_l_union_xy(NRRectL *d, NR::ICoord x, NR::ICoord y); - -NRRect *nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NR::Matrix const &m); -NRRect *nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NR::Matrix const *m); -NRRectL *nr_rect_l_enlarge(NRRectL *d, int amount); +NRRect *nr_rect_union_pt(NRRect *dst, Geom::Point const &p); +NRRect *nr_rect_d_union_xy(NRRect *d, double x, double y); +NRRectL *nr_rect_l_union_xy(NRRectL *d, gint32 x, gint32 y); #endif /* !LIBNR_NR_RECT_H_SEEN */ diff --git a/src/libnr/nr-render.h b/src/libnr/nr-render.h deleted file mode 100644 index 84215b7a3..000000000 --- a/src/libnr/nr-render.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __NR_RENDER_H__ -#define __NR_RENDER_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include <libnr/nr-pixblock.h> - -struct NRRenderer; - -typedef void (* NRRenderFunc) (NRRenderer *r, NRPixBlock *pb, NRPixBlock *m); - -struct NRRenderer { - NRRenderFunc render; -}; - -#define nr_render(r,pb,m) ((NRRenderer *) (r))->render ((NRRenderer *) (r), (pb), (m)) - -#endif diff --git a/src/libnr/nr-types-test.h b/src/libnr/nr-types-test.h deleted file mode 100644 index 77550351f..000000000 --- a/src/libnr/nr-types-test.h +++ /dev/null @@ -1,142 +0,0 @@ -// nr-types-test.h -#include <cxxtest/TestSuite.h> - -#include "libnr/nr-types.h" -#include "libnr/nr-point-fns.h" -#include <cmath> - -class NrTypesTest : public CxxTest::TestSuite -{ -public: - NrTypesTest() : - a( 1.5, 2.0 ), - b(-2.0, 3.0), - ab(-0.5, 5.0), - small(pow(2.0, -1070)), - small_left(-small, 0.0), - smallish_3_neg4(3.0 * small, -4.0 * small) - {} - virtual ~NrTypesTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrTypesTest *createSuite() { return new NrTypesTest(); } - static void destroySuite( NrTypesTest *suite ) { delete suite; } - - NR::Point const a; - NR::Point const b; - NR::Point const ab; - double const small; - NR::Point const small_left; - NR::Point const smallish_3_neg4; - - - void testXYValues( void ) - { - TS_ASSERT_EQUALS( NR::X, 0 ); - TS_ASSERT_EQUALS( NR::Y, 1 ); - } - - void testXYCtorAndArrayConst(void) - { - TS_ASSERT_EQUALS( a[NR::X], 1.5 ); - TS_ASSERT_EQUALS( a[NR::Y], 2.0 ); - } - - void testCopyCtor(void) - { - NR::Point a_copy(a); - - TS_ASSERT_EQUALS( a, a_copy ); - TS_ASSERT( !(a != a_copy) ); - } - - void testNonConstArrayOperator(void) - { - NR::Point a_copy(a); - a_copy[NR::X] = -2.0; - TS_ASSERT_DIFFERS( a_copy, a ); - TS_ASSERT_DIFFERS( a_copy, b ); - a_copy[NR::Y] = 3.0; - TS_ASSERT_EQUALS( a_copy, b ); - } - - void testBinaryPlusMinus(void) - { - TS_ASSERT_DIFFERS( a, b ); - TS_ASSERT_EQUALS( a + b, ab ); - TS_ASSERT_EQUALS( ab - a, b ); - TS_ASSERT_EQUALS( ab - b, a ); - TS_ASSERT_DIFFERS( ab + a, b ); - } - - void testUnaryMinus(void) - { - TS_ASSERT_EQUALS( -a, NR::Point(-a[NR::X], -a[NR::Y]) ); - } - - void tetScaleDivide(void) - { - TS_ASSERT_EQUALS( -a, -1.0 * a ); - TS_ASSERT_EQUALS( a + a + a, 3.0 * a ); - TS_ASSERT_EQUALS( a / .5, 2.0 * a ); - } - - void testDot(void) - { - TS_ASSERT_EQUALS( dot(a, b), ( a[NR::X] * b[NR::X] + - a[NR::Y] * b[NR::Y] ) ); - TS_ASSERT_EQUALS( dot(a, NR::rot90(a)), 0.0 ); - TS_ASSERT_EQUALS( dot(-a, NR::rot90(a)), 0.0 ); - } - - void testL1L2LInftyNorms(void) - { - // TODO look at TS_ASSERT_DELTA - - TS_ASSERT_EQUALS( L1(small_left), small ); - TS_ASSERT_EQUALS( L2(small_left), small ); - TS_ASSERT_EQUALS( LInfty(small_left), small ); - - TS_ASSERT_EQUALS( L1(smallish_3_neg4), 7.0 * small ); - TS_ASSERT_EQUALS( L2(smallish_3_neg4), 5.0 * small ); - TS_ASSERT_EQUALS( LInfty(smallish_3_neg4), 4.0 * small ); - } - - void testOperatorPlusEquals(void) - { - NR::Point x(a); - x += b; - TS_ASSERT_EQUALS( x, ab ); - } - - void tetOperatorDivEquals(void) - { - NR::Point x(a); - x /= .5; - TS_ASSERT_EQUALS( x, a + a ); - } - - void testNormalize(void) - { - NR::Point x(small_left); - x.normalize(); - TS_ASSERT_EQUALS( x, NR::Point(-1.0, 0.0) ); - - x = smallish_3_neg4; - x.normalize(); - TS_ASSERT_EQUALS( x, NR::Point(0.6, -0.8) ); - } - -}; - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-types.cpp b/src/libnr/nr-types.cpp deleted file mode 100644 index 5da5d5cf6..000000000 --- a/src/libnr/nr-types.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/** \file - * Implements NR::Point::normalize() - */ - -#include <libnr/nr-types.h> -#include <2geom/math-utils.h> - -/** Scales this vector to make it a unit vector (within rounding error). - * - * The current version tries to handle infinite coordinates gracefully, - * but it's not clear that any callers need that. - * - * \pre *this != Point(0, 0). - * \pre Neither coordinate is NaN. - * \post L2(*this) very near 1.0. - */ -void NR::Point::normalize() { - double len = hypot(_pt[0], _pt[1]); - g_return_if_fail(len != 0); - g_return_if_fail(!IS_NAN(len)); - static double const inf = 1e400; - if(len != inf) { - *this /= len; - } else { - unsigned n_inf_coords = 0; - /* Delay updating pt in case neither coord is infinite. */ - NR::Point tmp; - for ( unsigned i = 0 ; i < 2 ; ++i ) { - if ( _pt[i] == inf ) { - ++n_inf_coords; - tmp[i] = 1.0; - } else if ( _pt[i] == -inf ) { - ++n_inf_coords; - tmp[i] = -1.0; - } else { - tmp[i] = 0.0; - } - } - switch (n_inf_coords) { - case 0: - /* Can happen if both coords are near +/-DBL_MAX. */ - *this /= 4.0; - len = hypot(_pt[0], _pt[1]); - g_assert(len != inf); - *this /= len; - break; - - case 1: - *this = tmp; - break; - - case 2: - *this = sqrt(0.5) * tmp; - break; - } - } -} -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-types.h b/src/libnr/nr-types.h deleted file mode 100644 index 685c29342..000000000 --- a/src/libnr/nr-types.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __NR_TYPES_H__ -#define __NR_TYPES_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * Class-ifying NRPoint, Nathan Hurst <njh@mail.csse.monash.edu.au> - * - * This code is in public domain - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <libnr/nr-coord.h> -#include <libnr/nr-dim2.h> -#include <libnr/nr-i-coord.h> -#include <libnr/nr-point.h> -#include <libnr/nr-point-l.h> -#include <libnr/nr-point-ops.h> -#include <libnr/nr-rect.h> -#include <libnr/nr-rect-l.h> -#include <libnr/nr-forward.h> - -#endif /* !__NR_TYPES_H__ */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-values.cpp b/src/libnr/nr-values.cpp index 9193eff3b..5238353d4 100644 --- a/src/libnr/nr-values.cpp +++ b/src/libnr/nr-values.cpp @@ -1,7 +1,8 @@ #define __NR_VALUES_C__ -#include <libnr/nr-rect-l.h> +#include "libnr/nr-values.h" #include "libnr/nr-rect.h" +#include "libnr/nr-rect-l.h" /* The following predefined objects are for reference @@ -10,11 +11,9 @@ and comparison. NRRect NR_RECT_EMPTY(NR_HUGE, NR_HUGE, -NR_HUGE, -NR_HUGE); NRRectL NR_RECT_L_EMPTY = {NR_HUGE_L, NR_HUGE_L, -NR_HUGE_L, -NR_HUGE_L}; -NRRectL NR_RECT_S_EMPTY = - {NR_HUGE_S, NR_HUGE_S, -NR_HUGE_S, -NR_HUGE_S}; /** component_vectors[i] is like $e_i$ in common mathematical usage; or equivalently $I_i$ (where $I$ is the identity matrix). */ -NR::Point const component_vectors[] = {NR::Point(1., 0.), - NR::Point(0., 1.)}; +Geom::Point const component_vectors[] = {Geom::Point(1., 0.), + Geom::Point(0., 1.)}; diff --git a/src/libnr/nr-values.h b/src/libnr/nr-values.h index f85fca690..07faec9fa 100644 --- a/src/libnr/nr-values.h +++ b/src/libnr/nr-values.h @@ -11,12 +11,12 @@ */ #include <libnr/nr-forward.h> +#include <2geom/point.h> #define NR_EPSILON 1e-18 #define NR_HUGE 1e18 #define NR_HUGE_L (0x7fffffff) -#define NR_HUGE_S (0x7fff) /* The following predefined objects are for reference @@ -24,11 +24,10 @@ and comparison. They are defined in nr-values.cpp */ extern NRRect NR_RECT_EMPTY; extern NRRectL NR_RECT_L_EMPTY; -extern NRRectL NR_RECT_S_EMPTY; /** component_vectors[i] has 1.0 at position i, and 0.0 elsewhere (i.e. in the other position). */ -extern NR::Point const component_vectors[2]; +extern Geom::Point const component_vectors[2]; #endif diff --git a/src/libnr/nr_config.h.mingw b/src/libnr/nr_config.h.mingw deleted file mode 100644 index 6992cc6fc..000000000 --- a/src/libnr/nr_config.h.mingw +++ /dev/null @@ -1,12 +0,0 @@ -#define NR_SIZEOF_CHAR 1 -#define NR_SIZEOF_SHORT 2 -#define NR_SIZEOF_INT 4 -#define NR_SIZEOF_LONG 4 - -typedef signed char NRByte; -typedef unsigned char NRUByte; -typedef signed short NRShort; -typedef unsigned short NRUShort; -typedef signed int NRLong; -typedef unsigned long NRULong; - diff --git a/src/libnr/nr_config.h.win32 b/src/libnr/nr_config.h.win32 deleted file mode 100644 index e0bfbda3f..000000000 --- a/src/libnr/nr_config.h.win32 +++ /dev/null @@ -1,14 +0,0 @@ -#define NR_SIZEOF_CHAR 1 -#define NR_SIZEOF_SHORT 2 -#define NR_SIZEOF_INT 4 -#define NR_SIZEOF_LONG 4 - -typedef signed char NRByte; -typedef unsigned char NRUByte; -typedef signed short NRShort; -typedef unsigned short NRUShort; -typedef signed int NRLong; -typedef unsigned long NRULong; - - - diff --git a/src/livarot/Path.h b/src/livarot/Path.h index b8041c63a..78e90c34f 100644 --- a/src/livarot/Path.h +++ b/src/livarot/Path.h @@ -12,9 +12,8 @@ #include <vector> #include "LivarotDefs.h" #include "livarot/livarot-forward.h" -#include "libnr/nr-point.h" #include <libnr/nr-rect-l.h> -#include <2geom/forward.h> +#include <2geom/point.h> struct SPStyle; diff --git a/src/livarot/PathSimplify.cpp b/src/livarot/PathSimplify.cpp index fb2aa55e2..fe1981e4d 100644 --- a/src/livarot/PathSimplify.cpp +++ b/src/livarot/PathSimplify.cpp @@ -7,6 +7,7 @@ */ #include <glib/gmem.h> +#include <2geom/affine.h> #include "livarot/Path.h" #include "livarot/path-description.h" diff --git a/src/livarot/Shape.cpp b/src/livarot/Shape.cpp index 9107844be..d24e4b99d 100644 --- a/src/livarot/Shape.cpp +++ b/src/livarot/Shape.cpp @@ -2225,7 +2225,7 @@ double distance(Shape const *s, Geom::Point const &p) if ( el > 0.001 ) { double const npr = Geom::dot(d, e); if ( npr > 0 && npr < el ) { - double const nl = fabs( NR::cross(d, e) ); + double const nl = fabs( Geom::cross(d, e) ); double ndot = nl * nl / el; if ( ndot < bdot ) { bdot = ndot; @@ -2271,7 +2271,7 @@ bool distanceLessThanOrEqual(Shape const *s, Geom::Point const &p, double const double const max_l1 = max_l2 * M_SQRT2; for (int i = 0; i < s->numberOfPoints(); i++) { Geom::Point const offset( p - s->getPoint(i).x ); - double const l1 = NR::L1(offset); + double const l1 = Geom::L1(offset); if ( (l1 <= max_l2) || ((l1 <= max_l1) && (Geom::L2(offset) <= max_l2)) ) { return true; } @@ -2288,7 +2288,7 @@ bool distanceLessThanOrEqual(Shape const *s, Geom::Point const &p, double const Geom::Point const e_unit(e / el); double const npr = Geom::dot(d, e_unit); if ( npr > 0 && npr < el ) { - double const nl = fabs(NR::cross(d, e_unit)); + double const nl = fabs(Geom::cross(d, e_unit)); if ( nl <= max_l2 ) { return true; } diff --git a/src/livarot/Shape.h b/src/livarot/Shape.h index 5649ff9e4..158977897 100644 --- a/src/livarot/Shape.h +++ b/src/livarot/Shape.h @@ -14,8 +14,8 @@ #include <cstdlib> #include <cstring> #include <vector> +#include <2geom/point.h> -#include "libnr/nr-point.h" #include "livarot/livarot-forward.h" #include "livarot/LivarotDefs.h" diff --git a/src/livarot/path-description.h b/src/livarot/path-description.h index 1d0dfb57e..e9818b55b 100644 --- a/src/livarot/path-description.h +++ b/src/livarot/path-description.h @@ -1,8 +1,8 @@ #ifndef SEEN_INKSCAPE_LIVAROT_PATH_DESCRIPTION_H #define SEEN_INKSCAPE_LIVAROT_PATH_DESCRIPTION_H +#include <2geom/point.h> #include "svg/stringstream.h" -#include "libnr/nr-point.h" // path description commands /* FIXME: these should be unnecessary once the refactoring of the path diff --git a/src/livarot/sweep-event.h b/src/livarot/sweep-event.h index dab006101..5df952731 100644 --- a/src/livarot/sweep-event.h +++ b/src/livarot/sweep-event.h @@ -4,7 +4,7 @@ * Intersection events. */ -#include <libnr/nr-point.h> +#include <2geom/point.h> class SweepTree; diff --git a/src/livarot/sweep-tree.h b/src/livarot/sweep-tree.h index 4a2efe5ec..bbb027b24 100644 --- a/src/livarot/sweep-tree.h +++ b/src/livarot/sweep-tree.h @@ -1,8 +1,8 @@ #ifndef INKSCAPE_LIVAROT_SWEEP_TREE_H #define INKSCAPE_LIVAROT_SWEEP_TREE_H -#include "libnr/nr-point.h" #include "livarot/AVL.h" +#include <2geom/point.h> class Shape; class SweepEvent; diff --git a/src/marker.cpp b/src/marker.cpp index e82d3d952..2354d686c 100644 --- a/src/marker.cpp +++ b/src/marker.cpp @@ -19,6 +19,7 @@ #include "libnr/nr-convert2geom.h" #include <2geom/affine.h> +#include <2geom/transforms.h> #include "svg/svg.h" #include "display/nr-arena-group.h" #include "xml/repr.h" diff --git a/src/object-edit.cpp b/src/object-edit.cpp index 743ef573a..28c8d44db 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -959,7 +959,7 @@ StarKnotHolderEntity1::knot_set(Geom::Point const &p, Geom::Point const &/*origi Geom::Point const s = snap_knot_position(p); - Geom::Point d = s - to_2geom(star->center); + Geom::Point d = s - star->center; double arg1 = atan2(d); double darg1 = arg1 - star->arg[0]; @@ -986,7 +986,7 @@ StarKnotHolderEntity2::knot_set(Geom::Point const &p, Geom::Point const &/*origi Geom::Point const s = snap_knot_position(p); if (star->flatsided == false) { - Geom::Point d = s - to_2geom(star->center); + Geom::Point d = s - star->center; double arg1 = atan2(d); double darg1 = arg1 - star->arg[1]; diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 64137d56f..19e0351a3 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -38,7 +38,6 @@ #include "display/sp-ctrlline.h" #include "display/sodipodi-ctrl.h" #include <glibmm/i18n.h> -#include "libnr/nr-point-ops.h" #include "helper/units.h" #include "macros.h" #include "context-fns.h" @@ -913,7 +912,7 @@ pen_redraw_all (SPPenContext *const pc) if (last_seg) { Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( last_seg ); if ( cubic && - (*cubic)[2] != to_2geom(pc->p[0]) ) + (*cubic)[2] != pc->p[0] ) { Geom::Point p2 = (*cubic)[2]; SP_CTRL(pc->c0)->moveto(p2); diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index a873eb6fc..57205a436 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -57,10 +57,10 @@ static gint pencil_handle_button_release(SPPencilContext *const pc, GdkEventButt static gint pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint const state); static gint pencil_handle_key_release(SPPencilContext *const pc, guint const keyval, guint const state); -static void spdc_set_startpoint(SPPencilContext *pc, Geom::Point const p); -static void spdc_set_endpoint(SPPencilContext *pc, Geom::Point const p); +static void spdc_set_startpoint(SPPencilContext *pc, Geom::Point const &p); +static void spdc_set_endpoint(SPPencilContext *pc, Geom::Point const &p); static void spdc_finish_endpoint(SPPencilContext *pc); -static void spdc_add_freehand_point(SPPencilContext *pc, Geom::Point p, guint state); +static void spdc_add_freehand_point(SPPencilContext *pc, Geom::Point const &p, guint state); static void fit_and_split(SPPencilContext *pc); static void interpolate(SPPencilContext *pc); static void sketch_interpolate(SPPencilContext *pc); @@ -644,7 +644,7 @@ pencil_handle_key_release(SPPencilContext *const pc, guint const keyval, guint c * Reset points and set new starting point. */ static void -spdc_set_startpoint(SPPencilContext *const pc, Geom::Point const p) +spdc_set_startpoint(SPPencilContext *const pc, Geom::Point const &p) { pc->npoints = 0; pc->red_curve_is_valid = false; @@ -664,7 +664,7 @@ spdc_set_startpoint(SPPencilContext *const pc, Geom::Point const p) * We change RED curve. */ static void -spdc_set_endpoint(SPPencilContext *const pc, Geom::Point const p) +spdc_set_endpoint(SPPencilContext *const pc, Geom::Point const &p) { if (pc->npoints == 0) { return; @@ -716,7 +716,7 @@ spdc_finish_endpoint(SPPencilContext *const pc) static void -spdc_add_freehand_point(SPPencilContext *pc, Geom::Point p, guint /*state*/) +spdc_add_freehand_point(SPPencilContext *pc, Geom::Point const &p, guint /*state*/) { g_assert( pc->npoints > 0 ); g_return_if_fail(unsigned(pc->npoints) < G_N_ELEMENTS(pc->p)); diff --git a/src/rect-context.cpp b/src/rect-context.cpp index bcb1bf734..be4f1c71d 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -281,14 +281,14 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent /* Position center */ Geom::Point button_dt(desktop->w2d(button_w)); - rc->center = from_2geom(button_dt); + rc->center = button_dt; /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); - rc->center = from_2geom(button_dt); + rc->center = button_dt; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | diff --git a/src/rect-context.h b/src/rect-context.h index db7cd605b..00caf5d96 100644 --- a/src/rect-context.h +++ b/src/rect-context.h @@ -16,8 +16,8 @@ #include <stddef.h> #include <sigc++/sigc++.h> +#include <2geom/point.h> #include "event-context.h" -#include "libnr/nr-point.h" #define SP_TYPE_RECT_CONTEXT (sp_rect_context_get_type ()) #define SP_RECT_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_RECT_CONTEXT, SPRectContext)) diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp index b01ae5228..a503fea35 100644 --- a/src/removeoverlap.cpp +++ b/src/removeoverlap.cpp @@ -10,12 +10,13 @@ * * Released under GNU LGPL. Read the file 'COPYING' for more information. */ +#include <utility> +#include <2geom/transforms.h> #include "util/glib-list-iterators.h" #include "sp-item.h" #include "sp-item-transform.h" #include "libvpsc/generate-constraints.h" #include "libvpsc/remove_rectangle_overlap.h" -#include <utility> using vpsc::Rectangle; diff --git a/src/selection.cpp b/src/selection.cpp index 3c4ccccf2..3007a3d1f 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -403,7 +403,7 @@ NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const { Geom::OptRect Selection::boundsInDocument(SPItem::BBoxType type) const { NRRect r; - return to_2geom(boundsInDocument(&r, type)->upgrade()); + return to_2geom(boundsInDocument(&r, type)); } /** Extract the position of the center from the first selected object */ diff --git a/src/snap.cpp b/src/snap.cpp index f8fe8e3fa..922dfd530 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -19,6 +19,7 @@ */ #include <utility> +#include <2geom/transforms.h> #include "sp-namedview.h" #include "snap.h" @@ -293,7 +294,7 @@ Geom::Point SnapManager::multipleOfGridPitch(Geom::Point const &t, Geom::Point c // use getSnapDistance() instead of getWeightedDistance() here because the pointer's position // doesn't tell us anything about which node to snap success = true; - nearest_multiple = s.getPoint() - to_2geom(grid->origin); + nearest_multiple = s.getPoint() - grid->origin; nearest_distance = s.getSnapDistance(); bestSnappedPoint = s; } diff --git a/src/sp-conn-end-pair.h b/src/sp-conn-end-pair.h index 6e62b9839..98096a246 100644 --- a/src/sp-conn-end-pair.h +++ b/src/sp-conn-end-pair.h @@ -14,7 +14,6 @@ #include <glib/gtypes.h> #include "forward.h" -#include "libnr/nr-point.h" #include <stddef.h> #include <sigc++/connection.h> #include <sigc++/functors/slot.h> diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index d7bc0053f..9db0d29b2 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -361,7 +361,10 @@ sp_flowtext_print(SPItem *item, SPPrintContext *ctx) if (!bbox_maybe) { return; } - bbox = NRRect(from_2geom(*bbox_maybe)); + bbox.x0 = bbox_maybe->min()[Geom::X]; + bbox.y0 = bbox_maybe->min()[Geom::Y]; + bbox.x1 = bbox_maybe->max()[Geom::X]; + bbox.y1 = bbox_maybe->max()[Geom::Y]; NRRect dbox; dbox.x0 = 0.0; diff --git a/src/sp-image.cpp b/src/sp-image.cpp index f98a6c8e3..3f1c19295 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -25,6 +25,7 @@ #include <string> #include <glib/gstdio.h> #include <2geom/rect.h> +#include <2geom/transforms.h> #include <glibmm/i18n.h> #include "display/nr-arena-image.h" @@ -1497,7 +1498,7 @@ static void sp_image_set_curve( SPImage *image ) } else { NRRect rect; sp_image_bbox(image, &rect, Geom::identity(), 0); - Geom::Rect rect2 = to_2geom(*rect.upgrade()); + Geom::Rect rect2 = *to_2geom(&rect); SPCurve *c = SPCurve::new_from_rect(rect2, true); if (image->curve) { diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 424107426..8e1a4d92c 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -299,7 +299,7 @@ Geom::Point SPItem::getCenter() const { Geom::OptRect bbox = getBounds(i2d_affine()); if (bbox) { - return to_2geom(bbox->midpoint()) + Geom::Point (transform_center_x, transform_center_y); + return bbox->midpoint() + Geom::Point (transform_center_x, transform_center_y); } else { return Geom::Point(0, 0); // something's wrong! } diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index 76efb6b4b..38599188f 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -13,10 +13,11 @@ #include <cstring> #include <string> +#include <2geom/transforms.h> #include "display/nr-arena.h" #include "display/nr-arena-group.h" -#include <xml/repr.h> +#include "xml/repr.h" #include "enums.h" #include "attributes.h" diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 1feb644ad..35a159192 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -17,6 +17,7 @@ #include "config.h" #include <cstring> #include <string> +#include <2geom/transforms.h> #include "display/canvas-grid.h" #include "display/guideline.h" @@ -1099,8 +1100,7 @@ void SPNamedView::translateGuides(Geom::Translate const &tr) { for (GSList *l = guides; l != NULL; l = l->next) { SPGuide &guide = *SP_GUIDE(l->data); Geom::Point point_on_line = guide.point_on_line; - point_on_line[0] += tr[0]; - point_on_line[1] += tr[1]; + point_on_line *= tr; sp_guide_moveto(guide, point_on_line, true); } } diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 460421492..0dd65c7b9 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -844,7 +844,7 @@ sp_offset_distance_to_original (SPOffset * offset, Geom::Point px) { // we have a new minimum distance // now we need to wheck if px is inside or outside (for the sign) - nx = px - to_2geom(theRes->getPoint(i).x); + nx = px - theRes->getPoint(i).x; double nlen = sqrt (dot(nx , nx)); nx /= nlen; int pb, cb, fb; diff --git a/src/sp-root.cpp b/src/sp-root.cpp index b1eef65d2..7d72b7695 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -19,6 +19,7 @@ #include <cstring> #include <string> +#include <2geom/transforms.h> #include "svg/svg.h" #include "display/nr-arena-group.h" diff --git a/src/sp-text.h b/src/sp-text.h index c98721ec9..cd103aa2a 100644 --- a/src/sp-text.h +++ b/src/sp-text.h @@ -19,7 +19,6 @@ #include "sp-item.h" #include "sp-string.h" #include "text-tag-attributes.h" -#include "libnr/nr-point.h" #include "libnrtype/Layout-TNG.h" diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 754885192..a5e1fbc17 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -53,7 +53,7 @@ static void sp_spiral_context_set(SPEventContext *ec, Inkscape::Preferences::Ent static gint sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event); -static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point p, guint state); +static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint state); static void sp_spiral_finish(SPSpiralContext *sc); static void sp_spiral_cancel(SPSpiralContext *sc); @@ -275,7 +275,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) m.setup(desktop, true, sc->item); m.freeSnapReturnByRef(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); - sp_spiral_drag(sc, from_2geom(motion_dt), event->motion.state); + sp_spiral_drag(sc, motion_dt, event->motion.state); gobble_motion_events(GDK_BUTTON1_MASK); @@ -399,7 +399,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) return ret; } -static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point p, guint state) +static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint state) { SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; @@ -430,7 +430,7 @@ static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point p, guint state) SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, true, sc->item); - Geom::Point pt2g = to_2geom(p); + Geom::Point pt2g = p; m.freeSnapReturnByRef(pt2g, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); Geom::Point const p0 = desktop->dt2doc(sc->center); diff --git a/src/spiral-context.h b/src/spiral-context.h index 6d689c49c..d877e6ae4 100644 --- a/src/spiral-context.h +++ b/src/spiral-context.h @@ -18,8 +18,8 @@ #include <gtk/gtk.h> #include <stddef.h> #include <sigc++/sigc++.h> +#include <2geom/point.h> #include "event-context.h" -#include "libnr/nr-point.h" #define SP_TYPE_SPIRAL_CONTEXT (sp_spiral_context_get_type ()) #define SP_SPIRAL_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_SPIRAL_CONTEXT, SPSpiralContext)) diff --git a/src/spray-context.h b/src/spray-context.h index f6d9a9c0b..fc2340b5e 100644 --- a/src/spray-context.h +++ b/src/spray-context.h @@ -18,8 +18,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <2geom/point.h> #include "event-context.h" -#include <libnr/nr-point.h> //#include "ui/widget/spray-option.h" #include "ui/dialog/dialog.h" diff --git a/src/star-context.cpp b/src/star-context.cpp index 9f4afb94c..bc0376a20 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -225,9 +225,9 @@ sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val) Glib::ustring path = val->getEntryName(); if (path == "magnitude") { - sc->magnitude = NR_CLAMP(val->getInt(5), 3, 1024); + sc->magnitude = CLAMP(val->getInt(5), 3, 1024); } else if (path == "proportion") { - sc->proportion = NR_CLAMP(val->getDouble(0.5), 0.01, 2.0); + sc->proportion = CLAMP(val->getDouble(0.5), 0.01, 2.0); } else if (path == "isflatsided") { sc->isflatsided = val->getBool(); } else if (path == "rounded") { @@ -446,7 +446,7 @@ static void sp_star_drag(SPStarContext *sc, Geom::Point p, guint state) /* Snap corner point with no constraints */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, true, sc->item); - Geom::Point pt2g = to_2geom(p); + Geom::Point pt2g = p; m.freeSnapReturnByRef(pt2g, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); Geom::Point const p0 = desktop->dt2doc(sc->center); diff --git a/src/star-context.h b/src/star-context.h index b66e2dd15..c7cba2bf0 100644 --- a/src/star-context.h +++ b/src/star-context.h @@ -16,8 +16,8 @@ #include <stddef.h> #include <sigc++/sigc++.h> +#include <2geom/point.h> #include "event-context.h" -#include "libnr/nr-point.h" #define SP_TYPE_STAR_CONTEXT (sp_star_context_get_type ()) #define SP_STAR_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_STAR_CONTEXT, SPStarContext)) diff --git a/src/svg-view.cpp b/src/svg-view.cpp index b35375736..44c874150 100644 --- a/src/svg-view.cpp +++ b/src/svg-view.cpp @@ -13,6 +13,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <2geom/transforms.h> #include "display/canvas-arena.h" #include "document.h" #include "sp-item.h" diff --git a/src/tweak-context.h b/src/tweak-context.h index 5fbd078ef..d77605a82 100644 --- a/src/tweak-context.h +++ b/src/tweak-context.h @@ -13,7 +13,7 @@ */ #include "event-context.h" -#include <libnr/nr-point.h> +#include <2geom/point.h> #define SP_TYPE_TWEAK_CONTEXT (sp_tweak_context_get_type()) #define SP_TWEAK_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_TWEAK_CONTEXT, SPTweakContext)) diff --git a/src/ui/cache/svg_preview_cache.cpp b/src/ui/cache/svg_preview_cache.cpp index fd7070bab..c631631fb 100644 --- a/src/ui/cache/svg_preview_cache.cpp +++ b/src/ui/cache/svg_preview_cache.cpp @@ -21,6 +21,7 @@ #include <glib/gmem.h> #include <gtk/gtk.h> +#include <2geom/transforms.h> #include "sp-namedview.h" #include "selection.h" #include "inkscape.h" diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index a2169c0b3..f7cb06263 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -20,8 +20,8 @@ # include <config.h> #endif +#include <2geom/transforms.h> #include "ui/widget/spinbutton.h" - #include "desktop-handles.h" #include "unclump.h" #include "document.h" @@ -357,7 +357,7 @@ private : it < sorted.end(); it ++ ) { - if (!NR_DF_TEST_CLOSE (pos, it->bbox.min()[_orientation], 1e-6)) { + if (!Geom::are_near(pos, it->bbox.min()[_orientation], 1e-6)) { Geom::Point t(0.0, 0.0); t[_orientation] = pos - it->bbox.min()[_orientation]; sp_item_move_rel(it->item, Geom::Translate(t)); @@ -380,7 +380,7 @@ private : //new anchor position float pos = sorted.front().anchor + i * step; //Don't move if we are really close - if (!NR_DF_TEST_CLOSE (pos, it.anchor, 1e-6)) { + if (!Geom::are_near(pos, it.anchor, 1e-6)) { //Compute translation Geom::Point t(0.0, 0.0); t[_orientation] = pos - it.anchor; diff --git a/src/ui/dialog/align-and-distribute.h b/src/ui/dialog/align-and-distribute.h index 7c99d67c7..99b96463c 100644 --- a/src/ui/dialog/align-and-distribute.h +++ b/src/ui/dialog/align-and-distribute.h @@ -25,7 +25,6 @@ #include <gtkmm/table.h> #include <gtkmm/buttonbox.h> #include <gtkmm/label.h> -#include "libnr/nr-dim2.h" #include "libnr/nr-rect.h" diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index ae17214bf..7c7413ce5 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -21,6 +21,7 @@ #include <gtk/gtk.h> //for GTK_RESPONSE* types #include <glibmm/i18n.h> #include <gtkmm/stock.h> +#include <2geom/transforms.h> #include "verbs.h" #include "preferences.h" diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 901d02240..92c8bd349 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -16,6 +16,7 @@ #include <gtkmm/stock.h> #include <gtkmm/dialog.h> +#include <2geom/transforms.h> #include "document.h" #include "desktop-handles.h" diff --git a/src/ui/view/edit-widget-interface.h b/src/ui/view/edit-widget-interface.h index 4ff4f92f9..577beb5ce 100644 --- a/src/ui/view/edit-widget-interface.h +++ b/src/ui/view/edit-widget-interface.h @@ -16,9 +16,9 @@ #ifndef INKSCAPE_UI_VIEW_EDIT_WIDGET_IFACE_H #define INKSCAPE_UI_VIEW_EDIT_WIDGET_IFACE_H -#include "libnr/nr-point.h" #include "message.h" #include <gtkmm/window.h> +#include <2geom/point.h> namespace Inkscape { namespace UI { namespace Widget { class Dock; } } } diff --git a/src/ui/view/view.cpp b/src/ui/view/view.cpp index f05e024d1..dc6307ab0 100644 --- a/src/ui/view/view.cpp +++ b/src/ui/view/view.cpp @@ -16,7 +16,7 @@ # include "config.h" #endif -#include "libnr/nr-point.h" +#include <2geom/point.h> #include "document.h" #include "view.h" #include "message-stack.h" diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 672e1415b..626be7625 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -24,6 +24,7 @@ #include <string> #include <string.h> #include <vector> +#include <2geom/transforms.h> #include "desktop-handles.h" #include "document.h" diff --git a/src/ui/widget/rotateable.cpp b/src/ui/widget/rotateable.cpp index 396280aee..23d5363ef 100644 --- a/src/ui/widget/rotateable.cpp +++ b/src/ui/widget/rotateable.cpp @@ -9,13 +9,12 @@ * Released under GNU GPL. Read the file 'COPYING' for more information. */ -#include "event-context.h" -#include "rotateable.h" -#include "libnr/nr-point.h" -#include "libnr/nr-point-fns.h" #include <gtkmm/box.h> #include <gtkmm/eventbox.h> #include <glibmm/i18n.h> +#include <2geom/point.h> +#include "event-context.h" +#include "rotateable.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/ruler.h b/src/ui/widget/ruler.h index c315418d8..afe3a4ba7 100644 --- a/src/ui/widget/ruler.h +++ b/src/ui/widget/ruler.h @@ -13,7 +13,7 @@ */ #include <gtkmm/eventbox.h> -#include "libnr/nr-point.h" +#include <2geom/point.h> struct SPCanvasItem; struct SPDesktop; diff --git a/src/unclump.cpp b/src/unclump.cpp index d027a6986..baeeaff76 100644 --- a/src/unclump.cpp +++ b/src/unclump.cpp @@ -12,6 +12,7 @@ #include <algorithm> #include <map> +#include <2geom/transforms.h> #include "sp-item.h" diff --git a/src/widgets/dash-selector.cpp b/src/widgets/dash-selector.cpp index dead653de..3339c64d3 100644 --- a/src/widgets/dash-selector.cpp +++ b/src/widgets/dash-selector.cpp @@ -22,9 +22,9 @@ #include <cstring> #include <string> -#include <libnr/nr-macros.h> #include <gtk/gtk.h> #include <glibmm/i18n.h> +#include <2geom/coord.h> #include "style.h" #include "dialogs/dialog-events.h" @@ -144,7 +144,7 @@ SPDashSelector::set_dash (int ndash, double *dash, double o) if (np == ndash) { int j; for (j = 0; j < ndash; j++) { - if (!NR_DF_TEST_CLOSE (dash[j], pattern[j], delta)) + if (!Geom::are_near(dash[j], pattern[j], delta)) break; } if (j == ndash) { diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 6f3b4dcb9..797525838 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -24,8 +24,9 @@ # include "config.h" #endif -#include <gtkmm/paned.h> #include <gtk/gtk.h> +#include <gtkmm.h> +#include <2geom/rect.h> #include "box3d-context.h" #include "color-profile-fns.h" @@ -1522,7 +1523,7 @@ sp_desktop_widget_update_hruler (SPDesktopWidget *dtw) * the latter is used for drawing e.g. the grids and guides. Only when the viewbox * coincides with the pixel buffer, everything will line up nicely. */ - NR::IRect viewbox = dtw->canvas->getViewboxIntegers(); + Geom::IntRect viewbox = dtw->canvas->getViewboxIntegers(); double const scale = dtw->desktop->current_zoom(); double s = viewbox.min()[Geom::X] / scale - dtw->ruler_origin[Geom::X]; @@ -1538,7 +1539,7 @@ sp_desktop_widget_update_vruler (SPDesktopWidget *dtw) * the latter is used for drawing e.g. the grids and guides. Only when the viewbox * coincides with the pixel buffer, everything will line up nicely. */ - NR::IRect viewbox = dtw->canvas->getViewboxIntegers(); + Geom::IntRect viewbox = dtw->canvas->getViewboxIntegers(); double const scale = dtw->desktop->current_zoom(); double s = viewbox.min()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y]; diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h index 6c5af0aac..165367954 100644 --- a/src/widgets/desktop-widget.h +++ b/src/widgets/desktop-widget.h @@ -14,7 +14,6 @@ #include <gtk/gtk.h> -#include "libnr/nr-point.h" #include "forward.h" #include "sp-object.h" #include "message.h" @@ -23,6 +22,7 @@ #include <stddef.h> #include <sigc++/connection.h> +#include <2geom/point.h> // forward declaration typedef struct _EgeColorProfTracker EgeColorProfTracker; diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 450c5f0d9..95cb23a22 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -23,6 +23,7 @@ #include <gtkmm.h> #include <gdkmm/pixbuf.h> #include <glibmm/fileutils.h> +#include <2geom/transforms.h> #include "path-prefix.h" #include "preferences.h" diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 01308104e..d0ff38592 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -6777,11 +6777,11 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) unsigned writing_mode = item->style->writing_mode.value; // below, variable names suggest horizontal move, but we check the writing direction // and move in the corresponding axis - int axis; + Geom::Dim2 axis; if (writing_mode == SP_CSS_WRITING_MODE_LR_TB || writing_mode == SP_CSS_WRITING_MODE_RL_TB) { - axis = NR::X; + axis = Geom::X; } else { - axis = NR::Y; + axis = Geom::Y; } Geom::OptRect bbox @@ -6834,7 +6834,7 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) } } Geom::Point XY = SP_TEXT(item)->attributes.firstXY(); - if (axis == NR::X) { + if (axis == Geom::X) { XY = XY + Geom::Point (move, 0); } else { XY = XY + Geom::Point (0, move); |
