OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef _FXCRT_COORDINATES_ | 7 #ifndef _FXCRT_COORDINATES_ |
8 #define _FXCRT_COORDINATES_ | 8 #define _FXCRT_COORDINATES_ |
9 | 9 |
10 #include "fx_basic.h" | 10 #include "fx_basic.h" |
11 | 11 |
12 template<class baseType> class CFX_PSVTemplate; | 12 template<class baseType> class CFX_PSVTemplate; |
Tom Sepez
2015/04/10 21:33:04
I don't think there's a need to forward declare an
| |
13 template<class baseType> class CFX_VTemplate; | 13 template<class baseType> class CFX_VTemplate; |
14 template<class baseType> class CFX_PRLTemplate; | 14 template<class baseType> class CFX_PRLTemplate; |
Tom Sepez
2015/04/10 21:33:05
I didn't see an implementation of CFX_PRLTemplate
| |
15 template<class baseType> class CFX_RTemplate; | 15 template<class baseType> class CFX_RTemplate; |
16 template<class baseType> class CFX_ETemplate; | 16 template<class baseType> class CFX_ETemplate; |
Tom Sepez
2015/04/10 21:33:04
CFX_ETemplate appears unused.
| |
17 template<class baseType> class CFX_ATemplate; | 17 template<class baseType> class CFX_ATemplate; |
Tom Sepez
2015/04/10 21:33:05
CFX_ATemplate appears unused.
| |
18 template<class baseType> class CFX_RRTemplate; | 18 template<class baseType> class CFX_RRTemplate; |
Tom Sepez
2015/04/10 21:33:04
CFX_RRTemplate appears unused.
| |
19 class CFX_Matrix; | 19 class CFX_Matrix; |
20 template<class baseType> | 20 template<class baseType> |
21 class CFX_PSVTemplate : public CFX_Object | 21 class CFX_PSVTemplate : public CFX_Object |
22 { | 22 { |
23 public: | 23 public: |
24 typedef CFX_PSVTemplate<baseType> FXT_PSV; | 24 typedef CFX_PSVTemplate<baseType> FXT_PSV; |
25 typedef CFX_PSVTemplate<baseType> FXT_POINT; | 25 typedef CFX_PSVTemplate<baseType> FXT_POINT; |
Tom Sepez
2015/04/10 21:33:04
FXT_POINT appears unused, shadowed in subclass. ma
| |
26 typedef CFX_PSVTemplate<baseType> FXT_SIZE; | 26 typedef CFX_PSVTemplate<baseType> FXT_SIZE; |
Tom Sepez
2015/04/10 21:33:05
FXT_SIZE ditto
| |
27 void Set(baseType x, baseType y) | 27 void Set(baseType x, baseType y) |
Tom Sepez
2015/04/10 21:33:05
Same issue with shadowing parameters. Then we can
| |
28 { | 28 { |
29 FXT_PSV::x = x, FXT_PSV::y = y; | 29 FXT_PSV::x = x, FXT_PSV::y = y; |
30 } | 30 } |
31 void Set(const FXT_PSV &psv) | 31 void Set(const FXT_PSV &psv) |
32 { | 32 { |
33 FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; | 33 FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; |
34 } | 34 } |
35 void Add(baseType x, baseType y) | 35 void Add(baseType x, baseType y) |
36 { | 36 { |
37 FXT_PSV::x += x, FXT_PSV::y += y; | 37 FXT_PSV::x += x, FXT_PSV::y += y; |
(...skipping 23 matching lines...) Expand all Loading... | |
61 x *= lamda; | 61 x *= lamda; |
62 y *= lamda; | 62 y *= lamda; |
63 return *this; | 63 return *this; |
64 } | 64 } |
65 FXT_PSV& operator /= (baseType lamda) | 65 FXT_PSV& operator /= (baseType lamda) |
66 { | 66 { |
67 x /= lamda; | 67 x /= lamda; |
68 y /= lamda; | 68 y /= lamda; |
69 return *this; | 69 return *this; |
70 } | 70 } |
71 friend FX_BOOL operator == (const FXT_PSV &obj1, const FXT_PSV &obj2) | 71 friend FX_BOOL operator == (const FXT_PSV &obj1, const FXT_PSV &obj2) |
Tom Sepez
2015/04/10 21:33:05
why "friend"? x, y are public.
I think they wanted
| |
72 { | 72 { |
73 return obj1.x == obj2.x && obj1.y == obj2.y; | 73 return obj1.x == obj2.x && obj1.y == obj2.y; |
74 } | 74 } |
75 friend FX_BOOL operator != (const FXT_PSV &obj1, const FXT_PSV &obj2) | 75 friend FX_BOOL operator != (const FXT_PSV &obj1, const FXT_PSV &obj2) |
76 { | 76 { |
77 return obj1.x != obj2.x || obj1.y != obj2.y; | 77 return obj1.x != obj2.x || obj1.y != obj2.y; |
78 } | 78 } |
79 friend FXT_PSV operator + (const FXT_PSV &obj1, const FXT_PSV & obj2) | 79 friend FXT_PSV operator + (const FXT_PSV &obj1, const FXT_PSV & obj2) |
80 { | 80 { |
81 CFX_PSVTemplate obj; | 81 CFX_PSVTemplate obj; |
(...skipping 26 matching lines...) Expand all Loading... | |
108 { | 108 { |
109 CFX_PSVTemplate t; | 109 CFX_PSVTemplate t; |
110 t.x = obj.x / lamda; | 110 t.x = obj.x / lamda; |
111 t.y = obj.y / lamda; | 111 t.y = obj.y / lamda; |
112 return t; | 112 return t; |
113 } | 113 } |
114 baseType x, y; | 114 baseType x, y; |
115 }; | 115 }; |
116 typedef CFX_PSVTemplate<FX_INT32> CFX_Point; | 116 typedef CFX_PSVTemplate<FX_INT32> CFX_Point; |
117 typedef CFX_PSVTemplate<FX_FLOAT> CFX_PointF; | 117 typedef CFX_PSVTemplate<FX_FLOAT> CFX_PointF; |
118 typedef CFX_PSVTemplate<FX_INT32> CFX_Size; | 118 typedef CFX_PSVTemplate<FX_INT32> CFX_Size; |
Tom Sepez
2015/04/10 21:33:05
I'm deeply offended by anyone who thinks a size co
| |
119 typedef CFX_PSVTemplate<FX_FLOAT> CFX_SizeF; | 119 typedef CFX_PSVTemplate<FX_FLOAT> CFX_SizeF; |
120 typedef CFX_ArrayTemplate<CFX_Point> CFX_Points; | 120 typedef CFX_ArrayTemplate<CFX_Point> CFX_Points; |
121 typedef CFX_ArrayTemplate<CFX_PointF> CFX_PointsF; | 121 typedef CFX_ArrayTemplate<CFX_PointF> CFX_PointsF; |
122 typedef CFX_PSVTemplate<FX_INT32> * FX_LPPOINT; | 122 typedef CFX_PSVTemplate<FX_INT32> * FX_LPPOINT; |
Tom Sepez
2015/04/10 21:33:05
can we use the typdef's above here to save some ty
| |
123 typedef CFX_PSVTemplate<FX_FLOAT> * FX_LPPOINTF; | 123 typedef CFX_PSVTemplate<FX_FLOAT> * FX_LPPOINTF; |
124 typedef CFX_PSVTemplate<FX_INT32> const * FX_LPCPOINT; | 124 typedef CFX_PSVTemplate<FX_INT32> const * FX_LPCPOINT; |
125 typedef CFX_PSVTemplate<FX_FLOAT> const * FX_LPCPOINTF; | 125 typedef CFX_PSVTemplate<FX_FLOAT> const * FX_LPCPOINTF; |
126 #define CFX_FloatPoint CFX_PointF | 126 #define CFX_FloatPoint CFX_PointF |
Tom Sepez
2015/04/10 21:33:05
should be typedef.
| |
127 template<class baseType> | 127 template<class baseType> |
Tom Sepez
2015/04/10 21:33:04
probably should be typename baseType, since we ins
| |
128 class CFX_VTemplate: public CFX_PSVTemplate<baseType> | 128 class CFX_VTemplate: public CFX_PSVTemplate<baseType> |
129 { | 129 { |
130 public: | 130 public: |
131 typedef CFX_PSVTemplate<baseType> FXT_PSV; | 131 typedef CFX_PSVTemplate<baseType> FXT_PSV; |
132 typedef CFX_PSVTemplate<baseType> FXT_POINT; | 132 typedef CFX_PSVTemplate<baseType> FXT_POINT; |
Tom Sepez
2015/04/10 21:33:05
nit: this types are shadows?
| |
133 typedef CFX_PSVTemplate<baseType> FXT_SIZE; | 133 typedef CFX_PSVTemplate<baseType> FXT_SIZE; |
134 typedef CFX_VTemplate<baseType> FXT_VECTOR; | 134 typedef CFX_VTemplate<baseType> FXT_VECTOR; |
135 void» » Set(baseType x, baseType y) | 135 void» » Set(baseType newx, baseType newy) |
Tom Sepez
2015/04/10 21:00:04
why do we even need this method? Isn't there one
brucedawson
2015/04/10 21:29:50
A quick check shows that it is needed. fpdf_text_i
| |
136 { | 136 { |
137 FXT_PSV::x = x, FXT_PSV::y = y; | 137 FXT_PSV::x = newx, FXT_PSV::y = newy; |
Tom Sepez
2015/04/10 20:36:53
Can we get rid of the FXT_PSV:: qualifiers through
brucedawson
2015/04/10 21:29:50
I started doing that initially, and I'd be happy t
| |
138 } | 138 } |
139 void Set(const FXT_PSV &psv) | 139 void Set(const FXT_PSV &psv) |
140 { | 140 { |
141 FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; | 141 FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; |
142 } | 142 } |
143 void Set(const FXT_POINT &p1, const FXT_POINT &p2) | 143 void Set(const FXT_POINT &p1, const FXT_POINT &p2) |
144 { | 144 { |
145 FXT_PSV::x = p2.x - p1.x, FXT_PSV::y = p2.y - p1.y; | 145 FXT_PSV::x = p2.x - p1.x, FXT_PSV::y = p2.y - p1.y; |
146 } | 146 } |
147 void Reset() | 147 void Reset() |
(...skipping 10 matching lines...) Expand all Loading... | |
158 } | 158 } |
159 void Normalize() | 159 void Normalize() |
160 { | 160 { |
161 FX_FLOAT fLen = FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PS V::y); | 161 FX_FLOAT fLen = FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PS V::y); |
162 if (fLen < 0.0001f) { | 162 if (fLen < 0.0001f) { |
163 return; | 163 return; |
164 } | 164 } |
165 FXT_PSV::x = ((baseType)FXT_PSV::x) / fLen; | 165 FXT_PSV::x = ((baseType)FXT_PSV::x) / fLen; |
166 FXT_PSV::y = ((baseType)FXT_PSV::y) / fLen; | 166 FXT_PSV::y = ((baseType)FXT_PSV::y) / fLen; |
167 } | 167 } |
168 baseType» DotProduct(baseType x, baseType y) const | 168 baseType» DotProduct(baseType otherx, baseType othery) const |
169 { | 169 { |
170 return FXT_PSV::x * x + FXT_PSV::y * y; | 170 return FXT_PSV::x * otherx + FXT_PSV::y * othery; |
171 } | 171 } |
172 baseType DotProduct(const FXT_VECTOR &v) const | 172 baseType DotProduct(const FXT_VECTOR &v) const |
173 { | 173 { |
174 return FXT_PSV::x * v.x + FXT_PSV::y * v.y; | 174 return FXT_PSV::x * v.x + FXT_PSV::y * v.y; |
175 } | 175 } |
176 FX_BOOL» » IsParallel(baseType x, baseType y) const | 176 FX_BOOL» » IsParallel(baseType otherx, baseType othery) const |
177 { | 177 { |
178 baseType t = FXT_PSV::x * y - FXT_PSV::y * x; | 178 baseType t = FXT_PSV::x * othery - FXT_PSV::y * otherx; |
179 return FXSYS_fabs(t) < 0x0001f; | 179 return FXSYS_fabs(t) < 0x0001f; |
180 } | 180 } |
181 FX_BOOL IsParallel(const FXT_VECTOR &v) const | 181 FX_BOOL IsParallel(const FXT_VECTOR &v) const |
182 { | 182 { |
183 return IsParallel(v.x, v.y); | 183 return IsParallel(v.x, v.y); |
184 } | 184 } |
185 FX_BOOL» » IsPerpendicular(baseType x, baseType y) const | 185 FX_BOOL» » IsPerpendicular(baseType otherx, baseType othery) const |
186 { | 186 { |
187 baseType t = DotProduct(x, y); | 187 baseType t = DotProduct(otherx, othery); |
188 return FXSYS_fabs(t) < 0x0001f; | 188 return FXSYS_fabs(t) < 0x0001f; |
189 } | 189 } |
190 FX_BOOL IsPerpendicular(const FXT_VECTOR &v) const | 190 FX_BOOL IsPerpendicular(const FXT_VECTOR &v) const |
191 { | 191 { |
192 return IsPerpendicular(v.x, v.y); | 192 return IsPerpendicular(v.x, v.y); |
193 } | 193 } |
194 void Translate(baseType dx, baseType dy) | 194 void Translate(baseType dx, baseType dy) |
195 { | 195 { |
196 FXT_PSV::x += dx, FXT_PSV::y += dy; | 196 FXT_PSV::x += dx, FXT_PSV::y += dy; |
197 } | 197 } |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 FXT_RECT rect = rt; | 505 FXT_RECT rect = rt; |
506 rect.Intersect(*this); | 506 rect.Intersect(*this); |
507 return !rect.IsEmpty(); | 507 return !rect.IsEmpty(); |
508 } | 508 } |
509 FX_BOOL IntersectWith(const FXT_RECT &rt, FX_FLOAT fEpsilon) con st | 509 FX_BOOL IntersectWith(const FXT_RECT &rt, FX_FLOAT fEpsilon) con st |
510 { | 510 { |
511 FXT_RECT rect = rt; | 511 FXT_RECT rect = rt; |
512 rect.Intersect(*this); | 512 rect.Intersect(*this); |
513 return !rect.IsEmpty(fEpsilon); | 513 return !rect.IsEmpty(fEpsilon); |
514 } | 514 } |
515 friend FX_BOOL operator == (const FXT_RECT &rc1, const FXT_RECT &rc2) | 515 friend FX_BOOL operator == (const FXT_RECT &rc1, const FXT_RECT &rc2) |
Tom Sepez
2015/04/10 21:33:05
ditto on friend.
| |
516 { | 516 { |
517 return rc1.left == rc2.left && rc1.top == rc2.top && rc1.width == rc2.wi dth && rc1.height == rc2.height; | 517 return rc1.left == rc2.left && rc1.top == rc2.top && rc1.width == rc2.wi dth && rc1.height == rc2.height; |
518 } | 518 } |
519 friend FX_BOOL operator != (const FXT_RECT &rc1, const FXT_RECT &rc2) | 519 friend FX_BOOL operator != (const FXT_RECT &rc1, const FXT_RECT &rc2) |
520 { | 520 { |
521 return rc1.left != rc2.left || rc1.top != rc2.top || rc1.width != rc2.wi dth || rc1.height != rc2.height; | 521 return rc1.left != rc2.left || rc1.top != rc2.top || rc1.width != rc2.wi dth || rc1.height != rc2.height; |
522 } | 522 } |
523 baseType left, top; | 523 baseType left, top; |
524 baseType width, height; | 524 baseType width, height; |
525 }; | 525 }; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 struct FX_SMALL_RECT { | 602 struct FX_SMALL_RECT { |
603 | 603 |
604 FX_SHORT Left; | 604 FX_SHORT Left; |
605 | 605 |
606 FX_SHORT Top; | 606 FX_SHORT Top; |
607 | 607 |
608 FX_SHORT Right; | 608 FX_SHORT Right; |
609 | 609 |
610 FX_SHORT Bottom; | 610 FX_SHORT Bottom; |
611 }; | 611 }; |
612 class CFX_FloatRect : public CFX_Object | 612 class CFX_FloatRect : public CFX_Object |
Tom Sepez
2015/04/10 21:33:05
And yet this isn't a template.
| |
613 { | 613 { |
614 public: | 614 public: |
615 | 615 |
616 CFX_FloatRect() | 616 CFX_FloatRect() |
617 { | 617 { |
618 left = right = bottom = top = 0; | 618 left = right = bottom = top = 0; |
619 } | 619 } |
620 | 620 |
621 CFX_FloatRect(FX_FLOAT left1, FX_FLOAT bottom1, FX_FLOAT right1, FX_FLOAT to p1) | 621 CFX_FloatRect(FX_FLOAT left1, FX_FLOAT bottom1, FX_FLOAT right1, FX_FLOAT to p1) |
622 { | 622 { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 void TransformRect(CFX_RectF &rect) const; | 857 void TransformRect(CFX_RectF &rect) const; |
858 void TransformRect(CFX_Rect &rect) const; | 858 void TransformRect(CFX_Rect &rect) const; |
859 | 859 |
860 void TransformRect(FX_FLOAT& left, FX_FLOAT& right, F X_FLOAT& top, FX_FLOAT& bottom) const; | 860 void TransformRect(FX_FLOAT& left, FX_FLOAT& right, F X_FLOAT& top, FX_FLOAT& bottom) const; |
861 | 861 |
862 void TransformRect(CFX_FloatRect& rect) const | 862 void TransformRect(CFX_FloatRect& rect) const |
863 { | 863 { |
864 TransformRect(rect.left, rect.right, rect.top, rect.bottom); | 864 TransformRect(rect.left, rect.right, rect.top, rect.bottom); |
865 } | 865 } |
866 | 866 |
867 FX_FLOAT GetA() const | 867 FX_FLOAT GetA() const |
Tom Sepez
2015/04/10 21:33:05
|a| is public and we don't need this, or make |a|
| |
868 { | 868 { |
869 return a; | 869 return a; |
870 } | 870 } |
871 | 871 |
872 FX_FLOAT GetB() const | 872 FX_FLOAT GetB() const |
873 { | 873 { |
874 return b; | 874 return b; |
875 } | 875 } |
876 | 876 |
877 FX_FLOAT GetC() const | 877 FX_FLOAT GetC() const |
(...skipping 16 matching lines...) Expand all Loading... | |
894 return f; | 894 return f; |
895 } | 895 } |
896 public: | 896 public: |
897 FX_FLOAT a; | 897 FX_FLOAT a; |
898 FX_FLOAT b; | 898 FX_FLOAT b; |
899 FX_FLOAT c; | 899 FX_FLOAT c; |
900 FX_FLOAT d; | 900 FX_FLOAT d; |
901 FX_FLOAT e; | 901 FX_FLOAT e; |
902 FX_FLOAT f; | 902 FX_FLOAT f; |
903 }; | 903 }; |
904 #define CFX_AffineMatrix CFX_Matrix | 904 #define CFX_AffineMatrix CFX_Matrix |
Tom Sepez
2015/04/10 21:33:05
typedef.
| |
905 #endif | 905 #endif |
OLD | NEW |