From: David Gow Date: Wed, 27 Aug 2014 08:24:25 +0000 (+0800) Subject: Add a vec2 struct. X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=b04b227b04626afb2a8bf665dbcbf035bfa1cef8 Add a vec2 struct. --- diff --git a/src/document.cpp b/src/document.cpp index 6c39079..0428aa9 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -152,18 +152,14 @@ int Document::ClipObjectToQuadChild(int object_id, QuadTreeNodeChildren type) obj_bounds.h += (1 - (obj_bounds.y + obj_bounds.h)); } Rect child_node_bounds = TransformFromQuadChild(obj_bounds, type); - Rect clip_bezier_bounds; - clip_bezier_bounds.x = (child_node_bounds.x - m_objects.bounds[object_id].x) / m_objects.bounds[object_id].w; - clip_bezier_bounds.y = (child_node_bounds.y - m_objects.bounds[object_id].y) / m_objects.bounds[object_id].h; - clip_bezier_bounds.w = child_node_bounds.w / m_objects.bounds[object_id].w; - clip_bezier_bounds.h = child_node_bounds.h / m_objects.bounds[object_id].h; + Rect clip_bezier_bounds = TransformRectCoordinates(m_objects.bounds[object_id], child_node_bounds); std::vector new_curves = Bezier(m_objects.beziers[m_objects.data_indices[object_id]], child_node_bounds).ClipToRectangle(clip_bezier_bounds); for (size_t i = 0; i < new_curves.size(); ++i) { Rect new_bounds = TransformToQuadChild(m_objects.bounds[object_id], type); - new_bounds = TransformToQuadChild(new_curves[i].SolveBounds(), type); - Bezier new_curve_data = new_curves[i].ToRelative(new_bounds); - unsigned index = AddBezierData(new_curve_data); + //new_bounds = TransformToQuadChild(new_curves[i].SolveBounds(), type); + //Bezier new_curve_data = new_curves[i].ToRelative(new_bounds); + unsigned index = AddBezierData(new_curves[i]); m_objects.bounds.push_back(new_bounds); m_objects.types.push_back(BEZIER); m_objects.data_indices.push_back(index); diff --git a/src/real.h b/src/real.h index 406cb8e..2be3fdd 100644 --- a/src/real.h +++ b/src/real.h @@ -82,7 +82,31 @@ namespace IPDF return r; } + struct Vec2 + { + Real x; + Real y; + Vec2() : x(0), y(0) {} + Vec2(Real _x, Real _y) : x(_x), y(_y) {} + bool operator==(const Vec2& other) const { return (x == other.x) && (y == other.y); } + bool operator!=(const Vec2& other) const { return !(*this == other); } + + Vec2& operator=(const Vec2& other) { x = other.x; y = other.y; return *this; } + Vec2& operator+=(const Vec2& other) { x += other.x; y += other.y; return *this; } + Vec2& operator-=(const Vec2& other) { x -= other.x; y -= other.y; return *this; } + Vec2& operator*=(const Real& lambda) { x *= lambda; y *= lambda; return *this; } + Vec2& operator/=(const Real& lambda) { x /= lambda; y /= lambda; return *this; } + + Vec2 operator+(const Vec2& other) const { return Vec2(x + other.x, y + other.y); } + Vec2 operator-(const Vec2& other) const { return Vec2(x - other.x, y - other.y); } + Vec2 operator*(const Real& lambda) const { return Vec2(x * lambda, y * lambda); } + Vec2 operator/(const Real& lambda) const { return Vec2(x / lambda, y / lambda); } + + const Real SquareLength() const { return (x*x + y*y); } + + }; + } diff --git a/src/rect.h b/src/rect.h index 7b7adc1..bf7a242 100644 --- a/src/rect.h +++ b/src/rect.h @@ -27,6 +27,26 @@ namespace IPDF return true; } }; + + inline Rect TransformRectCoordinates(const Rect& view, const Rect& r) + { + Rect out; + out.x = (r.x - view.x) / view.w; + out.y = (r.y - view.y) / view.h; + out.w = r.w / view.w; + out.h = r.h / view.h; + return out; + } + + inline Vec2 TransformPointCoordinates(const Rect& view, const Vec2& v) + { + Vec2 out; + out.x = (v.x - view.x) / view.w; + out.y = (v.y - view.y) / view.h; + return out; + } + + } #endif //_RECT_H diff --git a/src/view.h b/src/view.h index 56e80a3..abfbefe 100644 --- a/src/view.h +++ b/src/view.h @@ -6,8 +6,8 @@ #include "framebuffer.h" #include "objectrenderer.h" -#define USE_GPU_TRANSFORM false -#define USE_GPU_RENDERING false +#define USE_GPU_TRANSFORM true +#define USE_GPU_RENDERING true #define USE_SHADING !(USE_GPU_RENDERING) && true namespace IPDF