From 6fdab3c4ec7ca7ad9161136a33ff465e227d9661 Mon Sep 17 00:00:00 2001 From: kramm Date: Fri, 16 Jun 2006 07:04:00 +0000 Subject: [PATCH] added gfxmatrix_transform() --- lib/gfxtools.c | 21 +++++++++++++++++++++ lib/gfxtools.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/lib/gfxtools.c b/lib/gfxtools.c index 60d3f30..239368a 100644 --- a/lib/gfxtools.c +++ b/lib/gfxtools.c @@ -628,3 +628,24 @@ void gfxmatrix_dump(gfxmatrix_t*m, FILE*fi, char*prefix) fprintf(fi, "%f %f | %f\n", m->m00, m->m10, m->tx); fprintf(fi, "%f %f | %f\n", m->m01, m->m11, m->ty); } + +void gfxmatrix_transform(gfxmatrix_t*m, double* v, double*dest) +{ + dest[0] = m->m00*v[0] + m->m10*v[1] + m->tx; + dest[1] = m->m01*v[0] + m->m11*v[1] + m->ty; +} +void gfxmatrix_invert(gfxmatrix_t*m, gfxmatrix_t*dest) +{ + double det = m->m00 * m->m11 - m->m10 * m->m01; + if(!det) { + memset(dest, 0, sizeof(gfxmatrix_t)); + return; + } + det = 1/det; + dest->m00 = m->m11 * det; + dest->m01 = -m->m01 * det; + dest->m10 = -m->m10 * det; + dest->m11 = m->m00 * det; + dest->tx = -(dest->m00 * m->tx + dest->m10 * m->ty); + dest->ty = -(dest->m01 * m->tx + dest->m11 * m->ty); +} diff --git a/lib/gfxtools.h b/lib/gfxtools.h index e18596a..780cfa6 100644 --- a/lib/gfxtools.h +++ b/lib/gfxtools.h @@ -65,6 +65,8 @@ gfxbbox_t gfxbbox_expand_to_point(gfxbbox_t box, gfxcoord_t x, gfxcoord_t y); void gfxline_transform(gfxline_t*line, gfxmatrix_t*matrix); void gfxmatrix_dump(gfxmatrix_t*l, FILE*fi, char*prefix); +void gfxmatrix_transform(gfxmatrix_t*m, gfxcoord_t* v1, gfxcoord_t*dest); +void gfxmatrix_invert(gfxmatrix_t*src, gfxmatrix_t*dest); #ifdef __cplusplus } -- 1.7.10.4