From ea1ae9915d1702ab62af520b1487f70a553fc6ae Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 25 Feb 2016 11:17:16 -0800 Subject: Make CFX_PSVTemplate simpler. Add default ctor so we don't have to zero these out. Also, make CFX_VTemplate simpler. Also, remove the Set() method in favor of assignment. Also, remove CFX_FloatPoint define. Also, remove unused (and wrong) CFX_VTemplate methods. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1733523003 . --- core/include/fxcrt/fx_coordinates.h | 253 +++++++-------------- .../fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 10 +- core/src/fpdftext/fpdf_text_int.cpp | 3 +- core/src/fxcrt/fx_basic_coords.cpp | 24 +- 4 files changed, 92 insertions(+), 198 deletions(-) (limited to 'core') diff --git a/core/include/fxcrt/fx_coordinates.h b/core/include/fxcrt/fx_coordinates.h index 97462303a3..053d637689 100644 --- a/core/include/fxcrt/fx_coordinates.h +++ b/core/include/fxcrt/fx_coordinates.h @@ -9,187 +9,123 @@ #include "core/include/fxcrt/fx_basic.h" -template -class CFX_PSVTemplate; -template -class CFX_VTemplate; -template -class CFX_PRLTemplate; -template -class CFX_RTemplate; -template -class CFX_ETemplate; -template -class CFX_ATemplate; -template -class CFX_RRTemplate; class CFX_Matrix; -template -class CFX_PSVTemplate { + +template +class CFX_PSTemplate { public: - typedef CFX_PSVTemplate FXT_PSV; - typedef CFX_PSVTemplate FXT_POINT; - typedef CFX_PSVTemplate FXT_SIZE; - void Set(baseType x, baseType y) { FXT_PSV::x = x, FXT_PSV::y = y; } - void Set(const FXT_PSV& psv) { FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; } - void Add(baseType x, baseType y) { FXT_PSV::x += x, FXT_PSV::y += y; } - void Subtract(baseType x, baseType y) { FXT_PSV::x -= x, FXT_PSV::y -= y; } - void Reset() { FXT_PSV::x = FXT_PSV::y = 0; } - FXT_PSV& operator+=(const FXT_PSV& obj) { + CFX_PSTemplate() : x(0), y(0) {} + CFX_PSTemplate(BaseType new_x, BaseType new_y) : x(new_x), y(new_y) {} + CFX_PSTemplate(const CFX_PSTemplate& other) : x(other.x), y(other.y) {} + void clear() { + x = 0; + y = 0; + } + CFX_PSTemplate operator=(const CFX_PSTemplate& other) { + if (this != &other) { + x = other.x; + y = other.y; + } + return *this; + } + bool operator==(const CFX_PSTemplate& other) const { + return x == other.x && y == other.y; + } + bool operator!=(const CFX_PSTemplate& other) const { + return !(*this == other); + } + CFX_PSTemplate& operator+=(const CFX_PSTemplate& obj) { x += obj.x; y += obj.y; return *this; } - FXT_PSV& operator-=(const FXT_PSV& obj) { + CFX_PSTemplate& operator-=(const CFX_PSTemplate& obj) { x -= obj.x; y -= obj.y; return *this; } - FXT_PSV& operator*=(baseType lamda) { - x *= lamda; - y *= lamda; + CFX_PSTemplate& operator*=(BaseType factor) { + x *= factor; + y *= factor; return *this; } - FXT_PSV& operator/=(baseType lamda) { - x /= lamda; - y /= lamda; + CFX_PSTemplate& operator/=(BaseType divisor) { + x /= divisor; + y /= divisor; return *this; } - friend FX_BOOL operator==(const FXT_PSV& obj1, const FXT_PSV& obj2) { - return obj1.x == obj2.x && obj1.y == obj2.y; - } - friend FX_BOOL operator!=(const FXT_PSV& obj1, const FXT_PSV& obj2) { - return obj1.x != obj2.x || obj1.y != obj2.y; - } - friend FXT_PSV operator+(const FXT_PSV& obj1, const FXT_PSV& obj2) { - CFX_PSVTemplate obj; - obj.x = obj1.x + obj2.x; - obj.y = obj1.y + obj2.y; - return obj; - } - friend FXT_PSV operator-(const FXT_PSV& obj1, const FXT_PSV& obj2) { - CFX_PSVTemplate obj; - obj.x = obj1.x - obj2.x; - obj.y = obj1.y - obj2.y; - return obj; - } - friend FXT_PSV operator*(const FXT_PSV& obj, baseType lamda) { - CFX_PSVTemplate t; - t.x = obj.x * lamda; - t.y = obj.y * lamda; - return t; - } - friend FXT_PSV operator*(baseType lamda, const FXT_PSV& obj) { - CFX_PSVTemplate t; - t.x = lamda * obj.x; - t.y = lamda * obj.y; - return t; - } - friend FXT_PSV operator/(const FXT_PSV& obj, baseType lamda) { - CFX_PSVTemplate t; - t.x = obj.x / lamda; - t.y = obj.y / lamda; - return t; - } - baseType x, y; -}; -typedef CFX_PSVTemplate CFX_Point; -typedef CFX_PSVTemplate CFX_PointF; -typedef CFX_PSVTemplate CFX_Size; -typedef CFX_PSVTemplate CFX_SizeF; -typedef CFX_ArrayTemplate CFX_Points; -typedef CFX_ArrayTemplate CFX_PointsF; -typedef CFX_PSVTemplate* FX_LPPOINT; -typedef CFX_PSVTemplate* FX_LPPOINTF; -typedef CFX_PSVTemplate const* FX_LPCPOINT; -typedef CFX_PSVTemplate const* FX_LPCPOINTF; -#define CFX_FloatPoint CFX_PointF -template -class CFX_VTemplate : public CFX_PSVTemplate { - public: - typedef CFX_PSVTemplate FXT_PSV; - typedef CFX_PSVTemplate FXT_POINT; - typedef CFX_PSVTemplate FXT_SIZE; - typedef CFX_VTemplate FXT_VECTOR; - void Set(baseType newx, baseType newy) { - FXT_PSV::x = newx; - FXT_PSV::y = newy; + CFX_PSTemplate operator+(const CFX_PSTemplate& other) { + return CFX_PSTemplate(x + other.x, y + other.y); } - void Set(const FXT_PSV& psv) { FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; } - void Set(const FXT_POINT& p1, const FXT_POINT& p2) { - FXT_PSV::x = p2.x - p1.x, FXT_PSV::y = p2.y - p1.y; + CFX_PSTemplate operator-(const CFX_PSTemplate& other) { + return CFX_PSTemplate(x - other.x, y - other.y); } - void Reset() { FXT_PSV::x = FXT_PSV::y = 0; } - baseType SquareLength() const { - return FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y; + CFX_PSTemplate operator*(BaseType factor) { + return CFX_PSTemplate(x * factor, y * factor); } - baseType Length() const { - return FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y); + CFX_PSTemplate operator/(BaseType divisor) { + return CFX_PSTemplate(x / divisor, y / divisor); } + + BaseType x; + BaseType y; +}; +typedef CFX_PSTemplate CFX_Point; +typedef CFX_PSTemplate CFX_PointF; +typedef CFX_PSTemplate CFX_Size; +typedef CFX_PSTemplate CFX_SizeF; +typedef CFX_ArrayTemplate CFX_Points; +typedef CFX_ArrayTemplate CFX_PointsF; + +template +class CFX_VTemplate : public CFX_PSTemplate { + public: + using CFX_PSTemplate::x; + using CFX_PSTemplate::y; + + CFX_VTemplate() : CFX_PSTemplate() {} + CFX_VTemplate(BaseType new_x, BaseType new_y) + : CFX_PSTemplate(new_x, new_y) {} + + CFX_VTemplate(const CFX_VTemplate& other) : CFX_PSTemplate(other) {} + + CFX_VTemplate(const CFX_PSTemplate& point1, + const CFX_PSTemplate& point2) + : CFX_PSTemplate(point2.x - point1.x, point2.y - point1.y) {} + + FX_FLOAT Length() const { return FXSYS_sqrt(x * x + y * y); } void Normalize() { - FX_FLOAT fLen = - FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y); - if (fLen < 0.0001f) { + FX_FLOAT fLen = Length(); + if (fLen < 0.0001f) return; - } - FXT_PSV::x = ((baseType)FXT_PSV::x) / fLen; - FXT_PSV::y = ((baseType)FXT_PSV::y) / fLen; - } - baseType DotProduct(baseType otherx, baseType othery) const { - return FXT_PSV::x * otherx + FXT_PSV::y * othery; - } - baseType DotProduct(const FXT_VECTOR& v) const { - return FXT_PSV::x * v.x + FXT_PSV::y * v.y; - } - FX_BOOL IsParallel(baseType otherx, baseType othery) const { - baseType t = FXT_PSV::x * othery - FXT_PSV::y * otherx; - return FXSYS_fabs(t) < 0x0001f; - } - FX_BOOL IsParallel(const FXT_VECTOR& v) const { return IsParallel(v.x, v.y); } - FX_BOOL IsPerpendicular(baseType otherx, baseType othery) const { - baseType t = DotProduct(otherx, othery); - return FXSYS_fabs(t) < 0x0001f; + + x /= fLen; + y /= fLen; } - FX_BOOL IsPerpendicular(const FXT_VECTOR& v) const { - return IsPerpendicular(v.x, v.y); + void Translate(BaseType dx, BaseType dy) { + x += dx; + y += dy; } - void Translate(baseType dx, baseType dy) { - FXT_PSV::x += dx, FXT_PSV::y += dy; + void Scale(BaseType sx, BaseType sy) { + x *= sx; + y *= sy; } - void Scale(baseType sx, baseType sy) { FXT_PSV::x *= sx, FXT_PSV::y *= sy; } void Rotate(FX_FLOAT fRadian) { - FX_FLOAT xx = (FX_FLOAT)FXT_PSV::x; - FX_FLOAT yy = (FX_FLOAT)FXT_PSV::y; FX_FLOAT cosValue = FXSYS_cos(fRadian); FX_FLOAT sinValue = FXSYS_sin(fRadian); - FXT_PSV::x = xx * cosValue - yy * sinValue; - FXT_PSV::y = xx * sinValue + yy * cosValue; - } - friend FX_FLOAT Cosine(const FXT_VECTOR& v1, const FXT_VECTOR& v2) { - FXSYS_assert(v1.SquareLength() != 0 && v2.SquareLength() != 0); - FX_FLOAT dotProduct = v1.DotProduct(v2); - return dotProduct / - (FX_FLOAT)FXSYS_sqrt(v1.SquareLength() * v2.SquareLength()); - } - friend FX_FLOAT ArcCosine(const FXT_VECTOR& v1, const FXT_VECTOR& v2) { - return (FX_FLOAT)FXSYS_acos(Cosine(v1, v2)); - } - friend FX_FLOAT SlopeAngle(const FXT_VECTOR& v) { - CFX_VTemplate vx; - vx.Set(1, 0); - FX_FLOAT fSlope = ArcCosine(v, vx); - return v.y < 0 ? -fSlope : fSlope; + x = x * cosValue - y * sinValue; + y = x * sinValue + y * cosValue; } }; typedef CFX_VTemplate CFX_Vector; typedef CFX_VTemplate CFX_VectorF; + template class CFX_RTemplate { public: - typedef CFX_PSVTemplate FXT_POINT; - typedef CFX_PSVTemplate FXT_SIZE; + typedef CFX_PSTemplate FXT_POINT; + typedef CFX_PSTemplate FXT_SIZE; typedef CFX_VTemplate FXT_VECTOR; - typedef CFX_PRLTemplate FXT_PARAL; typedef CFX_RTemplate FXT_RECT; void Set(baseType left, baseType top, baseType width, baseType height) { FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, @@ -335,11 +271,6 @@ class CFX_RTemplate { p.y = top + height / 2; return p; } - void GetParallelogram(FXT_PARAL& pg) const { - pg.x = left, pg.y = top; - pg.x1 = width, pg.y1 = 0; - pg.x2 = 0, pg.y2 = height; - } void Union(baseType x, baseType y) { baseType r = right(), b = bottom(); if (left > x) { @@ -595,16 +526,14 @@ class CFX_FloatRect { bottom += f; } - static CFX_FloatRect GetBBox(const CFX_FloatPoint* pPoints, int nPoints); + static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints); FX_FLOAT left; - FX_FLOAT right; - FX_FLOAT bottom; - FX_FLOAT top; }; + class CFX_Matrix { public: CFX_Matrix() { SetIdentity(); } @@ -694,19 +623,17 @@ class CFX_Matrix { int32_t TransformYDistance(int32_t dy) const; FX_FLOAT TransformDistance(FX_FLOAT dx, FX_FLOAT dy) const; int32_t TransformDistance(int32_t dx, int32_t dy) const; - FX_FLOAT TransformDistance(FX_FLOAT distance) const; + void TransformPoint(FX_FLOAT& x, FX_FLOAT& y) const; void TransformPoint(int32_t& x, int32_t& y) const; - void TransformPoints(CFX_PointF* points, int32_t iCount) const; - void TransformPoints(CFX_Point* points, int32_t iCount) const; void Transform(FX_FLOAT& x, FX_FLOAT& y) const { TransformPoint(x, y); } - void Transform(FX_FLOAT x, FX_FLOAT y, FX_FLOAT& x1, FX_FLOAT& y1) const { x1 = x, y1 = y; TransformPoint(x1, y1); } + void TransformVector(CFX_VectorF& v) const; void TransformVector(CFX_Vector& v) const; void TransformRect(CFX_RectF& rect) const; @@ -716,21 +643,15 @@ class CFX_Matrix { FX_FLOAT& right, FX_FLOAT& top, FX_FLOAT& bottom) const; - void TransformRect(CFX_FloatRect& rect) const { TransformRect(rect.left, rect.right, rect.top, rect.bottom); } FX_FLOAT GetA() const { return a; } - FX_FLOAT GetB() const { return b; } - FX_FLOAT GetC() const { return c; } - FX_FLOAT GetD() const { return d; } - FX_FLOAT GetE() const { return e; } - FX_FLOAT GetF() const { return f; } public: diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 4ad6f81d5e..cc9a998e57 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -768,11 +768,7 @@ static void DrawCoonPatchMeshes(FX_BOOL bTensor, for (int i = 1; i < 13; i++) { pPoints[i].m_Flag = FXPT_BEZIERTO; } - CFX_FloatPoint coords[16]; - for (int i = 0; i < 16; i++) { - coords[i].Set(0.0f, 0.0f); - } - + CFX_PointF coords[16]; int point_count = bTensor ? 16 : 12; while (!stream.m_BitStream.IsEOF()) { FX_DWORD flag = stream.GetFlag(); @@ -780,11 +776,11 @@ static void DrawCoonPatchMeshes(FX_BOOL bTensor, if (flag) { iStartPoint = 4; iStartColor = 2; - CFX_FloatPoint tempCoords[4]; + CFX_PointF tempCoords[4]; for (i = 0; i < 4; i++) { tempCoords[i] = coords[(flag * 3 + i) % 12]; } - FXSYS_memcpy(coords, tempCoords, sizeof(CFX_FloatPoint) * 4); + FXSYS_memcpy(coords, tempCoords, sizeof(tempCoords)); Coon_Color tempColors[2]; tempColors[0] = patch.patch_colors[flag]; tempColors[1] = patch.patch_colors[(flag + 1) % 4]; diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp index 7858fa0bf6..8e2eae1251 100644 --- a/core/src/fpdftext/fpdf_text_int.cpp +++ b/core/src/fpdftext/fpdf_text_int.cpp @@ -1552,8 +1552,7 @@ int32_t CPDF_TextPage::GetTextObjectWritingMode( if (dX <= 0.0001f && dY <= 0.0001f) { return -1; } - CFX_VectorF v; - v.Set(dX, dY); + CFX_VectorF v(dX, dY); v.Normalize(); if (v.y <= 0.0872f) { return v.x <= 0.0872f ? m_TextlineDir : 0; diff --git a/core/src/fxcrt/fx_basic_coords.cpp b/core/src/fxcrt/fx_basic_coords.cpp index 814fa36347..27feb55113 100644 --- a/core/src/fxcrt/fx_basic_coords.cpp +++ b/core/src/fxcrt/fx_basic_coords.cpp @@ -217,8 +217,7 @@ void CFX_FloatRect::UpdateRect(FX_FLOAT x, FX_FLOAT y) { top = y; } } -CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_FloatPoint* pPoints, - int nPoints) { +CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_PointF* pPoints, int nPoints) { if (nPoints == 0) { return CFX_FloatRect(); } @@ -454,27 +453,6 @@ void CFX_Matrix::TransformVector(CFX_Vector& v) const { v.x = FXSYS_round(fx); v.y = FXSYS_round(fy); } -void CFX_Matrix::TransformPoints(CFX_Point* points, int32_t iCount) const { - FXSYS_assert(iCount > 0); - FX_FLOAT fx, fy; - for (int32_t i = 0; i < iCount; i++) { - fx = a * points->x + c * points->y + e; - fy = b * points->x + d * points->y + f; - points->x = FXSYS_round(fx); - points->y = FXSYS_round(fy); - points++; - } -} -void CFX_Matrix::TransformPoints(CFX_PointF* points, int32_t iCount) const { - FXSYS_assert(iCount > 0); - FX_FLOAT fx, fy; - for (int32_t i = 0; i < iCount; i++) { - fx = a * points->x + c * points->y + e; - fy = b * points->x + d * points->y + f; - points->x = fx, points->y = fy; - points++; - } -} void CFX_Matrix::TransformPoint(FX_FLOAT& x, FX_FLOAT& y) const { FX_FLOAT fx = a * x + c * y + e; FX_FLOAT fy = b * x + d * y + f; -- cgit v1.2.3