summaryrefslogtreecommitdiffstats
path: root/src/libnr
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2011-07-14 19:42:57 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2011-07-14 19:42:57 +0000
commitefbf9755460d4c4b7a3d9d43dd753afcc8a28865 (patch)
tree41a259211da187e29f9983821b4cdfea221b6ad6 /src/libnr
parentFix crashes in print preview (diff)
parentMake cms_key in SPDesktopWidget a regular ustring rather than a pointer (diff)
downloadinkscape-efbf9755460d4c4b7a3d9d43dd753afcc8a28865.tar.gz
inkscape-efbf9755460d4c4b7a3d9d43dd753afcc8a28865.zip
Merge SPCanvasArena caching layer work
(bzr r10451)
Diffstat (limited to 'src/libnr')
-rw-r--r--src/libnr/Makefile_insert13
-rw-r--r--src/libnr/in-svg-plane.h5
-rw-r--r--src/libnr/libnr.def89
-rw-r--r--src/libnr/nr-convert2geom.h34
-rw-r--r--src/libnr/nr-coord.h29
-rw-r--r--src/libnr/nr-dim2.h22
-rw-r--r--src/libnr/nr-forward.h10
-rw-r--r--src/libnr/nr-i-coord.h25
-rw-r--r--src/libnr/nr-point-fns-test.h139
-rw-r--r--src/libnr/nr-point-fns.cpp91
-rw-r--r--src/libnr/nr-point-fns.h95
-rw-r--r--src/libnr/nr-point-l.h103
-rw-r--r--src/libnr/nr-point-ops.h88
-rw-r--r--src/libnr/nr-point.h155
-rw-r--r--src/libnr/nr-rect-l.cpp49
-rw-r--r--src/libnr/nr-rect-l.h131
-rw-r--r--src/libnr/nr-rect-ops.h51
-rw-r--r--src/libnr/nr-rect.cpp198
-rw-r--r--src/libnr/nr-rect.h243
-rw-r--r--src/libnr/nr-render.h25
-rw-r--r--src/libnr/nr-types-test.h142
-rw-r--r--src/libnr/nr-types.cpp68
-rw-r--r--src/libnr/nr-types.h39
-rw-r--r--src/libnr/nr-values.cpp12
-rw-r--r--src/libnr/nr-values.h5
-rw-r--r--src/libnr/nr_config.h.mingw12
-rw-r--r--src/libnr/nr_config.h.win3214
27 files changed, 110 insertions, 1777 deletions
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 cd6d6927b..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/isnan.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..1cb268266 100644
--- a/src/libnr/nr-rect-l.cpp
+++ b/src/libnr/nr-rect-l.cpp
@@ -1,21 +1,50 @@
-#include <libnr/nr-rect-l.h>
+#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>();
+NRRectL::NRRectL()
+{
+ x0 = G_MAXINT32;
+ y0 = G_MAXINT32;
+ x1 = G_MININT32;
+ y1 = G_MININT32;
+}
+
+NRRectL::NRRectL(gint32 xmin, gint32 ymin, gint32 xmax, gint32 ymax)
+{
+ x0 = xmin;
+ y0 = ymin;
+ x1 = xmax;
+ y1 = ymax;
+}
+
+NRRectL::NRRectL(Geom::OptIntRect const &r)
+{
+ if (r) {
+ x0 = r->left();
+ y0 = r->top();
+ x1 = r->right();
+ y1 = r->bottom();
} else {
- return NR::Rect(NR::Point(x0, y0), NR::Point(x1, y1));
+ x0 = G_MAXINT32;
+ y0 = G_MAXINT32;
+ x1 = G_MININT32;
+ y1 = G_MININT32;
}
}
-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])))
+NRRectL::NRRectL(Geom::IntRect const &r)
{
+ x0 = r.left();
+ y0 = r.top();
+ x1 = r.right();
+ y1 = r.bottom();
}
+Geom::OptIntRect NRRectL::upgrade_2geom() const
+{
+ Geom::OptIntRect ret;
+ if (x0 > x1 || y0 > y1) return ret;
+ ret = Geom::IntRect(x0, y0, x1, y1);
+ return ret;
}
/*
diff --git a/src/libnr/nr-rect-l.h b/src/libnr/nr-rect-l.h
index 3493fa8f4..c4c5f5a6d 100644
--- a/src/libnr/nr-rect-l.h
+++ b/src/libnr/nr-rect-l.h
@@ -1,132 +1,19 @@
#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>
+#include <2geom/int-rect.h>
struct NRRectL {
- boost::optional<NR::Rect> upgrade() const;
- NR::ICoord x0, y0, x1, y1;
+ gint32 x0, y0, x1, y1;
+ NRRectL();
+ NRRectL(gint32 xmin, gint32 ymin, gint32 xmax, gint32 ymax);
+ explicit NRRectL(Geom::IntRect const &r);
+ explicit NRRectL(Geom::OptIntRect const &r);
+ operator Geom::OptIntRect() const { Geom::OptIntRect r = upgrade_2geom(); return r; }
+ Geom::OptIntRect upgrade_2geom() const;
};
-
-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 0231c91d5..000000000
--- a/src/libnr/nr-types.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/** \file
- * Implements NR::Point::normalize()
- */
-
-#include <libnr/nr-types.h>
-
-#include "2geom/isnan.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..06f33b13f 100644
--- a/src/libnr/nr-values.cpp
+++ b/src/libnr/nr-values.cpp
@@ -1,20 +1,18 @@
#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
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};
+NRRectL NR_RECT_L_EMPTY(NR_HUGE_L, NR_HUGE_L, -NR_HUGE_L, -NR_HUGE_L);
/** 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;
-
-
-