diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2010-08-04 23:56:47 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2010-08-04 23:56:47 +0000 |
| commit | 498629f82d9453cb7222ab642b867c183fdf1666 (patch) | |
| tree | 33bb4b8bffc1f67c2167d393e928aee743fdce9d /src/libnr | |
| parent | Fix artifacts in Gaussian blur and other filters inadvertently (diff) | |
| download | inkscape-498629f82d9453cb7222ab642b867c183fdf1666.tar.gz inkscape-498629f82d9453cb7222ab642b867c183fdf1666.zip | |
Wholesale cruft removal part 3
(bzr r9508.1.47)
Diffstat (limited to 'src/libnr')
44 files changed, 10 insertions, 2544 deletions
diff --git a/src/libnr/Makefile_insert b/src/libnr/Makefile_insert index dc329c351..6afef39ef 100644 --- a/src/libnr/Makefile_insert +++ b/src/libnr/Makefile_insert @@ -4,8 +4,6 @@ ink_common_sources += \ libnr/in-svg-plane.h \ libnr/nr-blit.cpp \ libnr/nr-blit.h \ - libnr/nr-compose-transform.cpp \ - libnr/nr-compose-transform.h \ libnr/nr-compose-reference.h \ libnr/nr-compose.cpp \ libnr/nr-compose.h \ @@ -15,15 +13,6 @@ ink_common_sources += \ libnr/nr-forward.h \ libnr/nr-i-coord.h \ libnr/nr-macros.h \ - libnr/nr-matrix-fns.cpp \ - libnr/nr-matrix-fns.h \ - libnr/nr-matrix-ops.h \ - libnr/nr-matrix-rotate-ops.cpp \ - libnr/nr-matrix-rotate-ops.h \ - libnr/nr-matrix-scale-ops.h \ - libnr/nr-matrix-translate-ops.h \ - libnr/nr-matrix.cpp \ - libnr/nr-matrix.h \ libnr/nr-maybe.h \ libnr/nr-object.cpp \ libnr/nr-object.h \ @@ -36,7 +25,6 @@ ink_common_sources += \ libnr/nr-point-fns.cpp \ libnr/nr-point-fns.h \ libnr/nr-point-l.h \ - libnr/nr-point-matrix-ops.h \ libnr/nr-point-ops.h \ libnr/nr-point.h \ libnr/nr-rect-l.cpp \ @@ -45,26 +33,6 @@ ink_common_sources += \ libnr/nr-rect.h \ libnr/nr-rect-ops.h \ libnr/nr-render.h \ - libnr/nr-rotate-fns.cpp \ - libnr/nr-rotate-fns.h \ - libnr/nr-rotate-ops.h \ - libnr/nr-rotate-matrix-ops.cpp \ - libnr/nr-rotate-matrix-ops.h \ - libnr/nr-rotate.h \ - libnr/nr-scale-matrix-ops.cpp \ - libnr/nr-scale-matrix-ops.h \ - libnr/nr-scale-translate-ops.cpp \ - libnr/nr-scale-translate-ops.h \ - libnr/nr-scale-ops.h \ - libnr/nr-scale.h \ - libnr/nr-translate-matrix-ops.cpp \ - libnr/nr-translate-matrix-ops.h \ - libnr/nr-translate-scale-ops.cpp \ - libnr/nr-translate-scale-ops.h \ - libnr/nr-translate-ops.h \ - libnr/nr-translate.h \ - libnr/nr-translate-rotate-ops.cpp \ - libnr/nr-translate-rotate-ops.h \ libnr/nr-types.cpp \ libnr/nr-types.h \ libnr/nr-values.cpp \ @@ -86,10 +54,5 @@ ink_common_sources += \ CXXTEST_TESTSUITES += \ $(srcdir)/libnr/in-svg-plane-test.h \ $(srcdir)/libnr/nr-compose-test.h \ - $(srcdir)/libnr/nr-matrix-test.h \ $(srcdir)/libnr/nr-point-fns-test.h \ - $(srcdir)/libnr/nr-rotate-test.h \ - $(srcdir)/libnr/nr-rotate-fns-test.h \ - $(srcdir)/libnr/nr-scale-test.h \ - $(srcdir)/libnr/nr-translate-test.h \ $(srcdir)/libnr/nr-types-test.h diff --git a/src/libnr/nr-compose-transform.cpp b/src/libnr/nr-compose-transform.cpp deleted file mode 100644 index 05852bf07..000000000 --- a/src/libnr/nr-compose-transform.cpp +++ /dev/null @@ -1,367 +0,0 @@ -#define __NR_COMPOSE_TRANSFORM_C__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "nr-pixops.h" -#include "nr-matrix.h" - -/*#ifdef WITH_MMX -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus -/ * fixme: * / -/ *int nr_have_mmx (void); -#define NR_PIXOPS_MMX (1 && nr_have_mmx ()) -#ifdef __cplusplus -} -#endif //__cplusplus -#endif -*/ - -/* fixme: Implement missing (Lauris) */ -/* fixme: PREMUL colors before calculating average (Lauris) */ - -/* Fixed point precision */ -#define FBITS 12 -#define FBITS_HP 18 // In some places we need a higher precision - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); - -void -nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd) -{ - int xsize, ysize, size, dbits; - long FFs_x_x, FFs_x_y, FFs_y_x, FFs_y_y, FFs__x, FFs__y; - long FFs_x_x_S, FFs_x_y_S, FFs_y_x_S, FFs_y_y_S; - /* Subpixel positions */ - int FF_sx_S[256]; - int FF_sy_S[256]; - unsigned char *d0; - int FFsx0, FFsy0; - int x, y; - - if (alpha == 0) return; - if (alpha>255) { - g_warning("In transform PPN alpha=%u>255",alpha); - } - - // The color component is stored temporarily with a range of [0,255^3], so more supersampling and we get an overflow (fortunately Inkscape's preferences also doesn't allow a higher setting) - if (xd+yd>8) { - xd = 4; - yd = 4; - } - - xsize = (1 << xd); - ysize = (1 << yd); - size = xsize * ysize; - dbits = xd + yd; - unsigned int rounding_fix = size/2; - - /* Set up fixed point matrix */ - FFs_x_x = (long) floor(d2s[0] * (1 << FBITS) + 0.5); - FFs_x_y = (long) floor(d2s[1] * (1 << FBITS) + 0.5); - FFs_y_x = (long) floor(d2s[2] * (1 << FBITS) + 0.5); - FFs_y_y = (long) floor(d2s[3] * (1 << FBITS) + 0.5); - FFs__x = (long) floor(d2s[4] * (1 << FBITS) + 0.5); - FFs__y = (long) floor(d2s[5] * (1 << FBITS) + 0.5); - - FFs_x_x_S = FFs_x_x >> xd; - FFs_x_y_S = FFs_x_y >> xd; - FFs_y_x_S = FFs_y_x >> yd; - FFs_y_y_S = FFs_y_y >> yd; - - /* Set up subpixel matrix */ - /* fixme: We can calculate that in floating point (Lauris) */ - for (y = 0; y < ysize; y++) { - for (x = 0; x < xsize; x++) { - FF_sx_S[y * xsize + x] = FFs_x_x_S * x + FFs_y_x_S * y; - FF_sy_S[y * xsize + x] = FFs_x_y_S * x + FFs_y_y_S * y; - } - } - - d0 = px; - FFsx0 = FFs__x; - FFsy0 = FFs__y; - - for (y = 0; y < h; y++) { - unsigned char *d; - long FFsx, FFsy; - d = d0; - FFsx = FFsx0; - FFsy = FFsy0; - for (x = 0; x < w; x++) { - unsigned int r, g, b, a; - long sx, sy; - int i; - r = g = b = a = 0; - for (i = 0; i < size; i++) { - sx = (FFsx + FF_sx_S[i]) >> FBITS; - if ((sx >= 0) && (sx < sw)) { - sy = (FFsy + FF_sy_S[i]) >> FBITS; - if ((sy >= 0) && (sy < sh)) { - const unsigned char *s; - s = spx + sy * srs + sx * 4; - r += NR_PREMUL_112 (s[0], s[3]); // s in [0,255] - g += NR_PREMUL_112 (s[1], s[3]); - b += NR_PREMUL_112 (s[2], s[3]); - a += s[3]; - // a=sum(s3) - // r,g,b in [0,sum(s3)*255] - } - } - } - a = (a*alpha + rounding_fix) >> dbits; - // a=sum(s3)*alpha/size=avg(s3)*alpha - // Compare to nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P - if (a != 0) { - r = (r*alpha + rounding_fix) >> dbits; - g = (g*alpha + rounding_fix) >> dbits; - b = (b*alpha + rounding_fix) >> dbits; - // r,g,b in [0,avg(s3)*alpha*255]=[0,a*255] - if (a == 255*255) { - /* Full coverage, demul src */ - d[0] = NR_NORMALIZE_31(r); - d[1] = NR_NORMALIZE_31(g); - d[2] = NR_NORMALIZE_31(b); - d[3] = NR_NORMALIZE_21(a); - } else if (d[3] == 0) { - /* Only foreground, demul src */ - d[0] = NR_DEMUL_321(r,a); - d[1] = NR_DEMUL_321(g,a); - d[2] = NR_DEMUL_321(b,a); - d[3] = NR_NORMALIZE_21(a); - } else { - unsigned int ca; - /* Full composition */ - ca = NR_COMPOSEA_213(a, d[3]); - d[0] = NR_COMPOSEPNN_321131 (r, a, d[0], d[3], ca); - d[1] = NR_COMPOSEPNN_321131 (g, a, d[1], d[3], ca); - d[2] = NR_COMPOSEPNN_321131 (b, a, d[2], d[3], ca); - d[3] = NR_NORMALIZE_31(ca); - } - } - /* Advance pointers */ - FFsx += FFs_x_x; - FFsy += FFs_x_y; - d += 4; - } - FFsx0 += FFs_y_x; - FFsy0 += FFs_y_y; - d0 += rs; - } -} - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); - -static void -nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM_0 (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const long long *FFd2s, unsigned int alpha) -{ - unsigned char *d0; - long long FFsx0, FFsy0; - int x, y; - - d0 = px; - FFsx0 = FFd2s[4]; - FFsy0 = FFd2s[5]; - - for (y = 0; y < h; y++) { - unsigned char *d; - long long FFsx, FFsy; - d = d0; - FFsx = FFsx0; - FFsy = FFsy0; - for (x = 0; x < w; x++) { - long sx, sy; - sx = long(FFsx >> FBITS_HP); - if ((sx >= 0) && (sx < sw)) { - sy = long(FFsy >> FBITS_HP); - if ((sy >= 0) && (sy < sh)) { - const unsigned char *s; - unsigned int a; - s = spx + sy * srs + sx * 4; - a = NR_PREMUL_112 (s[3], alpha); - if (a != 0) { - if ((a == 255*255) || (d[3] == 0)) { - /* Transparent BG, premul src */ - d[0] = NR_PREMUL_121 (s[0], a); - d[1] = NR_PREMUL_121 (s[1], a); - d[2] = NR_PREMUL_121 (s[2], a); - d[3] = NR_NORMALIZE_21(a); - } else { - d[0] = NR_COMPOSENPP_1211 (s[0], a, d[0]); - d[1] = NR_COMPOSENPP_1211 (s[1], a, d[1]); - d[2] = NR_COMPOSENPP_1211 (s[2], a, d[2]); - d[3] = NR_COMPOSEA_211(a, d[3]); - } - } - } - } - /* Advance pointers */ - FFsx += FFd2s[0]; - FFsy += FFd2s[1]; - d += 4; - } - FFsx0 += FFd2s[2]; - FFsy0 += FFd2s[3]; - d0 += rs; - } -} - -static void -nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM_n (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const long long *FFd2s, const long *FF_S, unsigned int alpha, int dbits) -{ - int size; - unsigned char *d0; - long long FFsx0, FFsy0; - int x, y; - - size = (1 << dbits); - unsigned int rounding_fix = size/2; - - d0 = px; - FFsx0 = FFd2s[4]; - FFsy0 = FFd2s[5]; - - for (y = 0; y < h; y++) { - unsigned char *d; - long long FFsx, FFsy; - d = d0; - FFsx = FFsx0; - FFsy = FFsy0; - for (x = 0; x < w; x++) { - unsigned int r, g, b, a; - int i; - r = g = b = a = 0; - for (i = 0; i < size; i++) { - long sx, sy; - sx = (long (FFsx >> (FBITS_HP - FBITS)) + FF_S[2 * i]) >> FBITS; - if ((sx >= 0) && (sx < sw)) { - sy = (long (FFsy >> (FBITS_HP - FBITS)) + FF_S[2 * i + 1]) >> FBITS; - if ((sy >= 0) && (sy < sh)) { - const unsigned char *s; - s = spx + sy * srs + sx * 4; - r += NR_PREMUL_112(s[0], s[3]); - g += NR_PREMUL_112(s[1], s[3]); - b += NR_PREMUL_112(s[2], s[3]); - a += s[3]; - } - } - } - a = (a*alpha + rounding_fix) >> dbits; - if (a != 0) { - r = (r*alpha + rounding_fix) >> dbits; - g = (g*alpha + rounding_fix) >> dbits; - b = (b*alpha + rounding_fix) >> dbits; - if ((a == 255*255) || (d[3] == 0)) { - /* Transparent BG, premul src */ - d[0] = NR_NORMALIZE_31(r); - d[1] = NR_NORMALIZE_31(g); - d[2] = NR_NORMALIZE_31(b); - d[3] = NR_NORMALIZE_21(a); - } else { - d[0] = NR_COMPOSEPPP_3211 (r, a, d[0]); - d[1] = NR_COMPOSEPPP_3211 (g, a, d[1]); - d[2] = NR_COMPOSEPPP_3211 (b, a, d[2]); - d[3] = NR_COMPOSEA_211(a, d[3]); - } - } - /* Advance pointers */ - FFsx += FFd2s[0]; - FFsy += FFd2s[1]; - d += 4; - } - FFsx0 += FFd2s[2]; - FFsy0 += FFd2s[3]; - d0 += rs; - } -} - -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd) -{ - int dbits; - long FFd2s[6]; - long long FFd2s_HP[6]; // with higher precision - int i; - - if (alpha == 0) return; - if (alpha>255) { - g_warning("In transform PPN alpha=%u>255",alpha); - } - - // The color component is stored temporarily with a range of [0,255^3], so more supersampling and we get an overflow (fortunately Inkscape's preferences also doesn't allow a higher setting) - if (xd+yd>8) { - xd = 4; - yd = 4; - } - - dbits = xd + yd; - - for (i = 0; i < 6; i++) { - FFd2s[i] = (long) floor(d2s[i] * (1 << FBITS) + 0.5); - FFd2s_HP[i] = (long long) floor(d2s[i] * (1 << FBITS_HP) + 0.5);; - } - - if (dbits == 0) { - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM_0 (px, w, h, rs, spx, sw, sh, srs, FFd2s_HP, alpha); - } else { - int xsize, ysize; - long FFs_x_x_S, FFs_x_y_S, FFs_y_x_S, FFs_y_y_S; - long FF_S[2 * 256]; - int x, y; - - xsize = (1 << xd); - ysize = (1 << yd); - - FFs_x_x_S = FFd2s[0] >> xd; - FFs_x_y_S = FFd2s[1] >> xd; - FFs_y_x_S = FFd2s[2] >> yd; - FFs_y_y_S = FFd2s[3] >> yd; - - /* Set up subpixel matrix */ - /* fixme: We can calculate that in floating point (Lauris) */ - for (y = 0; y < ysize; y++) { - for (x = 0; x < xsize; x++) { - FF_S[2 * (y * xsize + x)] = FFs_x_x_S * x + FFs_y_x_S * y; - FF_S[2 * (y * xsize + x) + 1] = FFs_x_y_S * x + FFs_y_y_S * y; - } - } - - nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM_n (px, w, h, rs, spx, sw, sh, srs, FFd2s_HP, FF_S, alpha, dbits); - } -} - -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); diff --git a/src/libnr/nr-compose-transform.h b/src/libnr/nr-compose-transform.h deleted file mode 100644 index 7ffb20074..000000000 --- a/src/libnr/nr-compose-transform.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __NR_COMPOSE_TRANSFORM_H__ -#define __NR_COMPOSE_TRANSFORM_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include <libnr/nr-forward.h> - -/* FINAL DST SRC */ - -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_N_EMPTY_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_P_EMPTY_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); - -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_N_R8G8B8A8_N_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); -void nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_P_TRANSFORM (unsigned char *px, int w, int h, int rs, - const unsigned char *spx, int sw, int sh, int srs, - const NR::Matrix &d2s, unsigned int alpha, int xd, int yd); - -#endif diff --git a/src/libnr/nr-convert2geom.h b/src/libnr/nr-convert2geom.h index b7cbd7ee8..b0ce18c90 100644 --- a/src/libnr/nr-convert2geom.h +++ b/src/libnr/nr-convert2geom.h @@ -9,7 +9,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <libnr/nr-matrix.h> #include <libnr/nr-rect.h> #include <libnr/nr-point.h> #include <2geom/matrix.h> @@ -24,19 +23,6 @@ inline NR::Point from_2geom(Geom::Point const & _pt) { return NR::Point(_pt[0], _pt[1]); } -inline Geom::Matrix to_2geom(NR::Matrix const & mat) { - Geom::Matrix mat2geom(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); - return mat2geom; -} -inline NR::Matrix from_2geom(Geom::Matrix const & mat) { - NR::Matrix mat2geom(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); - return mat2geom; -} - -inline Geom::Translate to_2geom(NR::translate const & mat) { - return Geom::Translate( mat.offset[0], mat.offset[1] ); -} - inline Geom::Rect to_2geom(NR::Rect const & rect) { Geom::Rect rect2geom(to_2geom(rect.min()), to_2geom(rect.max())); return rect2geom; @@ -54,13 +40,6 @@ inline Geom::OptRect to_2geom(boost::optional<NR::Rect> const & rect) { return rect2geom; } -inline NR::scale from_2geom(Geom::Scale const & in) { - return NR::scale(in[Geom::X], in[Geom::Y]); -} -inline Geom::Scale to_2geom(NR::scale const & in) { - return Geom::Scale(in[NR::X], in[NR::Y]); -} - #endif /* diff --git a/src/libnr/nr-matrix-fns.cpp b/src/libnr/nr-matrix-fns.cpp deleted file mode 100644 index c8eb986fa..000000000 --- a/src/libnr/nr-matrix-fns.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include <libnr/nr-matrix-fns.h> -#include <cstdio> - -namespace NR { - -Matrix elliptic_quadratic_form(Matrix const &m) { - double const od = m[0] * m[1] + m[2] * m[3]; - return Matrix((m[0]*m[0] + m[1]*m[1]), od, - od, (m[2]*m[2] + m[3]*m[3]), - 0, 0); -/* def quadratic_form((a, b), (c, d)): - return ((a*a + c*c), a*c+b*d),(a*c+b*d, (b*b + d*d)) */ -} - -Eigen::Eigen(Matrix const &m) { - double const B = -m[0] - m[3]; - double const C = m[0]*m[3] - m[1]*m[2]; - double const center = -B/2.0; - double const delta = sqrt(B*B-4*C)/2.0; - values = Point(center + delta, center - delta); - for (int i = 0; i < 2; i++) { - vectors[i] = unit_vector(rot90(Point(m[0]-values[i], m[1]))); - } -} - -/** Returns just the scale/rotate/skew part of the matrix without the translation part. */ -Matrix transform(Matrix const &m) { - Matrix const ret(m[0], m[1], - m[2], m[3], - 0, 0); - return ret; -} - -translate get_translation(Matrix const &m) { - return translate(m[4], m[5]); -} - -void matrix_print(const gchar *say, Matrix const &m) -{ - printf ("%s %g %g %g %g %g %g\n", say, m[0], m[1], m[2], m[3], m[4], m[5]); -} - -} // namespace NR - - -/* - 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-matrix-fns.h b/src/libnr/nr-matrix-fns.h deleted file mode 100644 index a46aca909..000000000 --- a/src/libnr/nr-matrix-fns.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef SEEN_NR_MATRIX_FNS_H -#define SEEN_NR_MATRIX_FNS_H - -#include "nr-matrix.h" -#include <math.h> - -namespace NR { - -/** Given a matrix m such that unit_circle = m*x, this returns the - * quadratic form x*A*x = 1. */ -Matrix elliptic_quadratic_form(Matrix const &m); - -/** Given a matrix (ignoring the translation) this returns the eigen - * values and vectors. */ -class Eigen{ -public: - Point vectors[2]; - Point values; - Eigen(Matrix const &m); -}; - -// Matrix factories -Matrix from_basis(const Point x_basis, const Point y_basis, const Point offset=Point(0,0)); - -Matrix identity(); - -double expansion(Matrix const &m); -inline double expansionX(Matrix const &m) { return hypot(m[0], m[1]); } -inline double expansionY(Matrix const &m) { return hypot(m[2], m[3]); } - -bool transform_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon); -bool translate_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon); -bool matrix_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon); - -Matrix transform(Matrix const &m); -translate get_translation(Matrix const &m); - -void matrix_print(const gchar *say, Matrix const &m); - -} // namespace NR - -#endif /* !SEEN_NR_MATRIX_FNS_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-matrix-ops.h b/src/libnr/nr-matrix-ops.h deleted file mode 100644 index e534f9cf6..000000000 --- a/src/libnr/nr-matrix-ops.h +++ /dev/null @@ -1,41 +0,0 @@ -/* operator functions for NR::Matrix. */ -#ifndef SEEN_NR_MATRIX_OPS_H -#define SEEN_NR_MATRIX_OPS_H - -#include <libnr/nr-matrix.h> - -namespace NR { - -inline bool operator==(Matrix const &a, Matrix const &b) -{ - for(unsigned i = 0; i < 6; ++i) { - if ( a[i] != b[i] ) { - return false; - } - } - return true; -} - -inline bool operator!=(Matrix const &a, Matrix const &b) -{ - return !( a == b ); -} - -Matrix operator*(Matrix const &a, Matrix const &b); - -inline Matrix &operator*=(Matrix &a, Matrix const &b) { a = a * b; return a; } - -} /* namespace NR */ - -#endif /* !SEEN_NR_MATRIX_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-matrix-rotate-ops.cpp b/src/libnr/nr-matrix-rotate-ops.cpp deleted file mode 100644 index 625291575..000000000 --- a/src/libnr/nr-matrix-rotate-ops.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "libnr/nr-matrix-ops.h" - -NR::Matrix operator*(NR::Matrix const &m, NR::rotate const &r) -{ - return m * NR::Matrix(r); -} - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-matrix-rotate-ops.h b/src/libnr/nr-matrix-rotate-ops.h deleted file mode 100644 index 44d9c8726..000000000 --- a/src/libnr/nr-matrix-rotate-ops.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SEEN_LIBNR_NR_MATRIX_ROTATE_OPS_H -#define SEEN_LIBNR_NR_MATRIX_ROTATE_OPS_H - -#include "libnr/nr-forward.h" - -NR::Matrix operator*(NR::Matrix const &m, NR::rotate const &r); - - -#endif /* !SEEN_LIBNR_NR_MATRIX_ROTATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-matrix-scale-ops.h b/src/libnr/nr-matrix-scale-ops.h deleted file mode 100644 index d030bb66c..000000000 --- a/src/libnr/nr-matrix-scale-ops.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef SEEN_LIBNR_NR_MATRIX_SCALE_OPS_H -#define SEEN_LIBNR_NR_MATRIX_SCALE_OPS_H -/** \file - * Declarations (and definition if inline) of operator blah (NR::Matrix, NR::scale). - */ - -#include "libnr/nr-forward.h" - -namespace NR { - -inline Matrix &operator/=(Matrix &m, scale const &s) { - m[0] /= s[X]; m[1] /= s[Y]; - m[2] /= s[X]; m[3] /= s[Y]; - m[4] /= s[X]; m[5] /= s[Y]; - return m; -} - -inline Matrix &operator*=(Matrix &m, scale const &s) { - m[0] *= s[X]; m[1] *= s[Y]; - m[2] *= s[X]; m[3] *= s[Y]; - m[4] *= s[X]; m[5] *= s[Y]; - return m; -} - -inline Matrix operator/(Matrix const &m, scale const &s) { Matrix ret(m); ret /= s; return ret; } - -inline Matrix operator*(Matrix const &m, scale const &s) { Matrix ret(m); ret *= s; return ret; } - -} - -#endif /* !SEEN_LIBNR_NR_MATRIX_SCALE_OPS_H */ diff --git a/src/libnr/nr-matrix-test.h b/src/libnr/nr-matrix-test.h deleted file mode 100644 index d4267ffa5..000000000 --- a/src/libnr/nr-matrix-test.h +++ /dev/null @@ -1,191 +0,0 @@ -#include <cxxtest/TestSuite.h> - -#include <libnr/nr-matrix.h> -#include <libnr/nr-matrix-fns.h> -#include <libnr/nr-matrix-ops.h> -#include <libnr/nr-matrix-rotate-ops.h> -#include <libnr/nr-matrix-scale-ops.h> -#include <libnr/nr-point-matrix-ops.h> -#include <libnr/nr-rotate.h> -#include <libnr/nr-rotate-ops.h> -#include <libnr/nr-scale-ops.h> -#include <libnr/nr-scale-translate-ops.h> -#include <libnr/nr-translate.h> -#include <libnr/nr-translate-ops.h> -#include <libnr/nr-translate-scale-ops.h> - -inline bool point_equalp(NR::Point const &a, NR::Point const &b) -{ - return ( NR_DF_TEST_CLOSE(a[NR::X], b[NR::X], 1e-5) && - NR_DF_TEST_CLOSE(a[NR::Y], b[NR::Y], 1e-5) ); -} - -class NrMatrixTest : public CxxTest::TestSuite -{ -public: - - NrMatrixTest() : - m_id( NR::identity() ), - r_id( NR::Point(1, 0) ), - t_id( 0, 0 ), - c16( 1.0, 2.0, - 3.0, 4.0, - 5.0, 6.0), - r86( NR::Point(.8, .6) ), - mr86( r86 ), - t23( 2.0, 3.0 ), - s_id( 1.0, 1.0 ) - { - } - virtual ~NrMatrixTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrMatrixTest *createSuite() { return new NrMatrixTest(); } - static void destroySuite( NrMatrixTest *suite ) { delete suite; } - - NR::Matrix const m_id; - NR::rotate const r_id; - NR::translate const t_id; - NR::Matrix const c16; - NR::rotate const r86; - NR::Matrix const mr86; - NR::translate const t23; - NR::scale const s_id; - - - - - void testCtorsAssignmentOp(void) - { - NR::Matrix const c16_copy(c16); - NR::Matrix c16_eq(m_id); - c16_eq = c16; - for(unsigned i = 0; i < 6; ++i) { - TS_ASSERT_EQUALS( c16[i], 1.0 + i ); - TS_ASSERT_EQUALS( c16[i], c16_copy[i] ); - TS_ASSERT_EQUALS( c16[i], c16_eq[i] ); - TS_ASSERT_EQUALS( m_id[i], double( i == 0 || i == 3 ) ); - } - } - - void testScaleCtor(void) - { - NR::scale const s(2.0, 3.0); - NR::Matrix const ms(s); - NR::Point const p(5.0, 7.0); - TS_ASSERT_EQUALS( p * s, NR::Point(10.0, 21.0) ); - TS_ASSERT_EQUALS( p * ms, NR::Point(10.0, 21.0) ); - } - - void testRotateCtor(void) - { - NR::Point const p0(1.0, 0.0); - NR::Point const p90(0.0, 1.0); - TS_ASSERT_EQUALS( p0 * r86, NR::Point(.8, .6) ); - TS_ASSERT_EQUALS( p0 * mr86, NR::Point(.8, .6) ); - TS_ASSERT_EQUALS( p90 * r86, NR::Point(-.6, .8) ); - TS_ASSERT_EQUALS( p90 * mr86, NR::Point(-.6, .8) ); - TS_ASSERT( matrix_equalp(NR::Matrix( r86 * r86 ), - mr86 * mr86, - 1e-14) ); - } - - void testTranslateCtor(void) - { - NR::Matrix const mt23(t23); - NR::Point const b(-2.0, 3.0); - TS_ASSERT_EQUALS( b * t23, b * mt23 ); - } - - void testIdentity(void) - { - TS_ASSERT( m_id.test_identity() ); - TS_ASSERT( NR::Matrix(t_id).test_identity() ); - TS_ASSERT( !(NR::Matrix(NR::translate(-2, 3)).test_identity()) ); - TS_ASSERT( NR::Matrix(r_id).test_identity() ); - NR::rotate const rot180(NR::Point(-1, 0)); - TS_ASSERT( !(NR::Matrix(rot180).test_identity()) ); - TS_ASSERT( NR::Matrix(s_id).test_identity() ); - TS_ASSERT( !(NR::Matrix(NR::scale(1.0, 0.0)).test_identity()) ); - TS_ASSERT( !(NR::Matrix(NR::scale(0.0, 1.0)).test_identity()) ); - TS_ASSERT( !(NR::Matrix(NR::scale(1.0, -1.0)).test_identity()) ); - TS_ASSERT( !(NR::Matrix(NR::scale(-1.0, -1.0)).test_identity()) ); - } - - void testInverse(void) - { - TS_ASSERT_EQUALS( m_id.inverse(), m_id ); - TS_ASSERT_EQUALS( NR::Matrix(t23).inverse(), NR::Matrix(NR::translate(-2.0, -3.0)) ); - NR::scale const s2(-4.0, 2.0); - NR::scale const sp5(-.25, .5); - TS_ASSERT_EQUALS( NR::Matrix(s2).inverse(), NR::Matrix(sp5) ); - TS_ASSERT_EQUALS( NR::Matrix(sp5).inverse(), NR::Matrix(s2) ); - } - - void testEllipticQuadraticForm(void) - { - NR::Matrix const aff(1.0, 1.0, - 0.0, 1.0, - 5.0, 6.0); - NR::Matrix const invaff = aff.inverse(); - TS_ASSERT_EQUALS( invaff[1], -1.0 ); - - NR::Matrix const ef(elliptic_quadratic_form(invaff)); - NR::Matrix const exp_ef(2, -1, - -1, 1, - 0, 0); - TS_ASSERT_EQUALS( ef, exp_ef ); - } - - void testMatrixStarRotate(void) - { - NR::Matrix const ma(2.0, -1.0, - 4.0, 4.0, - -0.5, 2.0); - NR::Matrix const a_r86( ma * r86 ); - NR::Matrix const ma1( a_r86 * r86.inverse() ); - TS_ASSERT( matrix_equalp(ma1, ma, 1e-12) ); - NR::Matrix const exp_a_r86( 2*.8 + -1*-.6, 2*.6 + -1*.8, - 4*.8 + 4*-.6, 4*.6 + 4*.8, - -.5*.8 + 2*-.6, -.5*.6 + 2*.8 ); - TS_ASSERT( matrix_equalp(a_r86, exp_a_r86, 1e-12) ); - } - - void testTranslateStarScale_ScaleStarTranslate(void) - { - NR::translate const t2n4(2, -4); - NR::scale const sn2_8(-2, 8); - NR::Matrix const exp_ts(-2, 0, - 0, 8, - -4, -32); - NR::Matrix const exp_st(-2, 0, - 0, 8, - 2, -4); - TS_ASSERT_EQUALS( exp_ts, t2n4 * sn2_8 ); - TS_ASSERT_EQUALS( exp_st, sn2_8 * t2n4 ); - } - - void testMatrixStarScale(void) - { - NR::Matrix const ma(2.0, -1.0, - 4.0, 4.0, - -0.5, 2.0); - NR::scale const sn2_8(-2, 8); - NR::Matrix const exp_as(-4, -8, - -8, 32, - 1, 16); - TS_ASSERT_EQUALS( ma * sn2_8, exp_as ); - } -}; - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-matrix-translate-ops.h b/src/libnr/nr-matrix-translate-ops.h deleted file mode 100644 index 6e5607759..000000000 --- a/src/libnr/nr-matrix-translate-ops.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef SEEN_LIBNR_NR_MATRIX_TRANSLATE_OPS_H -#define SEEN_LIBNR_NR_MATRIX_TRANSLATE_OPS_H - -/** \file - * Declarations (and definition if inline) of operator - * blah (NR::Matrix, NR::translate). - */ - -#include "libnr/nr-matrix.h" -#include "libnr/nr-translate.h" - -namespace NR { - -inline Matrix &operator*=(Matrix &m, translate const &t) { - m[4] += t[X]; - m[5] += t[Y]; - return m; -} - -inline Matrix operator*(Matrix const &m, translate const &t) { Matrix ret(m); ret *= t; return ret; } - -inline Matrix operator/(Matrix const &numer, translate const &denom) { return numer * translate(-denom.offset); } - -} - -#endif /* !SEEN_LIBNR_NR_MATRIX_TRANSLATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-matrix.cpp b/src/libnr/nr-matrix.cpp deleted file mode 100644 index c7948a96e..000000000 --- a/src/libnr/nr-matrix.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#define __NR_MATRIX_C__ - -/** \file - * Various matrix routines. Currently includes some NR::rotate etc. routines too. - */ - -/* - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include <cstdlib> -#include "nr-matrix.h" -#include "nr-matrix-fns.h" - - - -/** - * Implement NR functions and methods - */ -namespace NR { - - - - - -/** - * Multiply two matrices together - */ -Matrix operator*(Matrix const &m0, Matrix const &m1) -{ - NR::Coord const d0 = m0[0] * m1[0] + m0[1] * m1[2]; - NR::Coord const d1 = m0[0] * m1[1] + m0[1] * m1[3]; - NR::Coord const d2 = m0[2] * m1[0] + m0[3] * m1[2]; - NR::Coord const d3 = m0[2] * m1[1] + m0[3] * m1[3]; - NR::Coord const d4 = m0[4] * m1[0] + m0[5] * m1[2] + m1[4]; - NR::Coord const d5 = m0[4] * m1[1] + m0[5] * m1[3] + m1[5]; - - Matrix ret( d0, d1, d2, d3, d4, d5 ); - - return ret; -} - - - - - -/** - * Return the inverse of this matrix. If an inverse is not defined, - * then return the identity matrix. - */ -Matrix Matrix::inverse() const -{ - Matrix d(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - - NR::Coord const det = _c[0] * _c[3] - _c[1] * _c[2]; - if (!NR_DF_TEST_CLOSE(det, 0.0, NR_EPSILON)) { - - NR::Coord const idet = 1.0 / det; - NR::Coord *dest = d._c; - - /*0*/ *dest++ = _c[3] * idet; - /*1*/ *dest++ = -_c[1] * idet; - /*2*/ *dest++ = -_c[2] * idet; - /*3*/ *dest++ = _c[0] * idet; - /*4*/ *dest++ = -_c[4] * d._c[0] - _c[5] * d._c[2]; - /*5*/ *dest = -_c[4] * d._c[1] - _c[5] * d._c[3]; - - } else { - d.set_identity(); - } - - return d; -} - - - - - -/** - * Set this matrix to Identity - */ -void Matrix::set_identity() -{ - NR::Coord *dest = _c; - - *dest++ = 1.0; //0 - *dest++ = 0.0; //1 - *dest++ = 0.0; //2 - *dest++ = 1.0; //3 - // translation - *dest++ = 0.0; //4 - *dest = 0.0; //5 -} - - - - - -/** - * return an Identity matrix - */ -Matrix identity() -{ - Matrix ret(1.0, 0.0, - 0.0, 1.0, - 0.0, 0.0); - return ret; -} - - - - - -/** - * - */ -Matrix from_basis(Point const x_basis, Point const y_basis, Point const offset) -{ - Matrix const ret(x_basis[X], y_basis[X], - x_basis[Y], y_basis[Y], - offset[X], offset[Y]); - return ret; -} - - - - -/** - * Returns a rotation matrix corresponding by the specified angle (in radians) about the origin. - * - * \see NR::rotate_degrees - * - * 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. - */ -rotate::rotate(NR::Coord const theta) : - vec(cos(theta), - sin(theta)) -{ -} - - - - - -/** - * Return the determinant of the Matrix - */ -NR::Coord Matrix::det() const -{ - return _c[0] * _c[3] - _c[1] * _c[2]; -} - - - - - -/** - * Return the scalar of the descriminant of the Matrix - */ -NR::Coord Matrix::descrim2() const -{ - return fabs(det()); -} - - - - - -/** - * Return the descriminant of the Matrix - */ -NR::Coord Matrix::descrim() const -{ - return sqrt(descrim2()); -} - - - - - -/** - * - */ -bool Matrix::is_translation(Coord const eps) const { - return ( fabs(_c[0] - 1.0) < eps && - fabs(_c[3] - 1.0) < eps && - fabs(_c[1]) < eps && - fabs(_c[2]) < eps ); -} - - -/** - * - */ -bool Matrix::is_scale(Coord const eps) const { - return ( (fabs(_c[0] - 1.0) > eps || fabs(_c[3] - 1.0) > eps) && - fabs(_c[1]) < eps && - fabs(_c[2]) < eps ); -} - - -/** - * - */ -bool Matrix::is_rotation(Coord const eps) const { - return ( fabs(_c[1]) > eps && - fabs(_c[2]) > eps && - fabs(_c[1] + _c[2]) < 2 * eps); -} - - - - - -/** - * test whether the matrix is the identity matrix (true). (2geom's Matrix::isIdentity() does the same) - */ -bool Matrix::test_identity() const { - return matrix_equalp(*this, NR_MATRIX_IDENTITY, NR_EPSILON); -} - - - - - -/** - * calculates the descriminant of the matrix. (Geom::Coord Matrix::descrim() does the same) - */ -double expansion(Matrix const &m) { - return sqrt(fabs(m.det())); -} - - - - - -/** - * - */ -bool transform_equalp(Matrix const &m0, Matrix const &m1, NR::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); -} - - - - - -/** - * - */ -bool translate_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon) { - return NR_DF_TEST_CLOSE(m0[4], m1[4], epsilon) && NR_DF_TEST_CLOSE(m0[5], m1[5], epsilon); -} - - - - - -/** - * - */ -bool matrix_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon) { - return transform_equalp(m0, m1, epsilon) && translate_equalp(m0, m1, epsilon); -} - - - -} //namespace NR - - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-matrix.h b/src/libnr/nr-matrix.h deleted file mode 100644 index b1f9d589a..000000000 --- a/src/libnr/nr-matrix.h +++ /dev/null @@ -1,313 +0,0 @@ -#ifndef __NR_MATRIX_H__ -#define __NR_MATRIX_H__ - -/** \file - * Definition of NR::Matrix type. - * - * \note Operator functions (e.g. Matrix * Matrix etc.) are mostly in - * libnr/nr-matrix-ops.h. See end of file for discussion. - * - * Main authors: - * Lauris Kaplinski <lauris@kaplinski.com>: - * Original NRMatrix definition and related macros. - * - * Nathan Hurst <njh@mail.csse.monash.edu.au>: - * NR::Matrix class version of the above. - * - * This code is in public domain. - */ - -#include <glib.h> // g_assert() -#include <glib/gmessages.h> - -#include "libnr/nr-coord.h" -#include "libnr/nr-values.h" -#include <libnr/nr-rotate.h> -#include <libnr/nr-scale.h> -#include <libnr/nr-translate.h> -#include <2geom/matrix.h> - -namespace NR { - -/** - * The Matrix class. - * - * For purposes of multiplication, points should be thought of as row vectors - * - * p = ( p[X] p[Y] 1 ) - * - * to be right-multiplied by transformation matrices - * \verbatim - c[] = | c[0] c[1] 0 | - | c[2] c[3] 0 | - | c[4] c[5] 1 | \endverbatim - * - * (so the columns of the matrix correspond to the columns (elements) of the result, - * and the rows of the matrix correspond to columns (elements) of the "input"). - */ -class Matrix { - - - public: - - /** - * Various forms of constructor - */ - - /** - * - */ - explicit Matrix() { } - - - /** - * - */ - Matrix(Matrix const &m) { - - NR::Coord const *src = m._c; - NR::Coord *dest = _c; - - *dest++ = *src++; //0 - *dest++ = *src++; //1 - *dest++ = *src++; //2 - *dest++ = *src++; //3 - *dest++ = *src++; //4 - *dest = *src ; //5 - - } - - - Matrix(Geom::Matrix const &m) { - NR::Coord *dest = _c; - - *dest++ = m[0]; - *dest++ = m[1]; - *dest++ = m[2]; - *dest++ = m[3]; - *dest++ = m[4]; - *dest = m[5]; - } - - /** - * - */ - Matrix(double c0, double c1, - double c2, double c3, - double c4, double c5) { - - NR::Coord *dest = _c; - - *dest++ = c0; //0 - *dest++ = c1; //1 - *dest++ = c2; //2 - *dest++ = c3; //3 - *dest++ = c4; //4 - *dest = c5; //5 - - } - - - - /** - * - */ - Matrix &operator=(Matrix const &m) { - - NR::Coord const *src = m._c; - NR::Coord *dest = _c; - - *dest++ = *src++; //0 - *dest++ = *src++; //1 - *dest++ = *src++; //2 - *dest++ = *src++; //3 - *dest++ = *src++; //4 - *dest = *src ; //5 - - return *this; - } - - - - - /** - * - */ - explicit Matrix(scale const &sm) { - - NR::Coord *dest = _c; - - *dest++ = sm[X]; //0 - *dest++ = 0.0; //1 - *dest++ = 0.0; //2 - *dest++ = sm[Y]; //3 - *dest++ = 0.0; //4 - *dest = 0.0; //5 - - } - - - - - - - /** - * - */ - explicit Matrix(rotate const &r) { - - NR::Coord *dest = _c; - - *dest++ = r.vec[X]; //0 - *dest++ = r.vec[Y]; //1 - *dest++ = -r.vec[Y]; //2 - *dest++ = r.vec[X]; //3 - *dest++ = 0.0; //4 - *dest = 0.0; //5 - - } - - - - - /** - * - */ - explicit Matrix(translate const &tm) { - - NR::Coord *dest = _c; - - *dest++ = 1.0; //0 - *dest++ = 0.0; //1 - *dest++ = 0.0; //2 - *dest++ = 1.0; //3 - *dest++ = tm[X]; //4 - *dest = tm[Y]; //5 - } - - - /** - * - */ - bool test_identity() const; - - - /** - * - */ - bool is_translation(Coord const eps = 1e-6) const; - - /** - * - */ - bool is_scale(Coord const eps = 1e-6) const; - - /** - * - */ - bool is_rotation(Coord const eps = 1e-6) const; - - - /** - * - */ - Matrix inverse() const; - - - - /** - * - */ - inline Coord &operator[](int const i) { - return _c[i]; - } - - - - /** - * - */ - inline Coord operator[](int const i) const { - return _c[i]; - } - - inline operator Geom::Matrix() const { - return Geom::Matrix(_c[0], _c[1], _c[2], _c[3], _c[4], _c[5]); - } - - /** - * - */ - void set_identity(); - - /** - * - */ - Coord det() const; - - - /** - * - */ - Coord descrim2() const; - - - /** - * - */ - Coord descrim() const; - - - private: - - - NR::Coord _c[6]; -}; - -/** A function to print out the Matrix (for debugging) */ -inline std::ostream &operator<< (std::ostream &out_file, const NR::Matrix &m) { - out_file << "A: " << m[0] << " C: " << m[2] << " E: " << m[4] << "\n"; - out_file << "B: " << m[1] << " D: " << m[3] << " F: " << m[5] << "\n"; - return out_file; -} - -} /* namespace NR */ - - - - - - - -/** \note - * Discussion of splitting up nr-matrix.h into lots of little files: - * - * Advantages: - * - * - Reducing amount of recompilation necessary when anything changes. - * - * - Hopefully also reducing compilation time by reducing the number of inline - * function definitions encountered by the compiler for a given .o file. - * (No timing comparisons done yet. On systems without much memory available - * for caching, this may be outweighed by additional I/O costs.) - * - * Disadvantages: - * - * - More #include lines necessary per file. If a compile fails due to - * not having all the necessary #include lines, then the developer needs - * to spend some time working out what #include to add. - */ - -#endif /* !__NR_MATRIX_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-point-matrix-ops.h b/src/libnr/nr-point-matrix-ops.h deleted file mode 100644 index 81e351103..000000000 --- a/src/libnr/nr-point-matrix-ops.h +++ /dev/null @@ -1,49 +0,0 @@ -/** @file - * @brief Operator functions over (NR::Point, NR::Matrix) - */ -#ifndef SEEN_NR_POINT_MATRIX_OPS_H -#define SEEN_NR_POINT_MATRIX_OPS_H - -#include "libnr/nr-point.h" -#include "libnr/nr-matrix.h" - -namespace NR { - -inline Point operator*(Point const &v, Matrix const &m) -{ -#if 1 /* Which code makes it easier to see what's happening? */ - NR::Point const xform_col0(m[0], - m[2]); - NR::Point const xform_col1(m[1], - m[3]); - NR::Point const xlate(m[4], m[5]); - return ( Point(dot(v, xform_col0), - dot(v, xform_col1)) - + xlate ); -#else - return Point(v[X] * m[0] + v[Y] * m[2] + m[4], - v[X] * m[1] + v[Y] * m[3] + m[5]); -#endif -} - -inline Point &Point::operator*=(Matrix const &m) -{ - *this = *this * m; - return *this; -} - -} /* namespace NR */ - - -#endif /* !SEEN_NR_POINT_MATRIX_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index 1e1f36104..58e16e963 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -11,6 +11,7 @@ #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]), @@ -220,6 +221,8 @@ nr_rect_d_union_xy (NRRect *d, NR::Coord x, NR::Coord y) NRRect * nr_rect_d_matrix_transform(NRRect *d, NRRect const *const s, NR::Matrix const &m) { + // defunct + /* using NR::X; using NR::Y; @@ -238,7 +241,7 @@ nr_rect_d_matrix_transform(NRRect *d, NRRect const *const s, NR::Matrix const &m std::max(c10[X], c11[X])); d->y1 = std::max(std::max(c00[Y], c01[Y]), std::max(c10[Y], c11[Y])); - } + }*/ return d; } diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h index c074b0034..f64b04f72 100644 --- a/src/libnr/nr-rect.h +++ b/src/libnr/nr-rect.h @@ -16,19 +16,23 @@ #include <stdexcept> #include <limits> +#include <glib.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-point-matrix-ops.h> #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 @@ -136,11 +140,6 @@ public: return Rect(s * min(), s * max()); } - /** Transforms the rect by m. Note that it gives correct results only for scales and translates */ - inline Rect operator*(Matrix const m) const { - return Rect(_min * m, _max * m); - } - inline bool operator==(Rect const &in_rect) { return ((this->min() == in_rect.min()) && (this->max() == in_rect.max())); } diff --git a/src/libnr/nr-rotate-fns-test.h b/src/libnr/nr-rotate-fns-test.h deleted file mode 100644 index e3bfe3043..000000000 --- a/src/libnr/nr-rotate-fns-test.h +++ /dev/null @@ -1,54 +0,0 @@ -#include <cxxtest/TestSuite.h> - -#include <cmath> -#include <glib/gmacros.h> - -#include <libnr/nr-rotate-fns.h> - -class NrRotateFnsTest : public CxxTest::TestSuite -{ -public: - - NrRotateFnsTest() - { - } - virtual ~NrRotateFnsTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrRotateFnsTest *createSuite() { return new NrRotateFnsTest(); } - static void destroySuite( NrRotateFnsTest *suite ) { delete suite; } - - - - void testRotateDegrees(void) - { - double const d[] = { - 0, 90, 180, 270, 360, 45, 45.01, 44.99, 134, 135, 136, 314, 315, 317, 359, 361 - }; - for ( unsigned i = 0; i < G_N_ELEMENTS(d); ++i ) { - double const degrees = d[i]; - NR::rotate const rot(rotate_degrees(degrees)); - NR::rotate const rot_approx( M_PI * ( degrees / 180. ) ); - TS_ASSERT( rotate_equalp(rot, rot_approx, 1e-12) ); - - NR::rotate const rot_inv(rotate_degrees(-degrees)); - NR::rotate const rot_compl(rotate_degrees(360 - degrees)); - TS_ASSERT( rotate_equalp(rot_inv, rot_compl, 1e-12) ); - - TS_ASSERT( !rotate_equalp(rot, rotate_degrees(degrees + 1), 1e-5) ); - } - } - -}; - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-rotate-fns.cpp b/src/libnr/nr-rotate-fns.cpp deleted file mode 100644 index f2669c20c..000000000 --- a/src/libnr/nr-rotate-fns.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/** \file - * Functions to/from NR::rotate. - */ -#include <glib.h> -#include "libnr/nr-rotate-ops.h" -#include "libnr/nr-rotate-fns.h" - -/** - * Returns a rotation matrix corresponding by the specified angle about the origin. - * - * 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. - */ -NR::rotate -rotate_degrees(double degrees) -{ - if (degrees < 0) { - return rotate_degrees(-degrees).inverse(); - } - - double const degrees0 = degrees; - if (degrees >= 360) { - degrees = fmod(degrees, 360); - } - - NR::rotate ret(1., 0.); - - if (degrees >= 180) { - NR::rotate const rot180(-1., 0.); - degrees -= 180; - ret = rot180; - } - - if (degrees >= 90) { - NR::rotate const rot90(0., 1.); - degrees -= 90; - ret *= rot90; - } - - if (degrees == 45) { - NR::rotate const rot45(M_SQRT1_2, M_SQRT1_2); - ret *= rot45; - } else { - double const radians = M_PI * ( degrees / 180 ); - ret *= NR::rotate(cos(radians), sin(radians)); - } - - NR::rotate const raw_ret( M_PI * ( degrees0 / 180 ) ); - g_return_val_if_fail(rotate_equalp(ret, raw_ret, 1e-8), - raw_ret); - return ret; -} - - -/* - 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-rotate-fns.h b/src/libnr/nr-rotate-fns.h deleted file mode 100644 index bd075114c..000000000 --- a/src/libnr/nr-rotate-fns.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SEEN_NR_ROTATE_FNS_H -#define SEEN_NR_ROTATE_FNS_H - -/** \file - * Declarations for rotation functions. - */ - -#include <libnr/nr-rotate.h> -#include <libnr/nr-point-fns.h> - -inline bool rotate_equalp(NR::rotate const &a, NR::rotate const &b, double const eps) -{ - return point_equalp(a.vec, b.vec, eps); -} - -NR::rotate rotate_degrees(double degrees); - -#endif /* !SEEN_NR_ROTATE_FNS_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-rotate-matrix-ops.cpp b/src/libnr/nr-rotate-matrix-ops.cpp deleted file mode 100644 index dd3851643..000000000 --- a/src/libnr/nr-rotate-matrix-ops.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include <libnr/nr-matrix-ops.h> - -NR::Matrix -operator*(NR::rotate const &a, NR::Matrix const &b) -{ - return NR::Matrix(a) * b; -} - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-rotate-matrix-ops.h b/src/libnr/nr-rotate-matrix-ops.h deleted file mode 100644 index d2f0eadba..000000000 --- a/src/libnr/nr-rotate-matrix-ops.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef SEEN_LIBNR_NR_ROTATE_MATRIX_OPS_H -#define SEEN_LIBNR_NR_ROTATE_MATRIX_OPS_H - -#include <libnr/nr-forward.h> - - -NR::Matrix operator*(NR::rotate const &a, NR::Matrix const &b); - - -#endif /* !SEEN_LIBNR_NR_ROTATE_MATRIX_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-rotate-ops.h b/src/libnr/nr-rotate-ops.h deleted file mode 100644 index 4b60b9d0c..000000000 --- a/src/libnr/nr-rotate-ops.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef SEEN_NR_ROTATE_OPS_H -#define SEEN_NR_ROTATE_OPS_H -#include <libnr/nr-rotate.h> - -namespace NR { - -inline Point operator*(Point const &v, rotate const &r) -{ - return Point(r.vec[X] * v[X] - r.vec[Y] * v[Y], - r.vec[Y] * v[X] + r.vec[X] * v[Y]); -} - -inline rotate operator*(rotate const &a, rotate const &b) -{ - return rotate( a.vec * b ); -} - -inline rotate &rotate::operator*=(rotate const &b) -{ - *this = *this * b; - return *this; -} - -inline rotate operator/(rotate const &numer, rotate const &denom) -{ - return numer * denom.inverse(); -} - -} /* namespace NR */ - - -#endif /* !SEEN_NR_ROTATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-rotate-test.h b/src/libnr/nr-rotate-test.h deleted file mode 100644 index 5514d09d1..000000000 --- a/src/libnr/nr-rotate-test.h +++ /dev/null @@ -1,110 +0,0 @@ -#include <cxxtest/TestSuite.h> - -#include <cmath> -#include <libnr/nr-matrix.h> -#include <libnr/nr-matrix-ops.h> -#include <libnr/nr-matrix-fns.h> /* identity, matrix_equalp */ -#include <libnr/nr-point-fns.h> -#include <libnr/nr-rotate.h> -#include <libnr/nr-rotate-fns.h> -#include <libnr/nr-rotate-ops.h> - - -class NrRotateTest : public CxxTest::TestSuite -{ -public: - - NrRotateTest() : - m_id( NR::identity() ), - r_id( 0.0 ), - rot234( .234 ), - b( -2.0, 3.0 ), - rot180( NR::Point(-1.0, 0.0) ) - { - } - virtual ~NrRotateTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrRotateTest *createSuite() { return new NrRotateTest(); } - static void destroySuite( NrRotateTest *suite ) { delete suite; } - - NR::Matrix const m_id; - NR::rotate const r_id; - NR::rotate const rot234; - NR::Point const b; - NR::rotate const rot180; - - - - - void testCtorsCompares(void) - { - TS_ASSERT_EQUALS( r_id, r_id ); - TS_ASSERT_EQUALS( rot234, rot234 ); - TS_ASSERT_DIFFERS( rot234, r_id ); - TS_ASSERT_EQUALS( r_id, NR::rotate(NR::Point(1.0, 0.0)) ); - TS_ASSERT_EQUALS( NR::Matrix(r_id), m_id ); - TS_ASSERT( NR::Matrix(r_id).test_identity() ); - - TS_ASSERT(rotate_equalp(rot234, NR::rotate(NR::Point(cos(.234), sin(.234))), 1e-12)); - } - - void testAssignmentOp(void) - { - NR::rotate rot234_eq(r_id); - rot234_eq = rot234; - TS_ASSERT_EQUALS( rot234, rot234_eq ); - TS_ASSERT_DIFFERS( rot234_eq, r_id ); - } - - void testInverse(void) - { - TS_ASSERT_EQUALS( r_id.inverse(), r_id ); - TS_ASSERT_EQUALS( rot234.inverse(), NR::rotate(-.234) ); - } - - void testOpStarPointRotate(void) - { - TS_ASSERT_EQUALS( b * r_id, b ); - TS_ASSERT_EQUALS( b * rot180, -b ); - TS_ASSERT_EQUALS( b * rot234, b * NR::Matrix(rot234) ); - TS_ASSERT(point_equalp(b * NR::rotate(M_PI / 2), - NR::rot90(b), - 1e-14)); - TS_ASSERT_EQUALS( b * rotate_degrees(90.), NR::rot90(b) ); - } - - void testOpStarRotateRotate(void) - { - TS_ASSERT_EQUALS( r_id * r_id, r_id ); - TS_ASSERT_EQUALS( rot180 * rot180, r_id ); - TS_ASSERT_EQUALS( rot234 * r_id, rot234 ); - TS_ASSERT_EQUALS( r_id * rot234, rot234 ); - TS_ASSERT( rotate_equalp(rot234 * rot234.inverse(), r_id, 1e-14) ); - TS_ASSERT( rotate_equalp(rot234.inverse() * rot234, r_id, 1e-14) ); - TS_ASSERT( rotate_equalp(( NR::rotate(0.25) * NR::rotate(.5) ), - NR::rotate(.75), - 1e-10) ); - } - - void testOpDivRotateRotate(void) - { - TS_ASSERT_EQUALS( rot234 / r_id, rot234 ); - TS_ASSERT_EQUALS( rot234 / rot180, rot234 * rot180 ); - TS_ASSERT( rotate_equalp(rot234 / rot234, r_id, 1e-14) ); - TS_ASSERT( rotate_equalp(r_id / rot234, rot234.inverse(), 1e-14) ); - } - -}; - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-rotate.h b/src/libnr/nr-rotate.h deleted file mode 100644 index 051372ce6..000000000 --- a/src/libnr/nr-rotate.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SEEN_NR_ROTATE_H -#define SEEN_NR_ROTATE_H - -/** \file - * Rotation about the origin. - */ - -#include <libnr/nr-point.h> -#include <libnr/nr-point-fns.h> -#include <libnr/nr-point-ops.h> - -namespace NR { - -/** Notionally an NR::Matrix corresponding to rotation about the origin. - Behaves like NR::Matrix for multiplication. -**/ -class rotate { -public: - Point vec; - -private: - rotate(); - -public: - explicit rotate(Coord theta); - explicit rotate(Point const &p) : vec(p) {} - explicit rotate(Coord const x, Coord const y) : vec(x, y) {} - - bool operator==(rotate const &o) const { - return vec == o.vec; - } - - bool operator!=(rotate const &o) const { - return vec != o.vec; - } - - inline rotate &operator*=(rotate const &b); - /* Defined in nr-rotate-ops.h. */ - - rotate inverse() const { - /** \todo - * In the usual case that vec is a unit vector (within rounding error), - * dividing by len_sq is either a noop or numerically harmful. - * Make a unit_rotate class (or the like) that knows its length is 1. - */ - double const len_sq = dot(vec, vec); - return rotate( Point(vec[X], -vec[Y]) - / len_sq ); - } -}; - -} /* namespace NR */ - - -#endif /* !SEEN_NR_ROTATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-scale-matrix-ops.cpp b/src/libnr/nr-scale-matrix-ops.cpp deleted file mode 100644 index 5b19efaea..000000000 --- a/src/libnr/nr-scale-matrix-ops.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "libnr/nr-matrix-ops.h" - -NR::Matrix -operator*(NR::scale const &s, NR::Matrix const &m) -{ - using NR::X; using NR::Y; - NR::Matrix ret(m); - ret[0] *= s[X]; - ret[1] *= s[X]; - ret[2] *= s[Y]; - ret[3] *= s[Y]; - return ret; -} - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-scale-matrix-ops.h b/src/libnr/nr-scale-matrix-ops.h deleted file mode 100644 index bf1b498c9..000000000 --- a/src/libnr/nr-scale-matrix-ops.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef SEEN_LIBNR_NR_SCALE_MATRIX_OPS_H -#define SEEN_LIBNR_NR_SCALE_MATRIX_OPS_H -/** \file - * Declarations (and definition if inline) of operator - * blah (NR::scale, NR::Matrix). - */ - -#include "libnr/nr-forward.h" - -NR::Matrix operator*(NR::scale const &s, NR::Matrix const &m); - - -#endif /* !SEEN_LIBNR_NR_SCALE_MATRIX_OPS_H */ diff --git a/src/libnr/nr-scale-ops.h b/src/libnr/nr-scale-ops.h deleted file mode 100644 index da1fea64c..000000000 --- a/src/libnr/nr-scale-ops.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef SEEN_NR_SCALE_OPS_H -#define SEEN_NR_SCALE_OPS_H - -#include <libnr/nr-scale.h> - -namespace NR { - -inline Point operator*(Point const &p, scale const &s) -{ - return Point(p[X] * s[X], - p[Y] * s[Y]); -} - -inline scale operator*(scale const &a, scale const &b) -{ - return scale(a[X] * b[X], - a[Y] * b[Y]); -} - -inline scale operator/(scale const &numer, scale const &denom) -{ - return scale(numer[X] / denom[X], - numer[Y] / denom[Y]); -} - -} /* namespace NR */ - - -#endif /* !SEEN_NR_SCALE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-scale-test.h b/src/libnr/nr-scale-test.h deleted file mode 100644 index 938e8e14d..000000000 --- a/src/libnr/nr-scale-test.h +++ /dev/null @@ -1,90 +0,0 @@ -#include <cxxtest/TestSuite.h> - -#include <libnr/nr-scale.h> -#include <libnr/nr-scale-ops.h> - -class NrScaleTest : public CxxTest::TestSuite -{ -public: - - NrScaleTest() : - sa( 1.5, 2.0 ), - b( -2.0, 3.0 ), - sb( b ) - { - } - virtual ~NrScaleTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrScaleTest *createSuite() { return new NrScaleTest(); } - static void destroySuite( NrScaleTest *suite ) { delete suite; } - - NR::scale const sa; - NR::Point const b; - NR::scale const sb; - - - - void testXY_CtorArrayOperator(void) - { - TS_ASSERT_EQUALS( sa[NR::X], 1.5 ); - TS_ASSERT_EQUALS( sa[NR::Y], 2.0 ); - TS_ASSERT_EQUALS( sa[0u], 1.5 ); - TS_ASSERT_EQUALS( sa[1u], 2.0 ); - } - - - void testCopyCtor_AssignmentOp_NotEquals(void) - { - NR::scale const sa_copy(sa); - TS_ASSERT_EQUALS( sa, sa_copy ); - TS_ASSERT(!( sa != sa_copy )); - TS_ASSERT( sa != sb ); - } - - void testAssignmentOp(void) - { - NR::scale sa_eq(sb); - sa_eq = sa; - TS_ASSERT_EQUALS( sa, sa_eq ); - } - - void testPointCtor(void) - { - TS_ASSERT_EQUALS( sb[NR::X], b[NR::X] ); - TS_ASSERT_EQUALS( sb[NR::Y], b[NR::Y] ); - } - - void testOpStarPointScale(void) - { - NR::Point const ab( b * sa ); - TS_ASSERT_EQUALS( ab, NR::Point(-3.0, 6.0) ); - } - - void testOpStarScaleScale(void) - { - NR::scale const sab( sa * sb ); - TS_ASSERT_EQUALS( sab, NR::scale(-3.0, 6.0) ); - } - - void testOpDivScaleScale(void) - { - NR::scale const sa_b( sa / sb ); - NR::scale const exp_sa_b(-0.75, 2./3.); - TS_ASSERT_EQUALS( sa_b[0], exp_sa_b[0] ); -// TS_ASSERT_EQUALS( fabs( sa_b[1] - exp_sa_b[1] ) < 1e-10 ); - TS_ASSERT_DELTA( sa_b[1], exp_sa_b[1], 1e-10 ); - } -}; - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-scale-translate-ops.cpp b/src/libnr/nr-scale-translate-ops.cpp deleted file mode 100644 index 911c92e5b..000000000 --- a/src/libnr/nr-scale-translate-ops.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "libnr/nr-matrix-translate-ops.h" - -NR::Matrix -operator*(NR::scale const &s, NR::translate const &t) -{ - return NR::Matrix(s) * t; -} - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-scale-translate-ops.h b/src/libnr/nr-scale-translate-ops.h deleted file mode 100644 index 2f6f23c2c..000000000 --- a/src/libnr/nr-scale-translate-ops.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SEEN_LIBNR_NR_SCALE_TRANSLATE_OPS_H -#define SEEN_LIBNR_NR_SCALE_TRANSLATE_OPS_H - -#include "libnr/nr-forward.h" - -NR::Matrix operator*(NR::scale const &s, NR::translate const &t); - - -#endif /* !SEEN_LIBNR_NR_SCALE_TRANSLATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-scale.h b/src/libnr/nr-scale.h deleted file mode 100644 index b4dbd1fb5..000000000 --- a/src/libnr/nr-scale.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SEEN_NR_SCALE_H -#define SEEN_NR_SCALE_H -#include <libnr/nr-point.h> -#include <libnr/nr-point-ops.h> - -namespace NR { - -class scale { -private: - Point _p; - -private: - scale(); - -public: - explicit scale(Point const &p) : _p(p) {} - scale(double const x, double const y) : _p(x, y) {} - explicit scale(double const s) : _p(s, s) {} - inline Coord operator[](Dim2 const d) const { return _p[d]; } - inline Coord operator[](unsigned const d) const { return _p[d]; } - inline Coord &operator[](Dim2 const d) { return _p[d]; } - inline Coord &operator[](unsigned const d) { return _p[d]; } - - bool operator==(scale const &o) const { - return _p == o._p; - } - - bool operator!=(scale const &o) const { - return _p != o._p; - } - - scale inverse() const { - return scale(1/_p[0], 1/_p[1]); - } - - NR::Point point() const { - return _p; - } -}; - -} /* namespace NR */ - - -#endif /* !SEEN_NR_SCALE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-matrix-ops.cpp b/src/libnr/nr-translate-matrix-ops.cpp deleted file mode 100644 index 47f362f9f..000000000 --- a/src/libnr/nr-translate-matrix-ops.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "libnr/nr-matrix-ops.h" - -namespace NR { - -Matrix -operator*(translate const &t, Matrix const &m) -{ - Matrix ret(m); - ret[4] += m[0] * t[X] + m[2] * t[Y]; - ret[5] += m[1] * t[X] + m[3] * t[Y]; - return ret; -} - -} /* namespace NR */ - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-matrix-ops.h b/src/libnr/nr-translate-matrix-ops.h deleted file mode 100644 index aceb123d1..000000000 --- a/src/libnr/nr-translate-matrix-ops.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SEEN_LIBNR_NR_TRANSLATE_MATRIX_OPS_H -#define SEEN_LIBNR_NR_TRANSLATE_MATRIX_OPS_H - -#include "libnr/nr-forward.h" - -namespace NR { -Matrix operator*(translate const &t, Matrix const &m); -} - - -#endif /* !SEEN_LIBNR_NR_TRANSLATE_MATRIX_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-ops.h b/src/libnr/nr-translate-ops.h deleted file mode 100644 index 14ab6d1ed..000000000 --- a/src/libnr/nr-translate-ops.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef SEEN_NR_TRANSLATE_OPS_H -#define SEEN_NR_TRANSLATE_OPS_H - -#include <libnr/nr-translate.h> -#include <libnr/nr-point-ops.h> - -namespace NR { - -inline bool operator==(translate const &a, translate const &b) -{ - return a.offset == b.offset; -} - -inline bool operator!=(translate const &a, translate const &b) -{ - return !( a == b ); -} - -inline translate operator*(translate const &a, translate const &b) -{ - return translate( a.offset + b.offset ); -} - -inline Point operator*(Point const &v, translate const &t) -{ - return t.offset + v; -} - -} /* namespace NR */ - - -#endif /* !SEEN_NR_TRANSLATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-rotate-ops.cpp b/src/libnr/nr-translate-rotate-ops.cpp deleted file mode 100644 index 35f60c10d..000000000 --- a/src/libnr/nr-translate-rotate-ops.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <libnr/nr-matrix-translate-ops.h> -#include <libnr/nr-rotate-ops.h> - -NR::Matrix -operator*(NR::translate const &a, NR::rotate const &b) -{ - return NR::Matrix(b) * NR::translate(a.offset * b); -} - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-rotate-ops.h b/src/libnr/nr-translate-rotate-ops.h deleted file mode 100644 index 0716f21cc..000000000 --- a/src/libnr/nr-translate-rotate-ops.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef SEEN_LIBNR_NR_TRANSLATE_ROTATE_OPS_H -#define SEEN_LIBNR_NR_TRANSLATE_ROTATE_OPS_H - -#include <libnr/nr-forward.h> - - -NR::Matrix operator*(NR::translate const &a, NR::rotate const &b); - - -#endif /* !SEEN_LIBNR_NR_TRANSLATE_ROTATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-scale-ops.cpp b/src/libnr/nr-translate-scale-ops.cpp deleted file mode 100644 index 83e5e8e65..000000000 --- a/src/libnr/nr-translate-scale-ops.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "libnr/nr-matrix-ops.h" - -NR::Matrix -operator*(NR::translate const &t, NR::scale const &s) -{ - using NR::X; using NR::Y; - - NR::Matrix ret(s); - ret[4] = t[X] * s[X]; - ret[5] = t[Y] * s[Y]; - return ret; -} - - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-scale-ops.h b/src/libnr/nr-translate-scale-ops.h deleted file mode 100644 index c72665857..000000000 --- a/src/libnr/nr-translate-scale-ops.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SEEN_LIBNR_NR_TRANSLATE_SCALE_OPS_H -#define SEEN_LIBNR_NR_TRANSLATE_SCALE_OPS_H - -#include "libnr/nr-forward.h" - -NR::Matrix operator*(NR::translate const &t, NR::scale const &s); - - -#endif /* !SEEN_LIBNR_NR_TRANSLATE_SCALE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate-test.h b/src/libnr/nr-translate-test.h deleted file mode 100644 index 630f43523..000000000 --- a/src/libnr/nr-translate-test.h +++ /dev/null @@ -1,85 +0,0 @@ -#include <cxxtest/TestSuite.h> - -#include <libnr/nr-point-ops.h> -#include <libnr/nr-matrix.h> -#include <libnr/nr-matrix-fns.h> -#include <libnr/nr-matrix-ops.h> -#include <libnr/nr-point-matrix-ops.h> -#include <libnr/nr-translate.h> -#include <libnr/nr-translate-ops.h> - -class NrTranslateTest : public CxxTest::TestSuite -{ -public: - - NrTranslateTest() : - b( -2.0, 3.0 ), - tb( b ), - tc( -3.0, -2.0 ), - tbc( tb * tc ), - t_id( 0.0, 0.0 ), - m_id( NR::identity() ) - { - } - virtual ~NrTranslateTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static NrTranslateTest *createSuite() { return new NrTranslateTest(); } - static void destroySuite( NrTranslateTest *suite ) { delete suite; } - - NR::Point const b; - NR::translate const tb; - NR::translate const tc; - NR::translate const tbc; - NR::translate const t_id; - NR::Matrix const m_id; - - - void testCtorsArrayOperator(void) - { - TS_ASSERT_EQUALS( tc[NR::X], -3.0 ); - TS_ASSERT_EQUALS( tc[NR::Y], -2.0 ); - - TS_ASSERT_EQUALS( tb[0], b[NR::X] ); - TS_ASSERT_EQUALS( tb[1], b[NR::Y] ); - } - - void testAssignmentOperator(void) - { - NR::translate tb_eq(tc); - tb_eq = tb; - TS_ASSERT_EQUALS( tb, tb_eq ); - TS_ASSERT_DIFFERS( tb_eq, tc ); - } - - void testOpStarTranslateTranslate(void) - { - TS_ASSERT_EQUALS( tbc.offset, NR::Point(-5.0, 1.0) ); - TS_ASSERT_EQUALS( tbc.offset, ( tc * tb ).offset ); - TS_ASSERT_EQUALS( NR::Matrix(tbc), NR::Matrix(tb) * NR::Matrix(tc) ); - } - - void testOpStarPointTranslate(void) - { - TS_ASSERT_EQUALS( tbc.offset, b * tc ); - TS_ASSERT_EQUALS( b * tc, b * NR::Matrix(tc) ); - } - - void testIdentity(void) - { - TS_ASSERT_EQUALS( b * t_id, b ); - TS_ASSERT_EQUALS( NR::Matrix(t_id), m_id ); - } -}; - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-translate.h b/src/libnr/nr-translate.h deleted file mode 100644 index c1ea927e0..000000000 --- a/src/libnr/nr-translate.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef SEEN_NR_TRANSLATE_H -#define SEEN_NR_TRANSLATE_H - -#include <libnr/nr-point.h> - -namespace NR { - -class translate { -public: - Point offset; -private: - translate(); -public: - explicit translate(Point const &p) : offset(p) {} - explicit translate(Coord const x, Coord const y) : offset(x, y) {} - Coord operator[](Dim2 const dim) const { return offset[dim]; } - Coord operator[](unsigned const dim) const { return offset[dim]; } -}; - -} /* namespace NR */ - - -#endif /* !SEEN_NR_TRANSLATE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-types.h b/src/libnr/nr-types.h index bf499e7ff..3aff62d4a 100644 --- a/src/libnr/nr-types.h +++ b/src/libnr/nr-types.h @@ -18,7 +18,6 @@ #include <libnr/nr-coord.h> #include <libnr/nr-dim2.h> #include <libnr/nr-i-coord.h> -#include <libnr/nr-matrix.h> #include <libnr/nr-point.h> #include <libnr/nr-point-l.h> #include <libnr/nr-point-ops.h> diff --git a/src/libnr/nr-values.cpp b/src/libnr/nr-values.cpp index f828c1396..9193eff3b 100644 --- a/src/libnr/nr-values.cpp +++ b/src/libnr/nr-values.cpp @@ -1,14 +1,12 @@ #define __NR_VALUES_C__ #include <libnr/nr-rect-l.h> -#include <libnr/nr-matrix-fns.h> - +#include "libnr/nr-rect.h" /* The following predefined objects are for reference and comparison. */ -NR::Matrix NR_MATRIX_IDENTITY = NR::identity(); 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}; diff --git a/src/libnr/nr-values.h b/src/libnr/nr-values.h index fb3c574a6..93b66b3a7 100644 --- a/src/libnr/nr-values.h +++ b/src/libnr/nr-values.h @@ -22,7 +22,6 @@ The following predefined objects are for reference and comparison. They are defined in nr-values.cpp */ -extern NR::Matrix NR_MATRIX_IDENTITY; extern NRRect NR_RECT_EMPTY; extern NRRectL NR_RECT_L_EMPTY; extern NRRectL NR_RECT_S_EMPTY; |
