summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/vg/Font.h2
-rw-r--r--src/vg/Image.cpp28
-rw-r--r--src/vg/Math.h415
-rw-r--r--src/vg/Path.cpp250
-rw-r--r--src/vg/Rasterizer.h2
6 files changed, 187 insertions, 511 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 84db850..40d2f62 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,7 +65,6 @@ set(VG_SOURCEFILES
src/es/esShapes.c
src/es/esTransform.c
src/es/esUtil.c
- src/vg/Math.cpp
src/vg/Image.cpp
src/vg/Context.cpp
src/vg/Font.cpp
diff --git a/src/vg/Font.h b/src/vg/Font.h
index ca29cb7..2356c69 100644
--- a/src/vg/Font.h
+++ b/src/vg/Font.h
@@ -62,7 +62,7 @@ public:
GLYPH_PATH = 1,
GLYPH_IMAGE = 2
};
- Glyph() { m_state = GLYPH_UNINITIALIZED; m_path = m_image = VG_INVALID_HANDLE; m_isHinted = false; m_origin.set(0.0f, 0.0f); m_escapement.set(0.0f, 0.0f); }
+ Glyph() { m_state = GLYPH_UNINITIALIZED; m_path = m_image = VG_INVALID_HANDLE; m_isHinted = false; m_origin(0.0f, 0.0f); m_escapement(0.0f, 0.0f); }
unsigned int m_index;
State m_state;
VGPath m_path;
diff --git a/src/vg/Image.cpp b/src/vg/Image.cpp
index 1d3c407..bbe7e16 100644
--- a/src/vg/Image.cpp
+++ b/src/vg/Image.cpp
@@ -1097,7 +1097,7 @@ Color Image::resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGI
Vector3 uvw(x,y,1.0f);
uvw = surfaceToImage * uvw;
- RIfloat oow = 1.0f / uvw.z;
+ RIfloat oow = 1.0f / uvw(2);
uvw *= oow;
if(aq & VG_IMAGE_QUALITY_BETTER)
@@ -1109,12 +1109,12 @@ Color Image::resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGI
RIfloat m_pixelFilterRadius = 1.25f;
RIfloat m_resamplingFilterRadius = 1.25f;
- RIfloat Ux = (surfaceToImage[0][0] - uvw.x * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
- RIfloat Vx = (surfaceToImage[1][0] - uvw.y * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
- RIfloat Uy = (surfaceToImage[0][1] - uvw.x * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
- RIfloat Vy = (surfaceToImage[1][1] - uvw.y * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
- RIfloat U0 = uvw.x;
- RIfloat V0 = uvw.y;
+ RIfloat Ux = (surfaceToImage(0,0) - uvw(0,0) * surfaceToImage(2,0)) * oow * m_pixelFilterRadius;
+ RIfloat Vx = (surfaceToImage(1,0) - uvw(0,1) * surfaceToImage(2,0)) * oow * m_pixelFilterRadius;
+ RIfloat Uy = (surfaceToImage(0,1) - uvw(0,0) * surfaceToImage(2,1)) * oow * m_pixelFilterRadius;
+ RIfloat Vy = (surfaceToImage(1,1) - uvw(0,1) * surfaceToImage(2,1)) * oow * m_pixelFilterRadius;
+ RIfloat U0 = uvw(0);
+ RIfloat V0 = uvw(1);
//calculate mip level
int level = 0;
@@ -1217,23 +1217,23 @@ Color Image::resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGI
}
else if(aq & VG_IMAGE_QUALITY_FASTER)
{ //bilinear
- uvw.x -= 0.5f;
- uvw.y -= 0.5f;
- int u = (int)floor(uvw.x);
- int v = (int)floor(uvw.y);
+ uvw(0,0) -= 0.5f;
+ uvw(0,1) -= 0.5f;
+ int u = (int)floor(uvw(0,0));
+ int v = (int)floor(uvw(0,1));
Color c00 = readTexel(u,v, 0, tilingMode, tileFillColor);
Color c10 = readTexel(u+1,v, 0, tilingMode, tileFillColor);
Color c01 = readTexel(u,v+1, 0, tilingMode, tileFillColor);
Color c11 = readTexel(u+1,v+1, 0, tilingMode, tileFillColor);
- RIfloat fu = uvw.x - (RIfloat)u;
- RIfloat fv = uvw.y - (RIfloat)v;
+ RIfloat fu = uvw(0,0) - (RIfloat)u;
+ RIfloat fv = uvw(0,1) - (RIfloat)v;
Color c0 = c00 * (1.0f - fu) + c10 * fu;
Color c1 = c01 * (1.0f - fu) + c11 * fu;
return c0 * (1.0f - fv) + c1 * fv;
}
else
{ //point sampling
- return readTexel((int)floor(uvw.x), (int)floor(uvw.y), 0, tilingMode, tileFillColor);
+ return readTexel((int)floor(uvw(0,0)), (int)floor(uvw(0,1)), 0, tilingMode, tileFillColor);
}
}
diff --git a/src/vg/Math.h b/src/vg/Math.h
index 7cbcdce..35f06a3 100644
--- a/src/vg/Math.h
+++ b/src/vg/Math.h
@@ -1,380 +1,59 @@
-#ifndef __MATH_H
-#define __MATH_H
-
-/*------------------------------------------------------------------------
- *
- * OpenVG 1.1 Reference Implementation
- * -----------------------------------
- *
- * Copyright (c) 2007 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and /or associated documentation files
- * (the "Materials "), to deal in the Materials without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Materials,
- * and to permit persons to whom the Materials are furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Materials.
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
- * THE USE OR OTHER DEALINGS IN THE MATERIALS.
- *
- *//**
- * \file
- * \brief Math functions, Vector and Matrix classes.
- * \note
- *//*-------------------------------------------------------------------*/
+#ifndef RI_MATH_H
+#define RI_MATH_H
#include "Defs.h"
+#include <Eigen/Dense>
-#include <math.h>
-
-namespace tgOpenVG
-{
-
-/*-------------------------------------------------------------------*//*!
-* \brief
-* \param
-* \return
-* \note
-*//*-------------------------------------------------------------------*/
-
-inline int RI_ISNAN(float a)
-{
- RIfloatInt p;
- p.f = a;
- unsigned int exponent = (p.i>>23) & 0xff;
- unsigned int mantissa = p.i & 0x7fffff;
- if(exponent == 255 && mantissa)
- return 1;
- return 0;
-}
-
-#if (RI_MANTISSA_BITS > 23)
-#error RI_MANTISSA_BITS is greater than 23
-#elif (RI_EXPONENT_BITS > 8)
-#error RI_EXPONENT_BITS is greater than 8
-#elif (RI_MANTISSA_BITS != 23) || (RI_EXPONENT_BITS != 8)
-
-class RIfloat
-{
-public:
- RIfloat() : v(0.0f) { removeBits(); }
- RIfloat(float a) : v(a) { removeBits(); }
- RIfloat(double a) : v((float)a) { removeBits(); }
- RIfloat(int a) : v((float)a) { removeBits(); }
- RIfloat(unsigned int a) : v((float)a) { removeBits(); }
- RIfloat& operator=(const RIfloat &a) { v = a.v; removeBits(); return *this; }
- RIfloat& operator+=(const RIfloat &a){ v += a.v; removeBits(); return *this; }
- RIfloat& operator-=(const RIfloat &a){ v -= a.v; removeBits(); return *this; }
- RIfloat& operator*=(const RIfloat &a){ v *= a.v; removeBits(); return *this; }
- RIfloat& operator/=(const RIfloat &a){ v /= a.v; removeBits(); return *this; }
- RIfloat operator-() const { return -v; }
- operator float() const { return v; }
- operator double() const { return (double)v; }
- operator int() const { return (int)v; }
-
- friend RIfloat operator+(const RIfloat &a, const RIfloat &b);
- friend RIfloat operator+(float a, const RIfloat &b);
- friend RIfloat operator+(const RIfloat &a, float b);
- friend RIfloat operator-(const RIfloat &a, const RIfloat &b);
- friend RIfloat operator-(float a, const RIfloat &b);
- friend RIfloat operator-(const RIfloat &a, float b);
- friend RIfloat operator*(const RIfloat &a, const RIfloat &b);
- friend RIfloat operator*(float a, const RIfloat &b);
- friend RIfloat operator*(const RIfloat &a, float b);
- friend RIfloat operator/(const RIfloat &a, const RIfloat &b);
- friend RIfloat operator/(float a, const RIfloat &b);
- friend RIfloat operator/(const RIfloat &a, float b);
-
- friend bool operator<(const RIfloat &a, const RIfloat &b);
- friend bool operator<(float a, const RIfloat &b);
- friend bool operator<(const RIfloat &a, float b);
- friend bool operator>(const RIfloat &a, const RIfloat &b);
- friend bool operator>(float a, const RIfloat &b);
- friend bool operator>(const RIfloat &a, float b);
- friend bool operator<=(const RIfloat &a, const RIfloat &b);
- friend bool operator<=(float a, const RIfloat &b);
- friend bool operator<=(const RIfloat &a, float b);
- friend bool operator>=(const RIfloat &a, const RIfloat &b);
- friend bool operator>=(float a, const RIfloat &b);
- friend bool operator>=(const RIfloat &a, float b);
- friend bool operator==(const RIfloat &a, const RIfloat &b);
- friend bool operator==(float a, const RIfloat &b);
- friend bool operator==(const RIfloat &a, float b);
- friend bool operator!=(const RIfloat &a, const RIfloat &b);
- friend bool operator!=(float a, const RIfloat &b);
- friend bool operator!=(const RIfloat &a, float b);
-private:
- void removeBits()
- {
- RIfloatInt p;
- p.f = v;
- unsigned int exponent = (p.i>>23) & 0xff;
- if(exponent == 0 || exponent == 255)
- return; //zero, denormal, infinite, or NaN
-
- p.i &= ~((1<<(23-RI_MANTISSA_BITS))-1);
-
-#if (RI_EXPONENT_BITS != 8)
- if (exponent > 127 + (1 << (RI_EXPONENT_BITS-1)))
- exponent = 127 + (1 << (RI_EXPONENT_BITS-1));
-
- if (exponent < 127 + 1 - (1 << (RI_EXPONENT_BITS-1)))
- exponent = 127 + 1 - (1 << (RI_EXPONENT_BITS-1));
-
- p.i &= ~(0xff<<23);
- p.i |= exponent<<23;
-#endif
- v = p.f;
- }
-
- float v;
-};
-
-inline RIfloat operator+(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v+b.v); }
-inline RIfloat operator+(float a, const RIfloat &b) { return RIfloat(a+b.v); }
-inline RIfloat operator+(const RIfloat &a, float b) { return RIfloat(a.v+b); }
-inline RIfloat operator-(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v-b.v); }
-inline RIfloat operator-(float a, const RIfloat &b) { return RIfloat(a-b.v); }
-inline RIfloat operator-(const RIfloat &a, float b) { return RIfloat(a.v-b); }
-inline RIfloat operator*(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v*b.v); }
-inline RIfloat operator*(float a, const RIfloat &b) { return RIfloat(a*b.v); }
-inline RIfloat operator*(const RIfloat &a, float b) { return RIfloat(a.v*b); }
-inline RIfloat operator/(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v/b.v); }
-inline RIfloat operator/(float a, const RIfloat &b) { return RIfloat(a/b.v); }
-inline RIfloat operator/(const RIfloat &a, float b) { return RIfloat(a.v/b); }
-
-inline bool operator<(const RIfloat &a, const RIfloat &b) { return a.v < b.v ? true : false; }
-inline bool operator<(float a, const RIfloat &b) { return a < b.v ? true : false; }
-inline bool operator<(const RIfloat &a, float b) { return a.v < b ? true : false; }
-inline bool operator>(const RIfloat &a, const RIfloat &b) { return a.v > b.v ? true : false; }
-inline bool operator>(float a, const RIfloat &b) { return a > b.v ? true : false; }
-inline bool operator>(const RIfloat &a, float b) { return a.v > b ? true : false; }
-inline bool operator<=(const RIfloat &a, const RIfloat &b) { return a.v <= b.v ? true : false; }
-inline bool operator<=(float a, const RIfloat &b) { return a <= b.v ? true : false; }
-inline bool operator<=(const RIfloat &a, float b) { return a.v <= b ? true : false; }
-inline bool operator>=(const RIfloat &a, const RIfloat &b) { return a.v >= b.v ? true : false; }
-inline bool operator>=(float a, const RIfloat &b) { return a >= b.v ? true : false; }
-inline bool operator>=(const RIfloat &a, float b) { return a.v >= b ? true : false; }
-inline bool operator==(const RIfloat &a, const RIfloat &b) { return a.v == b.v ? true : false; }
-inline bool operator==(float a, const RIfloat &b) { return a == b.v ? true : false; }
-inline bool operator==(const RIfloat &a, float b) { return a.v == b ? true : false; }
-inline bool operator!=(const RIfloat &a, const RIfloat &b) { return a.v != b.v ? true : false; }
-inline bool operator!=(float a, const RIfloat &b) { return a != b.v ? true : false; }
-inline bool operator!=(const RIfloat &a, float b) { return a.v != b ? true : false; }
-
-#else
typedef float RIfloat;
-#endif
-
-#define PI 3.141592654f
-
-inline RIfloat RI_MAX(RIfloat a, RIfloat b) { return (a > b) ? a : b; }
-inline RIfloat RI_MIN(RIfloat a, RIfloat b) { return (a < b) ? a : b; }
-inline RIfloat RI_CLAMP(RIfloat a, RIfloat l, RIfloat h) { if(RI_ISNAN(a)) return l; RI_ASSERT(l <= h); return (a < l) ? l : (a > h) ? h : a; }
-inline void RI_SWAP(RIfloat &a, RIfloat &b) { RIfloat tmp = a; a = b; b = tmp; }
-inline RIfloat RI_ABS(RIfloat a) { return (a < 0.0f) ? -a : a; }
-inline RIfloat RI_SQR(RIfloat a) { return a * a; }
-inline RIfloat RI_DEG_TO_RAD(RIfloat a) { return a * PI / 180.0f; }
-inline RIfloat RI_RAD_TO_DEG(RIfloat a) { return a * 180.0f/ PI; }
-inline RIfloat RI_MOD(RIfloat a, RIfloat b) { if(RI_ISNAN(a) || RI_ISNAN(b)) return 0.0f; RI_ASSERT(b >= 0.0f); if(b == 0.0f) return 0.0f; RIfloat f = (RIfloat)fmod(a, b); if(f < 0.0f) f += b; RI_ASSERT(f >= 0.0f && f <= b); return f; }
-inline int RI_INT_MAX(int a, int b) { return (a > b) ? a : b; }
-inline int RI_INT_MIN(int a, int b) { return (a < b) ? a : b; }
-inline void RI_INT_SWAP(int &a, int &b) { int tmp = a; a = b; b = tmp; }
-inline int RI_INT_MOD(int a, int b) { RI_ASSERT(b >= 0); if(!b) return 0; int i = a % b; if(i < 0) i += b; RI_ASSERT(i >= 0 && i < b); return i; }
-inline int RI_INT_ADDSATURATE(int a, int b) { RI_ASSERT(b >= 0); int r = a + b; return (r >= a) ? r : RI_INT32_MAX; }
+using namespace Eigen;
+using namespace tgOpenVG;
-class Matrix3x3;
-class Vector2;
-class Vector3;
+typedef Matrix<float, 3,3> Matrix3x3;
+typedef Matrix<float, 2, 1> Vector2;
+typedef Matrix<float, 3, 1> Vector3;
-//==============================================================================================
-//MatrixRxC, R = number of rows, C = number of columns
-//indexing: matrix[row][column]
-//Matrix3x3 inline functions cannot be inside the class because Vector3 is not defined yet when Matrix3x3 is defined
+// meh, I'd like to delete these
-class Matrix3x3
-{
-public:
- inline Matrix3x3 (); //initialized to identity
- inline Matrix3x3 ( const Matrix3x3& m );
- inline Matrix3x3 ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 );
- inline ~Matrix3x3 ();
- inline Matrix3x3& operator= ( const Matrix3x3& m );
- inline Vector3& operator[] ( int i ); //returns a row vector
- inline const Vector3& operator[] ( int i ) const;
- inline void set ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 );
- inline const Vector3 getRow ( int i ) const;
- inline const Vector3 getColumn ( int i ) const;
- inline void setRow ( int i, const Vector3& v );
- inline void setColumn ( int i, const Vector3& v );
- inline void operator*= ( const Matrix3x3& m );
- inline void operator*= ( RIfloat f );
- inline void operator+= ( const Matrix3x3& m );
- inline void operator-= ( const Matrix3x3& m );
- inline const Matrix3x3 operator- () const;
- inline void identity ();
- inline void transpose ();
- bool invert (); //if the matrix is singular, returns false and leaves it unmodified
- inline RIfloat det () const;
- inline bool isAffine () const;
-
-private:
- RIfloat matrix[3][3];
-};
-
-//==============================================================================================
+#define PI (float)(3.1415926535897932384626433832795)
-class Vector2
+inline int RI_ISNAN(float a)
{
-public:
- inline Vector2 () : x(0.0f), y(0.0f) {}
- inline Vector2 ( const Vector2& v ) : x(v.x), y(v.y) {}
- inline Vector2 ( RIfloat fx, RIfloat fy ) : x(fx), y(fy) {}
- inline ~Vector2 () {}
- inline Vector2& operator= ( const Vector2& v ) { x = v.x; y = v.y; return *this; }
- inline RIfloat& operator[] ( int i ) { RI_ASSERT(i>=0&&i<2); return (&x)[i]; }
- inline const RIfloat& operator[] ( int i ) const { RI_ASSERT(i>=0&&i<2); return (&x)[i]; }
- inline void set ( RIfloat fx, RIfloat fy ) { x = fx; y = fy; }
- inline void operator*= ( RIfloat f ) { x *= f; y *= f; }
- inline void operator+= ( const Vector2& v ) { x += v.x; y += v.y; }
- inline void operator-= ( const Vector2& v ) { x -= v.x; y -= v.y; }
- inline const Vector2 operator- () const { return Vector2(-x,-y); }
- //if the vector is zero, returns false and leaves it unmodified
- inline bool normalize () { double l = (double)x*(double)x+(double)y*(double)y; if( l == 0.0 ) return false; l = 1.0 / sqrt(l); x = (RIfloat)((double)x * l); y = (RIfloat)((double)y * l); return true; }
- inline RIfloat length () const { return (RIfloat)sqrt((double)x*(double)x+(double)y*(double)y); }
- inline void scale ( const Vector2& v ) { x *= v.x; y *= v.y; } //component-wise scale
- inline void negate () { x = -x; y = -y; }
-
- RIfloat x,y;
-};
-
-//==============================================================================================
-
-class Vector3
-{
-public:
- inline Vector3 () : x(0.0f), y(0.0f), z(0.0f) {}
- inline Vector3 ( const Vector3& v ) : x(v.x), y(v.y), z(v.z) {}
- inline Vector3 ( RIfloat fx, RIfloat fy, RIfloat fz ) : x(fx), y(fy), z(fz) {}
- inline ~Vector3 () {}
- inline Vector3& operator= ( const Vector3& v ) { x = v.x; y = v.y; z = v.z; return *this; }
- inline RIfloat& operator[] ( int i ) { RI_ASSERT(i>=0&&i<3); return (&x)[i]; }
- inline const RIfloat& operator[] ( int i ) const { RI_ASSERT(i>=0&&i<3); return (&x)[i]; }
- inline void set ( RIfloat fx, RIfloat fy, RIfloat fz ){ x = fx; y = fy; z = fz; }
- inline void operator*= ( RIfloat f ) { x *= f; y *= f; z *= f; }
- inline void operator+= ( const Vector3& v ) { x += v.x; y += v.y; z += v.z; }
- inline void operator-= ( const Vector3& v ) { x -= v.x; y -= v.y; z -= v.z; }
- inline const Vector3 operator- () const { return Vector3(-x,-y,-z); }
- //if the vector is zero, returns false and leaves it unmodified
- inline bool normalize () { double l = (double)x*(double)x+(double)y*(double)y+(double)z*(double)z; if( l == 0.0 ) return false; l = 1.0 / sqrt(l); x = (RIfloat)((double)x * l); y = (RIfloat)((double)y * l); z = (RIfloat)((double)z * l); return true; }
- inline RIfloat length () const { return (RIfloat)sqrt((double)x*(double)x+(double)y*(double)y+(double)z*(double)z); }
- inline void scale ( const Vector3& v ) { x *= v.x; y *= v.y; z *= v.z; } //component-wise scale
- inline void negate () { x = -x; y = -y; z = -z; }
-
- RIfloat x,y,z;
-};
-
-//==============================================================================================
-
-//Vector2 global functions
-inline bool operator== ( const Vector2& v1, const Vector2& v2 ) { return (v1.x == v2.x) && (v1.y == v2.y); }
-inline bool operator!= ( const Vector2& v1, const Vector2& v2 ) { return (v1.x != v2.x) || (v1.y != v2.y); }
-inline bool isEqual ( const Vector2& v1, const Vector2& v2, RIfloat epsilon ) { return RI_SQR(v2.x-v1.x) + RI_SQR(v2.y-v1.y) <= epsilon*epsilon; }
-inline bool isZero ( const Vector2& v ) { return (v.x == 0.0f) && (v.y == 0.0f); }
-inline const Vector2 operator* ( RIfloat f, const Vector2& v ) { return Vector2(v.x*f,v.y*f); }
-inline const Vector2 operator* ( const Vector2& v, RIfloat f ) { return Vector2(v.x*f,v.y*f); }
-inline const Vector2 operator+ ( const Vector2& v1, const Vector2& v2 ) { return Vector2(v1.x+v2.x, v1.y+v2.y); }
-inline const Vector2 operator- ( const Vector2& v1, const Vector2& v2 ) { return Vector2(v1.x-v2.x, v1.y-v2.y); }
-inline RIfloat dot ( const Vector2& v1, const Vector2& v2 ) { return v1.x*v2.x+v1.y*v2.y; }
-//if v is a zero vector, returns a zero vector
-inline const Vector2 normalize ( const Vector2& v ) { double l = (double)v.x*(double)v.x+(double)v.y*(double)v.y; if( l != 0.0 ) l = 1.0 / sqrt(l); return Vector2((RIfloat)((double)v.x * l), (RIfloat)((double)v.y * l)); }
-//if onThis is a zero vector, returns a zero vector
-inline const Vector2 project ( const Vector2& v, const Vector2& onThis ) { RIfloat l = dot(onThis,onThis); if( l != 0.0f ) l = dot(v, onThis)/l; return onThis * l; }
-inline const Vector2 lerp ( const Vector2& v1, const Vector2& v2, RIfloat ratio ) { return v1 + ratio * (v2 - v1); }
-inline const Vector2 scale ( const Vector2& v1, const Vector2& v2 ) { return Vector2(v1.x*v2.x, v1.y*v2.y); }
-//matrix * column vector. The input vector2 is implicitly expanded to (x,y,1)
-inline const Vector2 affineTransform( const Matrix3x3& m, const Vector2& v ) { RI_ASSERT(m.isAffine()); return Vector2(v.x * m[0][0] + v.y * m[0][1] + m[0][2], v.x * m[1][0] + v.y * m[1][1] + m[1][2]); }
+ RIfloatInt p;
+ p.f = a;
+ unsigned int exponent = (p.i>>23) & 0xff;
+ unsigned int mantissa = p.i & 0x7fffff;
+ if(exponent == 255 && mantissa)
+ return 1;
+ return 0;
+ }
+
+inline RIfloat RI_MAX(RIfloat a, RIfloat b) { return (a > b) ? a : b; }
+inline RIfloat RI_MIN(RIfloat a, RIfloat b) { return (a < b) ? a : b; }
+inline RIfloat RI_CLAMP(RIfloat a, RIfloat l, RIfloat h) { if(RI_ISNAN(a)) return l; RI_ASSERT(l <= h); return (a < l) ? l : (a > h) ? h : a; }
+inline void RI_SWAP(RIfloat &a, RIfloat &b) { RIfloat tmp = a; a = b; b = tmp; }
+inline RIfloat RI_ABS(RIfloat a) { return (a < 0.0f) ? -a : a; }
+inline RIfloat RI_SQR(RIfloat a) { return a * a; }
+inline RIfloat RI_DEG_TO_RAD(RIfloat a) { return a * PI / 180.0f; }
+inline RIfloat RI_RAD_TO_DEG(RIfloat a) { return a * 180.0f/ PI; }
+inline RIfloat RI_MOD(RIfloat a, RIfloat b) { if(RI_ISNAN(a) || RI_ISNAN(b)) return 0.0f; RI_ASSERT(b >= 0.0f); if(b == 0.0f) return 0.0f; RIfloat f = (RIfloat)fmod(a, b); if(f < 0.0f) f += b; RI_ASSERT(f >= 0.0f && f <= b); return f; }
+
+inline int RI_INT_MAX(int a, int b) { return (a > b) ? a : b; }
+inline int RI_INT_MIN(int a, int b) { return (a < b) ? a : b; }
+inline void RI_INT_SWAP(int &a, int &b) { int tmp = a; a = b; b = tmp; }
+inline int RI_INT_MOD(int a, int b) { RI_ASSERT(b >= 0); if(!b) return 0; int i = a % b; if(i < 0) i += b; RI_ASSERT(i >= 0 && i < b); return i; }
+inline int RI_INT_ADDSATURATE(int a, int b) { RI_ASSERT(b >= 0); int r = a + b; return (r >= a) ? r : RI_INT32_MAX; }
+
+inline const Vector2 perpendicularCW(const Vector2& v) { return Vector2(v(1), -v(0)); }
+inline const Vector2 perpendicularCCW(const Vector2& v) { return Vector2(-v(1), v(0)); }
+inline const Vector2 perpendicular(const Vector2& v, bool cw) { if(cw) return Vector2(v(1), -v(0)); return Vector2(-v(1), v(0)); }
+
+inline const Vector2 normalize ( const Vector2& v ) { double l = (double)v(0)*(double)v(0)+(double)v(1)*(double)v(1); if( l != 0.0 ) l = 1.0 / sqrt(l); return Vector2((RIfloat)((double)v(0) * l), (RIfloat)((double)v(1) * l)); }
+
+
+inline bool isAffine(Matrix3x3 matrix) { if( (matrix(2,0) == 0.0f) && (matrix(2,1) == 0.0f) && (matrix(2,2) == 1.0f) ) return true; return false; }
+inline const Vector2 affineTransform( const Matrix3x3& m, const Vector2& v ) { RI_ASSERT(isAffine(m)); return Vector2(v(0) * m(0,0) + v(1) * m(0,1) + m(0,2), v(0) * m(1,0) + v(1) * m(1,1) + m(1,2)); }
//matrix * column vector. The input vector2 is implicitly expanded to (x,y,0)
-inline const Vector2 affineTangentTransform(const Matrix3x3& m, const Vector2& v) { RI_ASSERT(m.isAffine()); return Vector2(v.x * m[0][0] + v.y * m[0][1], v.x * m[1][0] + v.y * m[1][1]); }
-inline const Vector2 perpendicularCW(const Vector2& v) { return Vector2(v.y, -v.x); }
-inline const Vector2 perpendicularCCW(const Vector2& v) { return Vector2(-v.y, v.x); }
-inline const Vector2 perpendicular(const Vector2& v, bool cw) { if(cw) return Vector2(v.y, -v.x); return Vector2(-v.y, v.x); }
-
-//==============================================================================================
-
-//Vector3 global functions
-inline bool operator== ( const Vector3& v1, const Vector3& v2 ) { return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z); }
-inline bool operator!= ( const Vector3& v1, const Vector3& v2 ) { return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z); }
-inline bool isEqual ( const Vector3& v1, const Vector3& v2, RIfloat epsilon ) { return RI_SQR(v2.x-v1.x) + RI_SQR(v2.y-v1.y) + RI_SQR(v2.z-v1.z) <= epsilon*epsilon; }
-inline const Vector3 operator* ( RIfloat f, const Vector3& v ) { return Vector3(v.x*f,v.y*f,v.z*f); }
-inline const Vector3 operator* ( const Vector3& v, RIfloat f ) { return Vector3(v.x*f,v.y*f,v.z*f); }
-inline const Vector3 operator+ ( const Vector3& v1, const Vector3& v2 ) { return Vector3(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z); }
-inline const Vector3 operator- ( const Vector3& v1, const Vector3& v2 ) { return Vector3(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z); }
-inline RIfloat dot ( const Vector3& v1, const Vector3& v2 ) { return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z; }
-inline const Vector3 cross ( const Vector3& v1, const Vector3& v2 ) { return Vector3( v1.y*v2.z-v1.z*v2.y, v1.z*v2.x-v1.x*v2.z, v1.x*v2.y-v1.y*v2.x ); }
-//if v is a zero vector, returns a zero vector
-inline const Vector3 normalize ( const Vector3& v ) { double l = (double)v.x*(double)v.x+(double)v.y*(double)v.y+(double)v.z*(double)v.z; if( l != 0.0 ) l = 1.0 / sqrt(l); return Vector3((RIfloat)((double)v.x * l), (RIfloat)((double)v.y * l), (RIfloat)((double)v.z * l)); }
-inline const Vector3 lerp ( const Vector3& v1, const Vector3& v2, RIfloat ratio ) { return v1 + ratio * (v2 - v1); }
-inline const Vector3 scale ( const Vector3& v1, const Vector3& v2 ) { return Vector3(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z); }
-
-//==============================================================================================
-
-//matrix * column vector
-inline const Vector3 operator* ( const Matrix3x3& m, const Vector3& v) { return Vector3( v.x*m[0][0]+v.y*m[0][1]+v.z*m[0][2], v.x*m[1][0]+v.y*m[1][1]+v.z*m[1][2], v.x*m[2][0]+v.y*m[2][1]+v.z*m[2][2] ); }
-
-//==============================================================================================
-
-//Matrix3x3 global functions
-inline bool operator== ( const Matrix3x3& m1, const Matrix3x3& m2 ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) if( m1[i][j] != m2[i][j] ) return false; return true; }
-inline bool operator!= ( const Matrix3x3& m1, const Matrix3x3& m2 ) { return !(m1 == m2); }
-inline const Matrix3x3 operator* ( const Matrix3x3& m1, const Matrix3x3& m2 ) { Matrix3x3 t; for(int i=0;i<3;i++) for(int j=0;j<3;j++) t[i][j] = m1[i][0] * m2[0][j] + m1[i][1] * m2[1][j] + m1[i][2] * m2[2][j]; return t; }
-inline const Matrix3x3 operator* ( RIfloat f, const Matrix3x3& m ) { Matrix3x3 t(m); t *= f; return t; }
-inline const Matrix3x3 operator* ( const Matrix3x3& m, RIfloat f ) { Matrix3x3 t(m); t *= f; return t; }
-inline const Matrix3x3 operator+ ( const Matrix3x3& m1, const Matrix3x3& m2 ) { Matrix3x3 t(m1); t += m2; return t; }
-inline const Matrix3x3 operator- ( const Matrix3x3& m1, const Matrix3x3& m2 ) { Matrix3x3 t(m1); t -= m2; return t; }
-inline const Matrix3x3 transpose ( const Matrix3x3& m ) { Matrix3x3 t(m); t.transpose(); return t; }
-// if the matrix is singular, returns it unmodified
-inline const Matrix3x3 invert ( const Matrix3x3& m ) { Matrix3x3 t(m); t.invert(); return t; }
-
-//==============================================================================================
-
-//Matrix3x3 inline functions (cannot be inside the class because Vector3 is not defined yet when Matrix3x3 is defined)
-inline Matrix3x3::Matrix3x3 () { identity(); }
-inline Matrix3x3::Matrix3x3 ( const Matrix3x3& m ) { *this = m; }
-inline Matrix3x3::Matrix3x3 ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 ) { set(m00,m01,m02,m10,m11,m12,m20,m21,m22); }
-inline Matrix3x3::~Matrix3x3 () {}
-inline Matrix3x3& Matrix3x3::operator= ( const Matrix3x3& m ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] = m.matrix[i][j]; return *this; }
-inline Vector3& Matrix3x3::operator[] ( int i ) { RI_ASSERT(i>=0&&i<3); return (Vector3&)matrix[i][0]; }
-inline const Vector3& Matrix3x3::operator[] ( int i ) const { RI_ASSERT(i>=0&&i<3); return (const Vector3&)matrix[i][0]; }
-inline void Matrix3x3::set ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 ) { matrix[0][0] = m00; matrix[0][1] = m01; matrix[0][2] = m02; matrix[1][0] = m10; matrix[1][1] = m11; matrix[1][2] = m12; matrix[2][0] = m20; matrix[2][1] = m21; matrix[2][2] = m22; }
-inline const Vector3 Matrix3x3::getRow ( int i ) const { RI_ASSERT(i>=0&&i<3); return Vector3(matrix[i][0], matrix[i][1], matrix[i][2]); }
-inline const Vector3 Matrix3x3::getColumn ( int i ) const { RI_ASSERT(i>=0&&i<3); return Vector3(matrix[0][i], matrix[1][i], matrix[2][i]); }
-inline void Matrix3x3::setRow ( int i, const Vector3& v ) { RI_ASSERT(i>=0&&i<3); matrix[i][0] = v.x; matrix[i][1] = v.y; matrix[i][2] = v.z; }
-inline void Matrix3x3::setColumn ( int i, const Vector3& v ) { RI_ASSERT(i>=0&&i<3); matrix[0][i] = v.x; matrix[1][i] = v.y; matrix[2][i] = v.z; }
-inline void Matrix3x3::operator*= ( const Matrix3x3& m ) { *this = *this * m; }
-inline void Matrix3x3::operator*= ( RIfloat f ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] *= f; }
-inline void Matrix3x3::operator+= ( const Matrix3x3& m ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] += m.matrix[i][j]; }
-inline void Matrix3x3::operator-= ( const Matrix3x3& m ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] -= m.matrix[i][j]; }
-inline const Matrix3x3 Matrix3x3::operator- () const { return Matrix3x3( -matrix[0][0],-matrix[0][1],-matrix[0][2], -matrix[1][0],-matrix[1][1],-matrix[1][2], -matrix[2][0],-matrix[2][1],-matrix[2][2]); }
-inline void Matrix3x3::identity () { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] = (i == j) ? 1.0f : 0.0f; }
-inline void Matrix3x3::transpose () { RI_SWAP(matrix[1][0], matrix[0][1]); RI_SWAP(matrix[2][0], matrix[0][2]); RI_SWAP(matrix[2][1], matrix[1][2]); }
-inline RIfloat Matrix3x3::det () const { return matrix[0][0] * (matrix[1][1]*matrix[2][2] - matrix[2][1]*matrix[1][2]) + matrix[0][1] * (matrix[2][0]*matrix[1][2] - matrix[1][0]*matrix[2][2]) + matrix[0][2] * (matrix[1][0]*matrix[2][1] - matrix[2][0]*matrix[1][1]); }
-inline bool Matrix3x3::isAffine () const { if(matrix[2][0] == 0.0f && matrix[2][1] == 0.0f && matrix[2][2] == 1.0f) return true; return false; }
-
-//==============================================================================================
-
-} //namespace tgOpenVG
-
-#endif /* __MATH_H */
+inline const Vector2 affineTangentTransform(const Matrix3x3& m, const Vector2& v) { RI_ASSERT(isAffine(m)); return Vector2(v(0) * m(0,0) + v(1) * m(0,1), v(0) * m(1,0) + v(1) * m(1,1)); }
+#endif // RI_MATH_H
diff --git a/src/vg/Path.cpp b/src/vg/Path.cpp
index 71469f5..6cdad9b 100644
--- a/src/vg/Path.cpp
+++ b/src/vg/Path.cpp
@@ -58,9 +58,9 @@ static const Vector2 unitAverage(const Vector2& u0, const Vector2& u1, bool cw)
Vector2 u = 0.5f * (u0 + u1);
Vector2 n0 = perpendicularCCW(u0);
- if( dot(u, u) > 0.25f )
+ if( u.dot(u) > 0.25f )
{ //the average is long enough and thus reliable
- if( dot(n0, u1) < 0.0f )
+ if( n0.dot(u1) < 0.0f )
u = -u; //choose the larger angle
}
else
@@ -87,12 +87,12 @@ static const Vector2 unitAverage(const Vector2& u0, const Vector2& u1)
{
Vector2 u = 0.5f * (u0 + u1);
- if( dot(u, u) < 0.25f )
+ if( u.dot(u) < 0.25f )
{ // the average is unreliable, use the average of the normals to the vectors instead
Vector2 n0 = perpendicularCCW(u0);
Vector2 n1 = perpendicularCW(u1);
u = 0.5f * (n0 + n1);
- if( dot(n1, u0) < 0.0f )
+ if( n1.dot(u0) < 0.0f )
u = -u;
}
@@ -485,7 +485,7 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
{
RI_ASSERT(srcPath);
RI_ASSERT(m_referenceCount > 0 && srcPath->m_referenceCount > 0);
- RI_ASSERT(matrix.isAffine());
+ RI_ASSERT(isAffine(matrix));
if(!srcPath->m_segments.size())
return;
@@ -551,8 +551,8 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(1));
s = c;
o = c;
break;
@@ -572,8 +572,8 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(1));
o = c;
break;
}
@@ -586,7 +586,7 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
if (absRel == VG_ABSOLUTE)
{
- c.y = o.y;
+ c(1) = o(1);
tc = affineTransform(matrix, c);
}
else
@@ -595,8 +595,8 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(1));
o = c;
segment = VG_LINE_TO;
break;
@@ -610,7 +610,7 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
if (absRel == VG_ABSOLUTE)
{
- c.x = o.x;
+ c(0) = o(0);
tc = affineTransform(matrix, c);
}
else
@@ -619,8 +619,8 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(1));
o = c;
segment = VG_LINE_TO;
break;
@@ -645,10 +645,10 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c1 += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.y);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0(1));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(1));
o = c1;
break;
}
@@ -675,12 +675,12 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c2 += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.y);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0(1));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(1));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2(1));
o = c2;
break;
}
@@ -699,8 +699,8 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c1 += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(1));
o = c1;
break;
}
@@ -724,10 +724,10 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
c2 += o;
}
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1(1));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2(1));
o = c2;
break;
}
@@ -743,21 +743,22 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
Vector2 c(srcPath->getCoordinate(srcCoord+3), srcPath->getCoordinate(srcCoord+4));
rot = RI_DEG_TO_RAD(rot);
- Matrix3x3 u((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
+ Matrix3x3 u;
+ u << (RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
(RIfloat)sin(rot)*rh, (RIfloat)cos(rot)*rv, 0,
- 0, 0, 1);
+ 0, 0, 1;
u = matrix * u;
- u[2].set(0,0,1); //force affinity
+ u(2,0) = 0.0f; u(2,1)=0.0f; u(2,2)=1.0f; // force affinity
//u maps from the unit circle to transformed ellipse
//compute new rh, rv and rot
- Vector2 p(u[0][0], u[1][0]);
- Vector2 q(u[1][1], -u[0][1]);
+ Vector2 p(u(0,0), u(1,0));
+ Vector2 q(u(1,1), -u(0,1));
bool swapped = false;
- if(dot(p,p) < dot(q,q))
+ if(p.dot(p) < q.dot(q))
{
- RI_SWAP(p.x,q.x);
- RI_SWAP(p.y,q.y);
+ RI_SWAP(p(0),q(0));
+ RI_SWAP(p(1),q(1));
swapped = true;
}
Vector2 h = (p+q) * 0.5f;
@@ -767,14 +768,14 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
rh = hlen + hplen;
rv = hlen - hplen;
h = hplen * h + hlen * hp;
- hlen = dot(h,h);
+ hlen = h.dot(h);
if(hlen == 0.0f)
rot = 0.0f;
else
{
h.normalize();
- rot = (RIfloat)acos(h.x);
- if(h.y < 0.0f)
+ rot = (RIfloat)acos(h(0));
+ if(h(1) < 0.0f)
rot = 2.0f*PI - rot;
}
if(swapped)
@@ -792,8 +793,8 @@ void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, rh);
setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, rv);
setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, RI_RAD_TO_DEG(rot));
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
- setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(0));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc(1));
o = c;
//flip winding if the determinant is negative
@@ -907,8 +908,8 @@ void Path::normalizeForInterpolation(const Path* srcPath)
Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
if(absRel == VG_RELATIVE)
c += o;
- setCoordinate(dstCoord++, c.x);
- setCoordinate(dstCoord++, c.y);
+ setCoordinate(dstCoord++, c(0));
+ setCoordinate(dstCoord++, c(1));
s = c;
p = c;
o = c;
@@ -921,8 +922,8 @@ void Path::normalizeForInterpolation(const Path* srcPath)
Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
if(absRel == VG_RELATIVE)
c += o;
- setCoordinate(dstCoord++, c.x);
- setCoordinate(dstCoord++, c.y);
+ setCoordinate(dstCoord++, c(0));
+ setCoordinate(dstCoord++, c(1));
p = c;
o = c;
break;
@@ -931,11 +932,11 @@ void Path::normalizeForInterpolation(const Path* srcPath)
case VG_HLINE_TO:
{
RI_ASSERT(coords == 1);
- Vector2 c(srcPath->getCoordinate(srcCoord+0), o.y);
+ Vector2 c(srcPath->getCoordinate(srcCoord+0), o(1));
if(absRel == VG_RELATIVE)
- c.x += o.x;
- setCoordinate(dstCoord++, c.x);
- setCoordinate(dstCoord++, c.y);
+ c(0) += o(0);
+ setCoordinate(dstCoord++, c(0));
+ setCoordinate(dstCoord++, c(1));
p = c;
o = c;
segment = VG_LINE_TO;
@@ -945,11 +946,11 @@ void Path::normalizeForInterpolation(const Path* srcPath)
case VG_VLINE_TO:
{
RI_ASSERT(coords == 1);
- Vector2 c(o.x, srcPath->getCoordinate(srcCoord+0));
+ Vector2 c(o(0), srcPath->getCoordinate(srcCoord+0));
if(absRel == VG_RELATIVE)
- c.y += o.y;
- setCoordinate(dstCoord++, c.x);
- setCoordinate(dstCoord++, c.y);
+ c(1) += o(1);
+ setCoordinate(dstCoord++, c(0));
+ setCoordinate(dstCoord++, c(1));
p = c;
o = c;
segment = VG_LINE_TO;
@@ -968,12 +969,12 @@ void Path::normalizeForInterpolation(const Path* srcPath)
}
Vector2 d0 = (1.0f/3.0f) * (o + 2.0f * c0);
Vector2 d1 = (1.0f/3.0f) * (c1 + 2.0f * c0);
- setCoordinate(dstCoord++, d0.x);
- setCoordinate(dstCoord++, d0.y);
- setCoordinate(dstCoord++, d1.x);
- setCoordinate(dstCoord++, d1.y);
- setCoordinate(dstCoord++, c1.x);
- setCoordinate(dstCoord++, c1.y);
+ setCoordinate(dstCoord++, d0(0));
+ setCoordinate(dstCoord++, d0(1));
+ setCoordinate(dstCoord++, d1(0));
+ setCoordinate(dstCoord++, d1(1));
+ setCoordinate(dstCoord++, c1(0));
+ setCoordinate(dstCoord++, c1(1));
p = c0;
o = c1;
segment = VG_CUBIC_TO;
@@ -992,12 +993,12 @@ void Path::normalizeForInterpolation(const Path* srcPath)
c1 += o;
c2 += o;
}
- setCoordinate(dstCoord++, c0.x);
- setCoordinate(dstCoord++, c0.y);
- setCoordinate(dstCoord++, c1.x);
- setCoordinate(dstCoord++, c1.y);
- setCoordinate(dstCoord++, c2.x);
- setCoordinate(dstCoord++, c2.y);
+ setCoordinate(dstCoord++, c0(0));
+ setCoordinate(dstCoord++, c0(1));
+ setCoordinate(dstCoord++, c1(0));
+ setCoordinate(dstCoord++, c1(1));
+ setCoordinate(dstCoord++, c2(0));
+ setCoordinate(dstCoord++, c2(1));
p = c1;
o = c2;
break;
@@ -1012,12 +1013,12 @@ void Path::normalizeForInterpolation(const Path* srcPath)
c1 += o;
Vector2 d0 = (1.0f/3.0f) * (o + 2.0f * c0);
Vector2 d1 = (1.0f/3.0f) * (c1 + 2.0f * c0);
- setCoordinate(dstCoord++, d0.x);
- setCoordinate(dstCoord++, d0.y);
- setCoordinate(dstCoord++, d1.x);
- setCoordinate(dstCoord++, d1.y);
- setCoordinate(dstCoord++, c1.x);
- setCoordinate(dstCoord++, c1.y);
+ setCoordinate(dstCoord++, d0(0));
+ setCoordinate(dstCoord++, d0(1));
+ setCoordinate(dstCoord++, d1(0));
+ setCoordinate(dstCoord++, d1(1));
+ setCoordinate(dstCoord++, c1(0));
+ setCoordinate(dstCoord++, c1(1));
p = c0;
o = c1;
segment = VG_CUBIC_TO;
@@ -1035,12 +1036,12 @@ void Path::normalizeForInterpolation(const Path* srcPath)
c1 += o;
c2 += o;
}
- setCoordinate(dstCoord++, c0.x);
- setCoordinate(dstCoord++, c0.y);
- setCoordinate(dstCoord++, c1.x);
- setCoordinate(dstCoord++, c1.y);
- setCoordinate(dstCoord++, c2.x);
- setCoordinate(dstCoord++, c2.y);
+ setCoordinate(dstCoord++, c0(0));
+ setCoordinate(dstCoord++, c0(1));
+ setCoordinate(dstCoord++, c1(0));
+ setCoordinate(dstCoord++, c1(1));
+ setCoordinate(dstCoord++, c2(0));
+ setCoordinate(dstCoord++, c2(1));
p = c1;
o = c2;
segment = VG_CUBIC_TO;
@@ -1061,8 +1062,8 @@ void Path::normalizeForInterpolation(const Path* srcPath)
setCoordinate(dstCoord++, rh);
setCoordinate(dstCoord++, rv);
setCoordinate(dstCoord++, rot);
- setCoordinate(dstCoord++, c.x);
- setCoordinate(dstCoord++, c.y);
+ setCoordinate(dstCoord++, c(0));
+ setCoordinate(dstCoord++, c(1));
p = c;
o = c;
break;
@@ -1212,7 +1213,7 @@ void Path::interpolateStroke(const Matrix3x3& pathToSurface, Rasterizer& rasteri
const RIfloat tessellationAngle = 5.0f;
- RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(dot(v0.t, v1.t), -1.0f, 1.0f))) / tessellationAngle;
+ RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(v0.t.dot(v1.t), -1.0f, 1.0f))) / tessellationAngle;
int samples = RI_INT_MAX((int)ceil(angle), 1);
for(int j=0;j<samples-1;j++)
@@ -1337,7 +1338,7 @@ void Path::doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const
rasterizer.clear();
- if( dot(tccw, v0.t) > 0.0f )
+ if( tccw.dot(v0.t) > 0.0f )
{ //draw ccw miter (draw from point 0 to 1)
s = ccw0t;
e = ccw1t;
@@ -1366,7 +1367,7 @@ void Path::doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const
{
case VG_JOIN_MITER:
{
- RIfloat theta = (RIfloat)acos(RI_CLAMP(dot(v0.t, -v1.t), -1.0f, 1.0f));
+ RIfloat theta = (RIfloat)acos(RI_CLAMP(v0.t.dot(-v1.t), -1.0f, 1.0f));
RIfloat miterLengthPerStrokeWidth = 1.0f / (RIfloat)sin(theta*0.5f);
if( miterLengthPerStrokeWidth < miterLimit )
{ //miter
@@ -1389,7 +1390,7 @@ void Path::doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const
const RIfloat tessellationAngle = 5.0f;
Vector2 prev = s;
- RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(dot(st, et), -1.0f, 1.0f))) / tessellationAngle;
+ RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(st.dot(et), -1.0f, 1.0f))) / tessellationAngle;
int samples = (int)ceil(angle);
if( samples )
{
@@ -1524,8 +1525,8 @@ void Path::stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const
{
StrokeVertex vi = vs;
vi.t = -vi.t;
- RI_SWAP(vi.ccw.x, vi.cw.x);
- RI_SWAP(vi.ccw.y, vi.cw.y);
+ RI_SWAP(vi.ccw(0), vi.cw(0));
+ RI_SWAP(vi.ccw(1), vi.cw(1));
doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //start cap //throws bad_alloc
}
}
@@ -1570,8 +1571,8 @@ void Path::stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const
{ //prevDashVertex is not the start vertex of the segment, cap it (start vertex has already been joined or capped)
StrokeVertex vi = prevDashVertex;
vi.t = -vi.t;
- RI_SWAP(vi.ccw.x, vi.cw.x);
- RI_SWAP(vi.ccw.y, vi.cw.y);
+ RI_SWAP(vi.ccw(0), vi.cw(0));
+ RI_SWAP(vi.ccw(1), vi.cw(1));
doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //throws bad_alloc
}
interpolateStroke(pathToSurface, rasterizer, prevDashVertex, nextDashVertex, strokeWidth); //throws bad_alloc
@@ -1600,8 +1601,8 @@ void Path::stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const
{ //prevDashVertex is not the start vertex of the segment, cap it (start vertex has already been joined or capped)
StrokeVertex vi = prevDashVertex;
vi.t = -vi.t;
- RI_SWAP(vi.ccw.x, vi.cw.x);
- RI_SWAP(vi.ccw.y, vi.cw.y);
+ RI_SWAP(vi.ccw(0), vi.cw(0));
+ RI_SWAP(vi.ccw(1), vi.cw(1));
doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //throws bad_alloc
}
interpolateStroke(pathToSurface, rasterizer, prevDashVertex, v1, strokeWidth); //throws bad_alloc
@@ -1627,8 +1628,8 @@ void Path::stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const
{
StrokeVertex vi = vs;
vi.t = -vi.t;
- RI_SWAP(vi.ccw.x, vi.cw.x);
- RI_SWAP(vi.ccw.y, vi.cw.y);
+ RI_SWAP(vi.ccw(0), vi.cw(0));
+ RI_SWAP(vi.ccw(1), vi.cw(1));
doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //start cap //throws bad_alloc
}
}
@@ -1678,8 +1679,8 @@ void Path::getPointAlong(int startIndex, int numSegments, RIfloat distance, Vect
// empty path?
if (!m_vertices.size() || !numSegments)
{
- p.set(0,0);
- t.set(1,0);
+ p << 0,0;
+ t << 1,0;
return;
}
@@ -1693,7 +1694,7 @@ void Path::getPointAlong(int startIndex, int numSegments, RIfloat distance, Vect
if (startVertex >= endVertex)
{
p = m_vertices[startVertex].userPosition;
- t.set(1,0);
+ t << 1,0;
return;
}
@@ -1847,10 +1848,10 @@ void Path::getPathTransformedBounds(const Matrix3x3& pathToSurface, RIfloat& min
p2 = pathToSurface * p2;
p3 = pathToSurface * p3;
- minx = RI_MIN(RI_MIN(RI_MIN(p0.x, p1.x), p2.x), p3.x);
- miny = RI_MIN(RI_MIN(RI_MIN(p0.y, p1.y), p2.y), p3.y);
- maxx = RI_MAX(RI_MAX(RI_MAX(p0.x, p1.x), p2.x), p3.x);
- maxy = RI_MAX(RI_MAX(RI_MAX(p0.y, p1.y), p2.y), p3.y);
+ minx = RI_MIN(RI_MIN(RI_MIN(p0(0), p1(0)), p2(0)), p3(0));
+ miny = RI_MIN(RI_MIN(RI_MIN(p0(1), p1(1)), p2(1)), p3(1));
+ maxx = RI_MAX(RI_MAX(RI_MAX(p0(0), p1(0)), p2(0)), p3(0));
+ maxy = RI_MAX(RI_MAX(RI_MAX(p0(1), p1(1)), p2(1)), p3(1));
}
else
{
@@ -1878,10 +1879,10 @@ void Path::addVertex(const Vector2& p, const Vector2& t, RIfloat pathLength, uns
m_vertices.push_back(v); //throws bad_alloc
m_numTessVertices++;
- m_userMinx = RI_MIN(m_userMinx, v.userPosition.x);
- m_userMiny = RI_MIN(m_userMiny, v.userPosition.y);
- m_userMaxx = RI_MAX(m_userMaxx, v.userPosition.x);
- m_userMaxy = RI_MAX(m_userMaxy, v.userPosition.y);
+ m_userMinx = RI_MIN(m_userMinx, v.userPosition(0));
+ m_userMiny = RI_MIN(m_userMiny, v.userPosition(1));
+ m_userMaxx = RI_MAX(m_userMaxx, v.userPosition(0));
+ m_userMaxy = RI_MAX(m_userMaxy, v.userPosition(1));
}
/*-------------------------------------------------------------------*//*!
@@ -2119,14 +2120,14 @@ static bool findEllipses(RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p0,
return false; //degenerate ellipse
rot = RI_DEG_TO_RAD(rot);
- unitCircleToEllipse.set((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
+ unitCircleToEllipse << (RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
(RIfloat)sin(rot)*rh, (RIfloat)cos(rot)*rv, 0,
- 0, 0, 1);
+ 0, 0, 1;
Matrix3x3 ellipseToUnitCircle = invert(unitCircleToEllipse);
//force affinity
- ellipseToUnitCircle[2][0] = 0.0f;
- ellipseToUnitCircle[2][1] = 0.0f;
- ellipseToUnitCircle[2][2] = 1.0f;
+ ellipseToUnitCircle(2,0) = 0.0f;
+ ellipseToUnitCircle(2,1) = 0.0f;
+ ellipseToUnitCircle(2,2) = 1.0f;
// Transform p0 and p1 into unit space
u0 = affineTransform(ellipseToUnitCircle, p0);
@@ -2135,7 +2136,7 @@ static bool findEllipses(RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p0,
Vector2 m = 0.5f * (u0 + u1);
Vector2 d = u0 - u1;
- RIfloat lsq = (RIfloat)dot(d,d);
+ RIfloat lsq = (RIfloat)d.dot(d);
if(lsq <= 0.0f)
return false; //the points are coincident
@@ -2147,14 +2148,14 @@ static bool findEllipses(RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p0,
rv *= 0.5f * l;
//redo the computation with scaled axes
- unitCircleToEllipse.set((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
+ unitCircleToEllipse <<(RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
(RIfloat)sin(rot)*rh, (RIfloat)cos(rot)*rv, 0,
- 0, 0, 1);
+ 0, 0, 1;
ellipseToUnitCircle = invert(unitCircleToEllipse);
//force affinity
- ellipseToUnitCircle[2][0] = 0.0f;
- ellipseToUnitCircle[2][1] = 0.0f;
- ellipseToUnitCircle[2][2] = 1.0f;
+ ellipseToUnitCircle(2,0) = 0.0f;
+ ellipseToUnitCircle(2,1) = 0.0f;
+ ellipseToUnitCircle(2,2) = 1.0f;
// Transform p0 and p1 into unit space
u0 = affineTransform(ellipseToUnitCircle, p0);
@@ -2164,7 +2165,7 @@ static bool findEllipses(RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p0,
d = u0 - u1;
m = 0.5f * (u0 + u1);
- lsq = dot(d,d);
+ lsq = d.dot(d);
if(lsq <= 0.0f)
return false; //the points are coincident
@@ -2196,8 +2197,8 @@ static bool findEllipses(RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p0,
//transform back to the original coordinate space
cp = affineTransform(unitCircleToEllipse, cp);
- unitCircleToEllipse[0][2] = cp.x;
- unitCircleToEllipse[1][2] = cp.y;
+ unitCircleToEllipse(0,2) = cp(0);
+ unitCircleToEllipse(1,2) = cp(1);
return true;
}
@@ -2298,9 +2299,6 @@ void Path::tessellate(const Matrix3x3& pathToSurface, float strokeWidth)
//tessellate the path segments
coordIndex = 0;
- s.set(0,0);
- o.set(0,0);
- p.set(0,0);
bool subpathHasGeometry = false;
VGPathSegment prevSegment = VG_MOVE_TO;
for(int i=0;i<m_segments.size();i++)
@@ -2353,9 +2351,9 @@ void Path::tessellate(const Matrix3x3& pathToSurface, float strokeWidth)
case VG_HLINE_TO:
{
RI_ASSERT(coords == 1);
- Vector2 c(getCoordinate(coordIndex+0), o.y);
+ Vector2 c(getCoordinate(coordIndex+0), o(1));
if(absRel == VG_RELATIVE)
- c.x += o.x;
+ c(0) += o(0);
if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
subpathHasGeometry = true;
p = c;
@@ -2366,9 +2364,9 @@ void Path::tessellate(const Matrix3x3& pathToSurface, float strokeWidth)
case VG_VLINE_TO:
{
RI_ASSERT(coords == 1);
- Vector2 c(o.x, getCoordinate(coordIndex+0));
+ Vector2 c(o(0), getCoordinate(coordIndex+0));
if(absRel == VG_RELATIVE)
- c.y += o.y;
+ c(1) += o(1);
if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
subpathHasGeometry = true;
p = c;
diff --git a/src/vg/Rasterizer.h b/src/vg/Rasterizer.h
index f1539a7..c6a9041 100644
--- a/src/vg/Rasterizer.h
+++ b/src/vg/Rasterizer.h
@@ -54,7 +54,7 @@ typedef RIfloat RScalar; //change this if you want to have different precision f
struct RVector2
{
inline RVector2() { }
- inline RVector2(const Vector2& v) { x = v.x; y = v.y; }
+ inline RVector2(const Vector2& v) { x = v(0,0); y = v(0,1); }
inline RVector2(RIfloat vx, RIfloat vy) { x = vx; y = vy; }
inline void set(RIfloat vx, RIfloat vy) { x = vx; y = vy; }
RScalar x;