summaryrefslogtreecommitdiffstats
path: root/src/libnr
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnr')
-rw-r--r--src/libnr/nr-forward.h2
-rw-r--r--src/libnr/nr-gradient.cpp87
-rw-r--r--src/libnr/nr-gradient.h6
-rw-r--r--src/libnr/nr-macros.h12
-rw-r--r--src/libnr/nr-matrix-fns.h3
-rw-r--r--src/libnr/nr-matrix-ops.h6
-rw-r--r--src/libnr/nr-matrix-scale-ops.cpp35
-rw-r--r--src/libnr/nr-matrix-scale-ops.h21
-rw-r--r--src/libnr/nr-matrix-test.cpp10
-rw-r--r--src/libnr/nr-matrix-test.h10
-rw-r--r--src/libnr/nr-matrix-translate-ops.cpp25
-rw-r--r--src/libnr/nr-matrix-translate-ops.h17
-rw-r--r--src/libnr/nr-matrix.cpp357
-rw-r--r--src/libnr/nr-matrix.h165
-rw-r--r--src/libnr/nr-path.cpp13
-rw-r--r--src/libnr/nr-path.h2
-rw-r--r--src/libnr/nr-point.h12
-rw-r--r--src/libnr/nr-rect.cpp2
-rw-r--r--src/libnr/nr-rect.h6
-rw-r--r--src/libnr/nr-svp-render.cpp58
-rw-r--r--src/libnr/nr-svp.cpp4
-rw-r--r--src/libnr/nr-svp.h5
-rw-r--r--src/libnr/nr-values.cpp4
-rw-r--r--src/libnr/nr-values.h2
24 files changed, 157 insertions, 707 deletions
diff --git a/src/libnr/nr-forward.h b/src/libnr/nr-forward.h
index cbc4d8eec..b12d141df 100644
--- a/src/libnr/nr-forward.h
+++ b/src/libnr/nr-forward.h
@@ -22,8 +22,6 @@ class translate;
class NArtBpath;
struct NRBPath;
struct NRPixBlock;
-struct NRMatrix;
-struct NRPoint;
struct NRRect;
struct NRRectL;
diff --git a/src/libnr/nr-gradient.cpp b/src/libnr/nr-gradient.cpp
index 2d52767bf..57ba651f4 100644
--- a/src/libnr/nr-gradient.cpp
+++ b/src/libnr/nr-gradient.cpp
@@ -23,6 +23,7 @@
#include <libnr/nr-pixblock-pixel.h>
#include <libnr/nr-blit.h>
#include <libnr/nr-gradient.h>
+#include <libnr/nr-matrix-ops.h>
#include <glib/gtypes.h>
#include <stdio.h>
@@ -299,31 +300,31 @@ NRRenderer *
nr_lgradient_renderer_setup (NRLGradientRenderer *lgr,
const unsigned char *cv,
unsigned int spread,
- const NRMatrix *gs2px,
+ const NR::Matrix *gs2px,
float x0, float y0,
float x1, float y1)
{
- NRMatrix n2gs, n2px, px2n;
+ NR::Matrix n2gs, n2px, px2n;
lgr->render = &render<Linear>;
lgr->vector = cv;
lgr->spread = spread;
- n2gs.c[0] = x1 - x0;
- n2gs.c[1] = y1 - y0;
- n2gs.c[2] = y1 - y0;
- n2gs.c[3] = x0 - x1;
- n2gs.c[4] = x0;
- n2gs.c[5] = y0;
+ n2gs[0] = x1 - x0;
+ n2gs[1] = y1 - y0;
+ n2gs[2] = y1 - y0;
+ n2gs[3] = x0 - x1;
+ n2gs[4] = x0;
+ n2gs[5] = y0;
- nr_matrix_multiply (&n2px, &n2gs, gs2px);
- nr_matrix_invert (&px2n, &n2px);
+ n2px = n2gs * (*gs2px);
+ px2n = n2px.inverse();
- lgr->x0 = n2px.c[4] - 0.5;
- lgr->y0 = n2px.c[5] - 0.5;
- lgr->dx = px2n.c[0] * NR_GRADIENT_VECTOR_LENGTH;
- lgr->dy = px2n.c[2] * NR_GRADIENT_VECTOR_LENGTH;
+ lgr->x0 = n2px[4] - 0.5;
+ lgr->y0 = n2px[5] - 0.5;
+ lgr->dx = px2n[0] * NR_GRADIENT_VECTOR_LENGTH;
+ lgr->dy = px2n[2] * NR_GRADIENT_VECTOR_LENGTH;
return (NRRenderer *) lgr;
}
@@ -362,8 +363,8 @@ static void render(NRGradientRenderer *gr, NRPixBlock *pb)
{
NRRGradientRenderer *rgr = static_cast<NRRGradientRenderer *>(gr);
- NR::Coord const dx = rgr->px2gs.c[0];
- NR::Coord const dy = rgr->px2gs.c[1];
+ NR::Coord const dx = rgr->px2gs[0];
+ NR::Coord const dy = rgr->px2gs[1];
NRPixBlock spb;
nr_pixblock_setup_extern(&spb, NR_PIXBLOCK_MODE_R8G8B8A8N,
@@ -374,8 +375,8 @@ static void render(NRGradientRenderer *gr, NRPixBlock *pb)
for (int y = pb->area.y0; y < pb->area.y1; y++) {
unsigned char *d = NR_PIXBLOCK_PX(pb) + (y - pb->area.y0) * pb->rs;
- NR::Coord gx = rgr->px2gs.c[0] * pb->area.x0 + rgr->px2gs.c[2] * y + rgr->px2gs.c[4];
- NR::Coord gy = rgr->px2gs.c[1] * pb->area.x0 + rgr->px2gs.c[3] * y + rgr->px2gs.c[5];
+ NR::Coord gx = rgr->px2gs[0] * pb->area.x0 + rgr->px2gs[2] * y + rgr->px2gs[4];
+ NR::Coord gy = rgr->px2gs[1] * pb->area.x0 + rgr->px2gs[3] * y + rgr->px2gs[5];
for (int x = pb->area.x0; x < pb->area.x1; x++) {
NR::Coord const pos = sqrt(((gx*gx) + (gy*gy)));
unsigned char const *s=spread::color_at(pos, rgr->vector);
@@ -410,10 +411,10 @@ static void render(NRGradientRenderer *gr, NRPixBlock *pb)
for (int y = y0; y < y1; y++) {
unsigned char *d = NR_PIXBLOCK_PX(pb) + (y - y0) * rs;
- NR::Coord gx = rgr->px2gs.c[0] * x0 + rgr->px2gs.c[2] * y + rgr->px2gs.c[4];
- NR::Coord gy = rgr->px2gs.c[1] * x0 + rgr->px2gs.c[3] * y + rgr->px2gs.c[5];
- NR::Coord const dx = rgr->px2gs.c[0];
- NR::Coord const dy = rgr->px2gs.c[1];
+ NR::Coord gx = rgr->px2gs[0] * x0 + rgr->px2gs[2] * y + rgr->px2gs[4];
+ NR::Coord gy = rgr->px2gs[1] * x0 + rgr->px2gs[3] * y + rgr->px2gs[5];
+ NR::Coord const dx = rgr->px2gs[0];
+ NR::Coord const dy = rgr->px2gs[1];
for (int x = x0; x < x1; x++) {
NR::Coord const gx2 = gx * gx;
NR::Coord const gxy2 = gx2 + gy * gy;
@@ -452,7 +453,7 @@ NRRenderer *
nr_rgradient_renderer_setup(NRRGradientRenderer *rgr,
unsigned char const *cv,
unsigned spread,
- NRMatrix const *gs2px,
+ NR::Matrix const *gs2px,
float cx, float cy,
float fx, float fy,
float r)
@@ -466,15 +467,15 @@ nr_rgradient_renderer_setup(NRRGradientRenderer *rgr,
NR_DF_TEST_CLOSE(cy, fy, NR_EPSILON)) {
rgr->render = render<SymmetricRadial>;
- nr_matrix_invert(&rgr->px2gs, gs2px);
- rgr->px2gs.c[0] *= (NR_GRADIENT_VECTOR_LENGTH / r);
- rgr->px2gs.c[1] *= (NR_GRADIENT_VECTOR_LENGTH / r);
- rgr->px2gs.c[2] *= (NR_GRADIENT_VECTOR_LENGTH / r);
- rgr->px2gs.c[3] *= (NR_GRADIENT_VECTOR_LENGTH / r);
- rgr->px2gs.c[4] -= cx;
- rgr->px2gs.c[5] -= cy;
- rgr->px2gs.c[4] *= (NR_GRADIENT_VECTOR_LENGTH / r);
- rgr->px2gs.c[5] *= (NR_GRADIENT_VECTOR_LENGTH / r);
+ rgr->px2gs = gs2px->inverse();
+ rgr->px2gs[0] *= (NR_GRADIENT_VECTOR_LENGTH / r);
+ rgr->px2gs[1] *= (NR_GRADIENT_VECTOR_LENGTH / r);
+ rgr->px2gs[2] *= (NR_GRADIENT_VECTOR_LENGTH / r);
+ rgr->px2gs[3] *= (NR_GRADIENT_VECTOR_LENGTH / r);
+ rgr->px2gs[4] -= cx;
+ rgr->px2gs[5] -= cy;
+ rgr->px2gs[4] *= (NR_GRADIENT_VECTOR_LENGTH / r);
+ rgr->px2gs[5] *= (NR_GRADIENT_VECTOR_LENGTH / r);
rgr->cx = 0.0;
rgr->cy = 0.0;
@@ -490,17 +491,17 @@ nr_rgradient_renderer_setup(NRRGradientRenderer *rgr,
fy = cy + (fy - cy ) * r / (float) df;
}
- NRMatrix n2gs;
- n2gs.c[0] = cx - fx;
- n2gs.c[1] = cy - fy;
- n2gs.c[2] = cy - fy;
- n2gs.c[3] = fx - cx;
- n2gs.c[4] = fx;
- n2gs.c[5] = fy;
-
- NRMatrix n2px;
- nr_matrix_multiply(&n2px, &n2gs, gs2px);
- nr_matrix_invert(&rgr->px2gs, &n2px);
+ NR::Matrix n2gs;
+ n2gs[0] = cx - fx;
+ n2gs[1] = cy - fy;
+ n2gs[2] = cy - fy;
+ n2gs[3] = fx - cx;
+ n2gs[4] = fx;
+ n2gs[5] = fy;
+
+ NR::Matrix n2px;
+ n2px = n2gs * (*gs2px);
+ rgr->px2gs = n2px.inverse();
rgr->cx = 1.0;
rgr->cy = 0.0;
diff --git a/src/libnr/nr-gradient.h b/src/libnr/nr-gradient.h
index 092ed1e22..1073f36ae 100644
--- a/src/libnr/nr-gradient.h
+++ b/src/libnr/nr-gradient.h
@@ -44,14 +44,14 @@ struct NRLGradientRenderer : public NRGradientRenderer {
NRRenderer *nr_lgradient_renderer_setup (NRLGradientRenderer *lgr,
const unsigned char *cv,
unsigned int spread,
- const NRMatrix *gs2px,
+ const NR::Matrix *gs2px,
float x0, float y0,
float x1, float y1);
/* Radial */
struct NRRGradientRenderer : public NRGradientRenderer {
- NRMatrix px2gs;
+ NR::Matrix px2gs;
float cx, cy;
float fx, fy;
float r;
@@ -61,7 +61,7 @@ struct NRRGradientRenderer : public NRGradientRenderer {
NRRenderer *nr_rgradient_renderer_setup (NRRGradientRenderer *rgr,
const unsigned char *cv,
unsigned int spread,
- const NRMatrix *gs2px,
+ const NR::Matrix *gs2px,
float cx, float cy,
float fx, float fy,
float r);
diff --git a/src/libnr/nr-macros.h b/src/libnr/nr-macros.h
index 0ccad30c4..e0d3dabfb 100644
--- a/src/libnr/nr-macros.h
+++ b/src/libnr/nr-macros.h
@@ -47,22 +47,12 @@
#define NR_DF_TEST_CLOSE(a,b,e) (fabs ((a) - (b)) <= (e))
// Todo: move these into nr-matrix.h
-#define NR_MATRIX_DF_TEST_TRANSFORM_CLOSE(a,b,e) (NR_DF_TEST_CLOSE ((*(a))[0], (*(b))[0], e) && \
- NR_DF_TEST_CLOSE ((*(a))[1], (*(b))[1], e) && \
- NR_DF_TEST_CLOSE ((*(a))[2], (*(b))[2], e) && \
- NR_DF_TEST_CLOSE ((*(a))[3], (*(b))[3], e))
-#define NR_MATRIX_DF_TEST_TRANSLATE_CLOSE(a,b,e) (NR_DF_TEST_CLOSE ((*(a))[4], (*(b))[4], e) && \
- NR_DF_TEST_CLOSE ((*(a))[5], (*(b))[5], e))
-#define NR_MATRIX_DF_TEST_CLOSE(a,b,e) (NR_MATRIX_DF_TEST_TRANSLATE_CLOSE (a, b, e) && \
- NR_MATRIX_DF_TEST_TRANSFORM_CLOSE (a, b, e))
-
#define NR_RECT_DFLS_TEST_EMPTY(a) (((a)->x0 >= (a)->x1) || ((a)->y0 >= (a)->y1))
#define NR_RECT_DFLS_TEST_INTERSECT(a,b) (((a)->x0 < (b)->x1) && ((a)->x1 > (b)->x0) && ((a)->y0 < (b)->y1) && ((a)->y1 > (b)->y0))
#define NR_RECT_DF_POINT_DF_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1))
#define NR_RECT_LS_POINT_LS_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1))
#define NR_RECT_LS_TEST_INSIDE(r,x,y) ((x >= (r)->x0) && (x < (r)->x1) && (y >= (r)->y0) && (y < (r)->y1))
-#define NR_MATRIX_D_TO_DOUBLE(m) ((m)->c)
-#define NR_MATRIX_D_FROM_DOUBLE(d) ((NRMatrix *) &(d)[0])
+#define NR_MATRIX_D_FROM_DOUBLE(d) ((NR::Matrix *) &(d)[0])
#endif
diff --git a/src/libnr/nr-matrix-fns.h b/src/libnr/nr-matrix-fns.h
index 208366746..a46aca909 100644
--- a/src/libnr/nr-matrix-fns.h
+++ b/src/libnr/nr-matrix-fns.h
@@ -2,6 +2,7 @@
#define SEEN_NR_MATRIX_FNS_H
#include "nr-matrix.h"
+#include <math.h>
namespace NR {
@@ -24,6 +25,8 @@ Matrix from_basis(const Point x_basis, const Point y_basis, const Point offset=P
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);
diff --git a/src/libnr/nr-matrix-ops.h b/src/libnr/nr-matrix-ops.h
index 02fb28d0c..e534f9cf6 100644
--- a/src/libnr/nr-matrix-ops.h
+++ b/src/libnr/nr-matrix-ops.h
@@ -23,14 +23,10 @@ inline bool operator!=(Matrix const &a, Matrix const &b)
Matrix operator*(Matrix const &a, Matrix const &b);
-inline Matrix operator*(Matrix const &a, NRMatrix const &b)
-{
- return a * NR::Matrix(b);
-}
+inline Matrix &operator*=(Matrix &a, Matrix const &b) { a = a * b; return a; }
} /* namespace NR */
-
#endif /* !SEEN_NR_MATRIX_OPS_H */
/*
diff --git a/src/libnr/nr-matrix-scale-ops.cpp b/src/libnr/nr-matrix-scale-ops.cpp
deleted file mode 100644
index 0079d3f76..000000000
--- a/src/libnr/nr-matrix-scale-ops.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "libnr/nr-matrix-ops.h"
-
-NR::Matrix
-operator/(NR::Matrix const &m, NR::scale const &s)
-{
- using NR::X; using NR::Y;
- NR::Matrix ret(m);
- ret[0] /= s[X]; ret[1] /= s[Y];
- ret[2] /= s[X]; ret[3] /= s[Y];
- ret[4] /= s[X]; ret[5] /= s[Y];
- return ret;
-}
-
-NR::Matrix
-operator*(NR::Matrix const &m, NR::scale const &s)
-{
- using NR::X; using NR::Y;
- NR::Matrix ret(m);
- ret[0] *= s[X]; ret[1] *= s[Y];
- ret[2] *= s[X]; ret[3] *= s[Y];
- ret[4] *= s[X]; ret[5] *= 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-matrix-scale-ops.h b/src/libnr/nr-matrix-scale-ops.h
index dee275182..d030bb66c 100644
--- a/src/libnr/nr-matrix-scale-ops.h
+++ b/src/libnr/nr-matrix-scale-ops.h
@@ -6,9 +6,26 @@
#include "libnr/nr-forward.h"
-NR::Matrix operator/(NR::Matrix const &m, NR::scale const &s);
+namespace NR {
-NR::Matrix operator*(NR::Matrix const &m, NR::scale const &s);
+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.cpp b/src/libnr/nr-matrix-test.cpp
index b7f064e48..d0bf25310 100644
--- a/src/libnr/nr-matrix-test.cpp
+++ b/src/libnr/nr-matrix-test.cpp
@@ -100,14 +100,14 @@ int main(int argc, char *argv[])
}
UTEST_TEST("nr_matrix_invert") {
- NRMatrix const nr_m_id(m_id);
+ NR::Matrix const nr_m_id(m_id);
Matrix const m_s2(NR::scale(-4.0, 2.0));
- NRMatrix const nr_s2(m_s2);
+ NR::Matrix const nr_s2(m_s2);
Matrix const m_sp5(NR::scale(-.25, .5));
- NRMatrix const nr_sp5(m_sp5);
+ NR::Matrix const nr_sp5(m_sp5);
Matrix const m_t23(t23);
- NRMatrix const nr_t23(m_t23);
- NRMatrix inv;
+ NR::Matrix const nr_t23(m_t23);
+ NR::Matrix inv;
nr_matrix_invert(&inv, &nr_m_id);
UTEST_ASSERT( Matrix(inv) == m_id );
nr_matrix_invert(&inv, &nr_t23);
diff --git a/src/libnr/nr-matrix-test.h b/src/libnr/nr-matrix-test.h
index 476852890..ee60d8f9b 100644
--- a/src/libnr/nr-matrix-test.h
+++ b/src/libnr/nr-matrix-test.h
@@ -127,14 +127,14 @@ public:
void testNrMatrixInvert(void)
{
- NRMatrix const nr_m_id(m_id);
+ NR::Matrix const nr_m_id(m_id);
Matrix const m_s2(NR::scale(-4.0, 2.0));
- NRMatrix const nr_s2(m_s2);
+ NR::Matrix const nr_s2(m_s2);
Matrix const m_sp5(NR::scale(-.25, .5));
- NRMatrix const nr_sp5(m_sp5);
+ NR::Matrix const nr_sp5(m_sp5);
Matrix const m_t23(t23);
- NRMatrix const nr_t23(m_t23);
- NRMatrix inv;
+ NR::Matrix const nr_t23(m_t23);
+ NR::Matrix inv;
nr_matrix_invert(&inv, &nr_m_id);
TS_ASSERT_EQUALS( Matrix(inv), m_id );
nr_matrix_invert(&inv, &nr_t23);
diff --git a/src/libnr/nr-matrix-translate-ops.cpp b/src/libnr/nr-matrix-translate-ops.cpp
deleted file mode 100644
index 554b5790a..000000000
--- a/src/libnr/nr-matrix-translate-ops.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "libnr/nr-matrix-ops.h"
-
-namespace NR {
-
-Matrix
-operator*(Matrix const &m, translate const &t)
-{
- Matrix ret(m);
- ret[4] += t[X];
- ret[5] += 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-matrix-translate-ops.h b/src/libnr/nr-matrix-translate-ops.h
index f51bccaa1..6e5607759 100644
--- a/src/libnr/nr-matrix-translate-ops.h
+++ b/src/libnr/nr-matrix-translate-ops.h
@@ -9,18 +9,19 @@
#include "libnr/nr-matrix.h"
#include "libnr/nr-translate.h"
-//NR::Matrix operator*(NR::Matrix const &m, NR::translate const &t);
-
namespace NR {
-Matrix operator*(Matrix const &m, translate const &t);
-}
-inline NR::Matrix
-operator/(NR::Matrix const &numer, NR::translate const &denom)
-{
- return numer * NR::translate(-denom.offset);
+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 */
diff --git a/src/libnr/nr-matrix.cpp b/src/libnr/nr-matrix.cpp
index ed482f46f..eb1f21d47 100644
--- a/src/libnr/nr-matrix.cpp
+++ b/src/libnr/nr-matrix.cpp
@@ -13,156 +13,7 @@
#include <cstdlib>
#include "nr-matrix.h"
-
-
-
-/**
- * Multiply two NRMatrices together, storing the result in d.
- */
-NRMatrix *
-nr_matrix_multiply(NRMatrix *d, NRMatrix const *m0, NRMatrix const *m1)
-{
- if (m0) {
- if (m1) {
- NR::Coord d0 = m0->c[0] * m1->c[0] + m0->c[1] * m1->c[2];
- NR::Coord d1 = m0->c[0] * m1->c[1] + m0->c[1] * m1->c[3];
- NR::Coord d2 = m0->c[2] * m1->c[0] + m0->c[3] * m1->c[2];
- NR::Coord d3 = m0->c[2] * m1->c[1] + m0->c[3] * m1->c[3];
- NR::Coord d4 = m0->c[4] * m1->c[0] + m0->c[5] * m1->c[2] + m1->c[4];
- NR::Coord d5 = m0->c[4] * m1->c[1] + m0->c[5] * m1->c[3] + m1->c[5];
-
- NR::Coord *dest = d->c;
- *dest++ = d0;
- *dest++ = d1;
- *dest++ = d2;
- *dest++ = d3;
- *dest++ = d4;
- *dest = d5;
- } else {
- *d = *m0;
- }
- } else {
- if (m1) {
- *d = *m1;
- } else {
- nr_matrix_set_identity(d);
- }
- }
-
- return d;
-}
-
-
-
-
-/**
- * Store the inverted value of Matrix m in d
- */
-NRMatrix *
-nr_matrix_invert(NRMatrix *d, NRMatrix const *m)
-{
- if (m) {
- NR::Coord const det = m->c[0] * m->c[3] - m->c[1] * m->c[2];
- if (!NR_DF_TEST_CLOSE(det, 0.0, NR_EPSILON)) {
-
- NR::Coord const idet = 1.0 / det;
- NR::Coord *dest = d->c;
-
- /* Cache m->c[0] and m->c[4] in case d == m. */
- NR::Coord const m_c0(m->c[0]);
- NR::Coord const m_c4(m->c[4]);
-
- /*0*/ *dest++ = m->c[3] * idet;
- /*1*/ *dest++ = -m->c[1] * idet;
- /*2*/ *dest++ = -m->c[2] * idet;
- /*3*/ *dest++ = m_c0 * idet;
- /*4*/ *dest++ = -m_c4 * d->c[0] - m->c[5] * d->c[2];
- /*5*/ *dest = -m_c4 * d->c[1] - m->c[5] * d->c[3];
-
- } else {
- nr_matrix_set_identity(d);
- }
- } else {
- nr_matrix_set_identity(d);
- }
-
- return d;
-}
-
-
-
-
-
-/**
- * Set this matrix to a translation of x and y
- */
-NRMatrix *
-nr_matrix_set_translate(NRMatrix *m, NR::Coord const x, NR::Coord const y)
-{
- NR::Coord *dest = m->c;
-
- *dest++ = 1.0; //0
- *dest++ = 0.0; //1
- *dest++ = 0.0; //2
- *dest++ = 1.0; //3
- *dest++ = x; //4
- *dest = y; //5
-
- return m;
-}
-
-
-
-
-
-/**
- * Set this matrix to a scaling transform in sx and sy
- */
-NRMatrix *
-nr_matrix_set_scale(NRMatrix *m, NR::Coord const sx, NR::Coord const sy)
-{
- NR::Coord *dest = m->c;
-
- *dest++ = sx; //0
- *dest++ = 0.0; //1
- *dest++ = 0.0; //2
- *dest++ = sy; //3
- *dest++ = 0.0; //4
- *dest = 0.0; //5
-
- return m;
-}
-
-
-
-
-
-/**
- * Set this matrix to a rotating transform of angle 'theta' radians
- */
-NRMatrix *
-nr_matrix_set_rotate(NRMatrix *m, NR::Coord const theta)
-{
- NR::Coord const s = sin(theta);
- NR::Coord const c = cos(theta);
-
- NR::Coord *dest = m->c;
-
- *dest++ = c; //0
- *dest++ = s; //1
- *dest++ = -s; //2
- *dest++ = c; //3
- *dest++ = 0.0; //4
- *dest = 0.0; //5
-
- return m;
-}
-
-
-
-
-
-
+#include "nr-matrix-fns.h"
@@ -176,22 +27,6 @@ namespace NR {
/**
- * Constructor. Assign to nr if not null, else identity
- */
-Matrix::Matrix(NRMatrix const *nr)
-{
- if (nr) {
- assign(nr->c);
- } else {
- set_identity();
- }
-}
-
-
-
-
-
-/**
* Multiply two matrices together
*/
Matrix operator*(Matrix const &m0, Matrix const &m1)
@@ -213,54 +48,6 @@ Matrix operator*(Matrix const &m0, Matrix const &m1)
/**
- * Multiply a matrix by another
- */
-Matrix &Matrix::operator*=(Matrix const &o)
-{
- *this = *this * o;
- return *this;
-}
-
-
-
-
-
-/**
- * Multiply by a scaling matrix
- */
-Matrix &Matrix::operator*=(scale const &other)
-{
- /* This loop is massive overkill. Let's unroll.
- * o _c[] goes from 0..5
- * o other[] alternates between 0 and 1
- */
- /*
- * for (unsigned i = 0; i < 3; ++i) {
- * for (unsigned j = 0; j < 2; ++j) {
- * this->_c[i * 2 + j] *= other[j];
- * }
- * }
- */
-
- NR::Coord const xscale = other[0];
- NR::Coord const yscale = other[1];
- NR::Coord *dest = _c;
-
- /*i=0 j=0*/ *dest++ *= xscale;
- /*i=0 j=1*/ *dest++ *= yscale;
- /*i=1 j=0*/ *dest++ *= xscale;
- /*i=1 j=1*/ *dest++ *= yscale;
- /*i=2 j=0*/ *dest++ *= xscale;
- /*i=2 j=1*/ *dest *= yscale;
-
- return *this;
-}
-
-
-
-
-
-/**
* Return the inverse of this matrix. If an inverse is not defined,
* then return the identity matrix.
*/
@@ -398,121 +185,6 @@ NR::Coord Matrix::descrim() const
/**
- * Assign a matrix to a given coordinate array
- */
-Matrix &Matrix::assign(Coord const *array)
-{
- assert(array != NULL);
-
- Coord const *src = array;
- Coord *dest = _c;
-
- *dest++ = *src++; //0
- *dest++ = *src++; //1
- *dest++ = *src++; //2
- *dest++ = *src++; //3
- *dest++ = *src++; //4
- *dest = *src ; //5
-
- return *this;
-}
-
-
-
-
-
-/**
- * Copy this matrix's value to a NRMatrix
- */
-NRMatrix *Matrix::copyto(NRMatrix *nrm) const {
-
- assert(nrm != NULL);
-
- Coord const *src = _c;
- Coord *dest = nrm->c;
-
- *dest++ = *src++; //0
- *dest++ = *src++; //1
- *dest++ = *src++; //2
- *dest++ = *src++; //3
- *dest++ = *src++; //4
- *dest = *src ; //5
-
- return nrm;
-}
-
-
-
-
-/**
- * Copy this matrix's values to an array
- */
-NR::Coord *Matrix::copyto(NR::Coord *array) const {
-
- assert(array != NULL);
-
- Coord const *src = _c;
- Coord *dest = array;
-
- *dest++ = *src++; //0
- *dest++ = *src++; //1
- *dest++ = *src++; //2
- *dest++ = *src++; //3
- *dest++ = *src++; //4
- *dest = *src ; //5
-
- return array;
-}
-
-
-
-
-
-/**
- *
- */
-double expansion(Matrix const &m) {
- return sqrt(fabs(m.det()));
-}
-
-
-
-
-
-/**
- *
- */
-double Matrix::expansion() const {
- return sqrt(fabs(det()));
-}
-
-
-
-
-
-/**
- *
- */
-double Matrix::expansionX() const {
- return sqrt(_c[0] * _c[0] + _c[1] * _c[1]);
-}
-
-
-
-
-
-/**
- *
- */
-double Matrix::expansionY() const {
- return sqrt(_c[2] * _c[2] + _c[3] * _c[3]);
-}
-
-
-
-
-
-/**
*
*/
bool Matrix::is_translation(Coord const eps) const {
@@ -550,7 +222,18 @@ bool Matrix::is_rotation(Coord const eps) const {
*
*/
bool Matrix::test_identity() const {
- return NR_MATRIX_DF_TEST_CLOSE(this, &NR_MATRIX_IDENTITY, NR_EPSILON);
+ return matrix_equalp(*this, NR_MATRIX_IDENTITY, NR_EPSILON);
+}
+
+
+
+
+
+/**
+ *
+ */
+double expansion(Matrix const &m) {
+ return sqrt(fabs(m.det()));
}
@@ -561,7 +244,11 @@ bool Matrix::test_identity() const {
*
*/
bool transform_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon) {
- return NR_MATRIX_DF_TEST_TRANSFORM_CLOSE(&m0, &m1, 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);
}
@@ -572,7 +259,7 @@ bool transform_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilo
*
*/
bool translate_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon) {
- return NR_MATRIX_DF_TEST_TRANSLATE_CLOSE(&m0, &m1, epsilon);
+ return NR_DF_TEST_CLOSE(m0[4], m1[4], epsilon) && NR_DF_TEST_CLOSE(m0[5], m1[5], epsilon);
}
@@ -582,10 +269,8 @@ bool translate_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilo
/**
*
*/
-bool matrix_equalp(Matrix const &m0, Matrix const &m1, NR::Coord const epsilon)
-{
- return ( NR_MATRIX_DF_TEST_TRANSFORM_CLOSE(&m0, &m1, epsilon) &&
- NR_MATRIX_DF_TEST_TRANSLATE_CLOSE(&m0, &m1, 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);
}
diff --git a/src/libnr/nr-matrix.h b/src/libnr/nr-matrix.h
index a8af553b6..f626377e5 100644
--- a/src/libnr/nr-matrix.h
+++ b/src/libnr/nr-matrix.h
@@ -2,7 +2,7 @@
#define __NR_MATRIX_H__
/** \file
- * Definition of NRMatrix and NR::Matrix types.
+ * 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.
@@ -26,41 +26,6 @@
#include <libnr/nr-scale.h>
#include <libnr/nr-translate.h>
-/// NRMatrix is the obsolete form of NR::Matrix.
-/// It consists of six NR::Coord values.
-struct NRMatrix {
- NR::Coord c[6];
-
- NR::Coord &operator[](int i) { return c[i]; }
- NR::Coord operator[](int i) const { return c[i]; }
-};
-
-#define nr_matrix_set_identity(m) (*(m) = NR_MATRIX_IDENTITY)
-
-#define nr_matrix_test_identity(m,e) (!(m) || NR_MATRIX_DF_TEST_CLOSE(m, &NR_MATRIX_IDENTITY, e))
-
-#define nr_matrix_test_equal(m0,m1,e) ((!(m0) && !(m1)) || ((m0) && (m1) && NR_MATRIX_DF_TEST_CLOSE(m0, m1, e)))
-#define nr_matrix_test_transform_equal(m0,m1,e) ((!(m0) && !(m1)) || ((m0) && (m1) && NR_MATRIX_DF_TEST_TRANSFORM_CLOSE(m0, m1, e)))
-#define nr_matrix_test_translate_equal(m0,m1,e) ((!(m0) && !(m1)) || ((m0) && (m1) && NR_MATRIX_DF_TEST_TRANSLATE_CLOSE(m0, m1, e)))
-
-NRMatrix *nr_matrix_invert(NRMatrix *d, NRMatrix const *m);
-
-/* d,m0,m1 needn't be distinct in any of these multiply routines. */
-
-NRMatrix *nr_matrix_multiply(NRMatrix *d, NRMatrix const *m0, NRMatrix const *m1);
-
-NRMatrix *nr_matrix_set_translate(NRMatrix *m, NR::Coord const x, NR::Coord const y);
-
-NRMatrix *nr_matrix_set_scale(NRMatrix *m, NR::Coord const sx, NR::Coord const sy);
-
-NRMatrix *nr_matrix_set_rotate(NRMatrix *m, NR::Coord const theta);
-
-#define NR_MATRIX_DF_TRANSFORM_X(m,x,y) ((*(m))[0] * (x) + (*(m))[2] * (y) + (*(m))[4])
-#define NR_MATRIX_DF_TRANSFORM_Y(m,x,y) ((*(m))[1] * (x) + (*(m))[3] * (y) + (*(m))[5])
-
-#define NR_MATRIX_DF_EXPANSION2(m) (fabs((*(m))[0] * (*(m))[3] - (*(m))[1] * (*(m))[2]))
-#define NR_MATRIX_DF_EXPANSION(m) (sqrt(NR_MATRIX_DF_EXPANSION2(m)))
-
namespace NR {
/**
@@ -113,27 +78,6 @@ class Matrix {
-
- /**
- *
- */
- Matrix(NRMatrix 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
-
- }
-
-
-
-
/**
*
*/
@@ -231,13 +175,6 @@ class Matrix {
}
-
- /**
- *
- */
- Matrix(NRMatrix const *nr);
-
-
/**
*
*/
@@ -266,29 +203,6 @@ class Matrix {
Matrix inverse() const;
- /**
- *
- */
- Matrix &operator*=(Matrix const &other);
-
-
- /**
- *
- */
- Matrix &operator*=(scale const &other);
-
-
-
- /**
- *
- */
- Matrix &operator*=(translate const &other) {
- _c[4] += other[X];
- _c[5] += other[Y];
- return *this;
- }
-
-
/**
*
@@ -330,83 +244,6 @@ class Matrix {
Coord descrim() const;
- /**
- *
- */
- double expansion() const;
-
-
- /**
- *
- */
- double expansionX() const;
-
-
- /**
- *
- */
- double expansionY() const;
-
- // legacy
-
-
- /**
- *
- */
- Matrix &assign(Coord const *array);
-
-
- /**
- *
- */
- NRMatrix *copyto(NRMatrix* nrm) const;
-
-
- /**
- *
- */
- Coord *copyto(Coord *array) const;
-
-
-
- /**
- *
- */
- operator NRMatrix&() {
- g_assert(sizeof(_c) == sizeof(NRMatrix));
- return *reinterpret_cast<NRMatrix *>(_c);
- }
-
-
-
- /**
- *
- */
- operator NRMatrix const&() const {
- g_assert(sizeof(_c) == sizeof(NRMatrix));
- return *reinterpret_cast<const NRMatrix *>(_c);
- }
-
-
-
- /**
- *
- */
- operator NRMatrix*() {
- g_assert(sizeof(_c) == sizeof(NRMatrix));
- return reinterpret_cast<NRMatrix *>(_c);
- }
-
-
- /**
- *
- */
- operator NRMatrix const*() const {
- g_assert(sizeof(_c) == sizeof(NRMatrix));
- return reinterpret_cast<NRMatrix const *>(_c);
- }
-
-
private:
diff --git a/src/libnr/nr-path.cpp b/src/libnr/nr-path.cpp
index a0011c9dc..713cfe43d 100644
--- a/src/libnr/nr-path.cpp
+++ b/src/libnr/nr-path.cpp
@@ -20,7 +20,7 @@ static void nr_curve_bbox(NR::Point const p000, NR::Point const p001,
NR::Point const p011, NR::Point const p111,
NRRect *bbox);
-NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NRMatrix const *transform)
+NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NR::Matrix const *transform)
{
int i;
@@ -38,13 +38,10 @@ NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NRMatrix const *tra
while (s->path[i].code != NR_END) {
d->path[i].code = s->path[i].code;
if (s->path[i].code == NR_CURVETO) {
- d->path[i].x1 = NR_MATRIX_DF_TRANSFORM_X (transform, s->path[i].x1, s->path[i].y1);
- d->path[i].y1 = NR_MATRIX_DF_TRANSFORM_Y (transform, s->path[i].x1, s->path[i].y1);
- d->path[i].x2 = NR_MATRIX_DF_TRANSFORM_X (transform, s->path[i].x2, s->path[i].y2);
- d->path[i].y2 = NR_MATRIX_DF_TRANSFORM_Y (transform, s->path[i].x2, s->path[i].y2);
+ d->path[i].setC(1, s->path[i].c(1) * (*transform));
+ d->path[i].setC(2, s->path[i].c(2) * (*transform));
}
- d->path[i].x3 = NR_MATRIX_DF_TRANSFORM_X (transform, s->path[i].x3, s->path[i].y3);
- d->path[i].y3 = NR_MATRIX_DF_TRANSFORM_Y (transform, s->path[i].x3, s->path[i].y3);
+ d->path[i].setC(3, s->path[i].c(3) * (*transform));
i += 1;
}
d->path[i].code = NR_END;
@@ -53,7 +50,7 @@ NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NRMatrix const *tra
}
NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NR::Matrix const transform) {
- NRMatrix tr = transform;
+ NR::Matrix tr = transform;
return nr_path_duplicate_transform(d, s, &tr);
}
diff --git a/src/libnr/nr-path.h b/src/libnr/nr-path.h
index 6fdc85694..bf7369be4 100644
--- a/src/libnr/nr-path.h
+++ b/src/libnr/nr-path.h
@@ -36,7 +36,7 @@ struct NRBPath {
NArtBpath *path;
};
-NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NRMatrix const *transform);
+NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NR::Matrix const *transform);
NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NR::Matrix const transform);
diff --git a/src/libnr/nr-point.h b/src/libnr/nr-point.h
index 60c5586b0..c1ec3adc9 100644
--- a/src/libnr/nr-point.h
+++ b/src/libnr/nr-point.h
@@ -18,13 +18,6 @@
#include <2geom/point.h>
-/// A NRPoint consists of x and y coodinates.
-/// \todo
-/// This class appears to be obsoleted out in favour of NR::Point.
-struct NRPoint {
- NR::Coord x, y;
-};
-
namespace NR {
class Matrix;
@@ -40,11 +33,6 @@ public:
_pt[Y] = y;
}
- inline Point(NRPoint const &p) {
- _pt[X] = p.x;
- _pt[Y] = p.y;
- }
-
inline Point(Point const &p) {
for (unsigned i = 0; i < 2; ++i) {
_pt[i] = p._pt[i];
diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp
index f3036eff1..a1c8c93b2 100644
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
@@ -224,7 +224,7 @@ nr_rect_d_matrix_transform(NRRect *d, NRRect const *const s, NR::Matrix const &m
}
NRRect *
-nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NRMatrix const *m)
+nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NR::Matrix const *m)
{
return nr_rect_d_matrix_transform(d, s, *m);
}
diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index 5d897c695..c61083b4b 100644
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
@@ -24,9 +24,9 @@
#include <libnr/nr-point.h>
#include <libnr/nr-maybe.h>
#include <libnr/nr-point-matrix-ops.h>
+#include <libnr/nr-forward.h>
namespace NR {
- struct Matrix;
/** A rectangle is always aligned to the X and Y axis. This means it
* can be defined using only 4 coordinates, and determining
@@ -247,8 +247,6 @@ inline std::ostream
/* legacy rect stuff */
-struct NRMatrix;
-
/* NULL rect is infinite */
struct NRRect {
@@ -302,7 +300,7 @@ 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, NRMatrix 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);
diff --git a/src/libnr/nr-svp-render.cpp b/src/libnr/nr-svp-render.cpp
index 3ad1c2ca5..4e53cd5de 100644
--- a/src/libnr/nr-svp-render.cpp
+++ b/src/libnr/nr-svp-render.cpp
@@ -9,8 +9,8 @@
* This code is in public domain
*/
-#define NR_SVPSEG_Y0(s,i) ((s)->points[(s)->segments[i].start].y)
-#define NR_SVPSEG_Y1(s,i) ((s)->points[(s)->segments[i].start + (s)->segments[i].length - 1].y)
+#define NR_SVPSEG_Y0(s,i) ((s)->points[(s)->segments[i].start][NR::Y])
+#define NR_SVPSEG_Y1(s,i) ((s)->points[(s)->segments[i].start + (s)->segments[i].length - 1][NR::Y])
#define noNR_VERBOSE
@@ -75,7 +75,7 @@ static NRRun *nr_run_insort (NRRun *start, NRRun *run);
struct NRSlice {
NRSlice *next;
int wind;
- NRPoint *points;
+ NR::Point *points;
unsigned int current;
unsigned int last;
NR::Coord x;
@@ -83,7 +83,7 @@ struct NRSlice {
NR::Coord stepx;
};
-static NRSlice *nr_slice_new (int wind, NRPoint *points, unsigned int length, NR::Coord y);
+static NRSlice *nr_slice_new (int wind, NR::Point *points, unsigned int length, NR::Coord y);
static NRSlice *nr_slice_free_one (NRSlice *s);
static void nr_slice_free_list (NRSlice *s);
static NRSlice *nr_slice_insort (NRSlice *start, NRSlice *slice);
@@ -189,7 +189,7 @@ nr_svp_render (NRSVP *svp, unsigned char *px, unsigned int bpp, unsigned int rs,
NRRun * newrun;
rx0 = cs->x;
ry0 = cs->y;
- if (cs->points[cs->current + 1].y > dy1) {
+ if (cs->points[cs->current + 1][NR::Y] > dy1) {
/* The same slice continues */
rx1 = rx0 + (dy1 - ry0) * cs->stepx;
ry1 = dy1;
@@ -198,12 +198,12 @@ nr_svp_render (NRSVP *svp, unsigned char *px, unsigned int bpp, unsigned int rs,
} else {
/* Subpixel height run */
cs->current += 1;
- rx1 = cs->points[cs->current].x;
- ry1 = cs->points[cs->current].y;
+ rx1 = cs->points[cs->current][NR::X];
+ ry1 = cs->points[cs->current][NR::Y];
cs->x = rx1;
cs->y = ry1;
if (cs->current < cs->last) {
- cs->stepx = (cs->points[cs->current + 1].x - rx1) / (cs->points[cs->current + 1].y - ry1);
+ cs->stepx = (cs->points[cs->current + 1][NR::X] - rx1) / (cs->points[cs->current + 1][NR::Y] - ry1);
}
}
newrun = nr_run_new (rx0, ry0, rx1, ry1, cs->wind);
@@ -355,10 +355,10 @@ nr_svp_render (NRSVP *svp, unsigned char *px, unsigned int bpp, unsigned int rs,
static NRSlice *ffslice = NULL;
static NRSlice *
-nr_slice_new (int wind, NRPoint *points, unsigned int length, NR::Coord y)
+nr_slice_new (int wind, NR::Point *points, unsigned int length, NR::Coord y)
{
NRSlice *s;
- NRPoint *p;
+ NR::Point *p;
/* g_assert (svl); */
/* g_assert (svl->vertex); */
@@ -386,16 +386,16 @@ nr_slice_new (int wind, NRPoint *points, unsigned int length, NR::Coord y)
s->current = 0;
s->last = length - 1;
- while ((s->current < s->last) && (s->points[s->current + 1].y <= y)) s->current += 1;
+ while ((s->current < s->last) && (s->points[s->current + 1][NR::Y] <= y)) s->current += 1;
p = s->points + s->current;
- if (s->points[s->current].y == y) {
- s->x = p[0].x;
+ if (s->points[s->current][NR::Y] == y) {
+ s->x = p[0][NR::X];
} else {
- s->x = p[0].x + (p[1].x - p[0].x) * (y - p[0].y) / (p[1].y - p[0].y);
+ s->x = p[0][NR::X] + (p[1][NR::X] - p[0][NR::X]) * (y - p[0][NR::Y]) / (p[1][NR::Y] - p[0][NR::Y]);
}
s->y = y;
- s->stepx = (p[1].x - p[0].x) / (p[1].y - p[0].y);
+ s->stepx = (p[1][NR::X] - p[0][NR::X]) / (p[1][NR::Y] - p[0][NR::Y]);
return s;
}
@@ -462,44 +462,44 @@ nr_slice_compare (NRSlice *l, NRSlice *r)
if (l->stepx > r->stepx) return 1;
} else if (l->y > r->y) {
unsigned int pidx;
- NRPoint *p;
+ NR::Point *p;
NR::Coord x, ldx, rdx;
/* This is bitch - we have to determine r values at l->y */
pidx = 0;
- while ((pidx < r->last) && (r->points[pidx + 1].y <= l->y)) pidx += 1;
+ while ((pidx < r->last) && (r->points[pidx + 1][NR::Y] <= l->y)) pidx += 1;
/* If v is last vertex, r ends before l starts */
if (pidx >= r->last) return 1;
p = r->points + pidx;
- if (p[0].y == l->y) {
- x = p[0].x;
+ if (p[0][NR::Y] == l->y) {
+ x = p[0][NR::X];
} else {
- x = p[0].x + (p[1].x - p[0].x) * (l->y - p[0].y) / (p[1].y - p[0].y);
+ x = p[0][NR::X] + (p[1][NR::X] - p[0][NR::X]) * (l->y - p[0][NR::Y]) / (p[1][NR::Y] - p[0][NR::Y]);
}
if (l->x < x) return -1;
if (l->x > x) return 1;
- ldx = l->stepx * (p[1].y - p[0].y);
- rdx = p[1].x - p[0].x;
+ ldx = l->stepx * (p[1][NR::Y] - p[0][NR::Y]);
+ rdx = p[1][NR::X] - p[0][NR::X];
if (ldx < rdx) return -1;
if (ldx > rdx) return 1;
} else {
unsigned int pidx;
- NRPoint *p;
+ NR::Point *p;
NR::Coord x, ldx, rdx;
/* This is bitch - we have to determine l value at r->y */
pidx = 0;
- while ((pidx < l->last) && (l->points[pidx + 1].y <= r->y)) pidx += 1;
+ while ((pidx < l->last) && (l->points[pidx + 1][NR::Y] <= r->y)) pidx += 1;
/* If v is last vertex, l ends before r starts */
if (pidx >= l->last) return 1;
p = l->points + pidx;
- if (p[0].y == r->y) {
- x = p[0].x;
+ if (p[0][NR::Y] == r->y) {
+ x = p[0][NR::X];
} else {
- x = p[0].x + (p[1].x - p[0].x) * (r->y - p[0].y) / (p[1].y - p[0].y);
+ x = p[0][NR::X] + (p[1][NR::X] - p[0][NR::X]) * (r->y - p[0][NR::Y]) / (p[1][NR::Y] - p[0][NR::Y]);
}
if (x < r->x) return -1;
if (x > r->x) return 1;
- ldx = l->stepx * (p[1].y - p[0].y);
- rdx = p[1].x - p[0].x;
+ ldx = l->stepx * (p[1][NR::Y] - p[0][NR::Y]);
+ rdx = p[1][NR::X] - p[0][NR::X];
if (ldx < rdx) return -1;
if (ldx > rdx) return 1;
}
diff --git a/src/libnr/nr-svp.cpp b/src/libnr/nr-svp.cpp
index 7fa2cfd36..e9581e969 100644
--- a/src/libnr/nr-svp.cpp
+++ b/src/libnr/nr-svp.cpp
@@ -48,9 +48,9 @@ nr_svp_bbox (NRSVP *svp, NRRect *bbox, unsigned int clear)
seg = svp->segments + sidx;
if (seg->length) {
x0 = MIN (x0, seg->x0);
- y0 = MIN (y0, svp->points[seg->start].y);
+ y0 = MIN (y0, svp->points[seg->start][NR::Y]);
x1 = MAX (x1, seg->x1);
- y1 = MAX (y1, svp->points[seg->start + seg->length - 1].y);
+ y1 = MAX (y1, svp->points[seg->start + seg->length - 1][NR::Y]);
}
}
diff --git a/src/libnr/nr-svp.h b/src/libnr/nr-svp.h
index ca1521f29..122238db6 100644
--- a/src/libnr/nr-svp.h
+++ b/src/libnr/nr-svp.h
@@ -14,8 +14,7 @@
#include <glib/gtypes.h>
#include <libnr/nr-coord.h>
-
-struct NRPoint;
+#include <libnr/nr-forward.h>
struct NRSVPSegment {
gint16 wind;
@@ -33,7 +32,7 @@ struct NRSVPFlat {
struct NRSVP {
unsigned int length;
- NRPoint *points;
+ NR::Point *points;
NRSVPSegment segments[1];
};
diff --git a/src/libnr/nr-values.cpp b/src/libnr/nr-values.cpp
index 846a16bb8..f828c1396 100644
--- a/src/libnr/nr-values.cpp
+++ b/src/libnr/nr-values.cpp
@@ -1,14 +1,14 @@
#define __NR_VALUES_C__
#include <libnr/nr-rect-l.h>
+#include <libnr/nr-matrix-fns.h>
/*
The following predefined objects are for reference
and comparison.
*/
-NRMatrix NR_MATRIX_IDENTITY =
- {{1.0, 0.0, 0.0, 1.0, 0.0, 0.0}};
+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 7fa00d809..fb3c574a6 100644
--- a/src/libnr/nr-values.h
+++ b/src/libnr/nr-values.h
@@ -22,7 +22,7 @@
The following predefined objects are for reference
and comparison. They are defined in nr-values.cpp
*/
-extern NRMatrix NR_MATRIX_IDENTITY;
+extern NR::Matrix NR_MATRIX_IDENTITY;
extern NRRect NR_RECT_EMPTY;
extern NRRectL NR_RECT_L_EMPTY;
extern NRRectL NR_RECT_S_EMPTY;