summaryrefslogtreecommitdiff
path: root/core/include/fxcrt
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-02-29 11:24:29 -0800
committerTom Sepez <tsepez@chromium.org>2016-02-29 11:24:29 -0800
commitd5e7b355b8c4c22ff770547797cbc536bdc95d5b (patch)
tree4c0607b1701f23753a71b42c02b74764dd4bfd38 /core/include/fxcrt
parenta74e9c9d3b0d98c5d6042d7ca739cd921a4524db (diff)
downloadpdfium-d5e7b355b8c4c22ff770547797cbc536bdc95d5b.tar.xz
Fixup FX_RECT and FX_SMALL_RECT classes.
Put these first, so later on more complicated classes can have constructors that take these as arguments. Add better constructors, and call appropriately. Also don't be afraid to return these from methods since RVO. R=dsinclair@chromium.org Review URL: https://codereview.chromium.org/1745683002 .
Diffstat (limited to 'core/include/fxcrt')
-rw-r--r--core/include/fxcrt/fx_coordinates.h378
1 files changed, 187 insertions, 191 deletions
diff --git a/core/include/fxcrt/fx_coordinates.h b/core/include/fxcrt/fx_coordinates.h
index c6bf230014..e2800ffdb0 100644
--- a/core/include/fxcrt/fx_coordinates.h
+++ b/core/include/fxcrt/fx_coordinates.h
@@ -120,6 +120,193 @@ class CFX_VTemplate : public CFX_PSTemplate<BaseType> {
typedef CFX_VTemplate<int32_t> CFX_Vector;
typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF;
+// Rectangles.
+// TODO(tsepez): Consolidate all these different rectangle classes.
+
+// LTRB rectangles (y-axis runs downwards).
+struct FX_SMALL_RECT {
+ FX_SMALL_RECT() : FX_SMALL_RECT(kInvalid, kInvalid, kInvalid, kInvalid) {}
+
+ FX_SMALL_RECT(int16_t l, int16_t t, int16_t r, int16_t b)
+ : left(l), top(t), right(r), bottom(b) {}
+
+ static const int16_t kInvalid = -1;
+
+ int16_t left;
+ int16_t top;
+ int16_t right;
+ int16_t bottom;
+};
+
+struct FX_RECT {
+ FX_RECT() : left(0), top(0), right(0), bottom(0) {}
+
+ FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {}
+
+ explicit FX_RECT(const FX_SMALL_RECT& small)
+ : FX_RECT(small.left, small.top, small.right, small.bottom) {}
+
+ int Width() const { return right - left; }
+ int Height() const { return bottom - top; }
+ bool IsEmpty() const { return right <= left || bottom <= top; }
+
+ void Normalize();
+
+ void Intersect(const FX_RECT& src);
+ void Intersect(int l, int t, int r, int b) { Intersect(FX_RECT(l, t, r, b)); }
+
+ void Union(const FX_RECT& other_rect);
+ void Union(int l, int t, int r, int b) { Union(FX_RECT(l, t, r, b)); }
+
+ void Offset(int dx, int dy) {
+ left += dx;
+ right += dx;
+ top += dy;
+ bottom += dy;
+ }
+
+ bool operator==(const FX_RECT& src) const {
+ return left == src.left && right == src.right && top == src.top &&
+ bottom == src.bottom;
+ }
+
+ FX_BOOL Contains(const FX_RECT& other_rect) const {
+ return other_rect.left >= left && other_rect.right <= right &&
+ other_rect.top >= top && other_rect.bottom <= bottom;
+ }
+
+ FX_BOOL Contains(int x, int y) const {
+ return x >= left && x < right && y >= top && y < bottom;
+ }
+
+ FX_SMALL_RECT ToSmallRect() const {
+ return FX_SMALL_RECT(
+ static_cast<uint16_t>(left), static_cast<uint16_t>(top),
+ static_cast<uint16_t>(right), static_cast<uint16_t>(bottom));
+ }
+
+ int left;
+ int top;
+ int right;
+ int bottom;
+};
+
+// LBRT rectangles (y-axis runs upwards).
+class CFX_FloatPoint {
+ public:
+ CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {}
+
+ FX_FLOAT x;
+ FX_FLOAT y;
+};
+
+class CFX_FloatRect {
+ public:
+ CFX_FloatRect() : CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f) {}
+ CFX_FloatRect(FX_FLOAT l, FX_FLOAT b, FX_FLOAT r, FX_FLOAT t)
+ : left(l), bottom(b), right(r), top(t) {}
+
+ explicit CFX_FloatRect(const FX_FLOAT* pArray)
+ : CFX_FloatRect(pArray[0], pArray[1], pArray[2], pArray[3]) {}
+
+ explicit CFX_FloatRect(const FX_RECT& rect);
+
+ void Normalize();
+
+ void Reset() {
+ left = 0.0f;
+ right = 0.0f;
+ bottom = 0.0f;
+ top = 0.0f;
+ }
+
+ FX_BOOL IsEmpty() const { return left >= right || bottom >= top; }
+ FX_BOOL Contains(const CFX_FloatRect& other_rect) const;
+ FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const;
+
+ void Transform(const CFX_Matrix* pMatrix);
+ void Intersect(const CFX_FloatRect& other_rect);
+ void Union(const CFX_FloatRect& other_rect);
+
+ FX_RECT GetInnerRect() const;
+ FX_RECT GetOutterRect() const;
+ FX_RECT GetClosestRect() const;
+
+ int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects);
+
+ void InitRect(FX_FLOAT x, FX_FLOAT y) {
+ left = x;
+ right = x;
+ bottom = y;
+ top = y;
+ }
+ void UpdateRect(FX_FLOAT x, FX_FLOAT y);
+
+ FX_FLOAT Width() const { return right - left; }
+ FX_FLOAT Height() const { return top - bottom; }
+
+ void Inflate(FX_FLOAT x, FX_FLOAT y) {
+ Normalize();
+ left -= x;
+ right += x;
+ bottom -= y;
+ top += y;
+ }
+
+ void Inflate(FX_FLOAT other_left,
+ FX_FLOAT other_bottom,
+ FX_FLOAT other_right,
+ FX_FLOAT other_top) {
+ Normalize();
+ left -= other_left;
+ bottom -= other_bottom;
+ right += other_right;
+ top += other_top;
+ }
+
+ void Inflate(const CFX_FloatRect& rt) {
+ Inflate(rt.left, rt.bottom, rt.right, rt.top);
+ }
+
+ void Deflate(FX_FLOAT x, FX_FLOAT y) {
+ Normalize();
+ left += x;
+ right -= x;
+ bottom += y;
+ top -= y;
+ }
+
+ void Deflate(FX_FLOAT other_left,
+ FX_FLOAT other_bottom,
+ FX_FLOAT other_right,
+ FX_FLOAT other_top) {
+ Normalize();
+ left += other_left;
+ bottom += other_bottom;
+ right -= other_right;
+ top -= other_top;
+ }
+
+ void Deflate(const CFX_FloatRect& rt) {
+ Deflate(rt.left, rt.bottom, rt.right, rt.top);
+ }
+
+ void Translate(FX_FLOAT e, FX_FLOAT f) {
+ left += e;
+ right += e;
+ top += f;
+ bottom += f;
+ }
+
+ static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints);
+
+ FX_FLOAT left;
+ FX_FLOAT bottom;
+ FX_FLOAT right;
+ FX_FLOAT top;
+};
+
+// LTWH rectangles (y-axis runs downwards).
template <class baseType>
class CFX_RTemplate {
public:
@@ -350,197 +537,6 @@ typedef CFX_RTemplate<FX_FLOAT>* FX_LPRECTF;
typedef CFX_RTemplate<int32_t> const* FX_LPCRECT;
typedef CFX_RTemplate<FX_FLOAT> const* FX_LPCRECTF;
typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray;
-struct FX_RECT {
- int left;
-
- int top;
-
- int right;
-
- int bottom;
-
- FX_RECT() : left(0), top(0), right(0), bottom(0) {}
-
- FX_RECT(int left1, int top1, int right1, int bottom1) {
- left = left1;
- top = top1;
- right = right1;
- bottom = bottom1;
- }
-
- int Width() const { return right - left; }
-
- int Height() const { return bottom - top; }
-
- FX_BOOL IsEmpty() const { return right <= left || bottom <= top; }
-
- void Normalize();
-
- void Intersect(const FX_RECT& src);
-
- void Intersect(int left1, int top1, int right1, int bottom1) {
- Intersect(FX_RECT(left1, top1, right1, bottom1));
- }
-
- void Union(const FX_RECT& other_rect);
-
- bool operator==(const FX_RECT& src) const {
- return left == src.left && right == src.right && top == src.top &&
- bottom == src.bottom;
- }
-
- void Offset(int dx, int dy) {
- left += dx;
- right += dx;
- top += dy;
- bottom += dy;
- }
-
- FX_BOOL Contains(const FX_RECT& other_rect) const {
- return other_rect.left >= left && other_rect.right <= right &&
- other_rect.top >= top && other_rect.bottom <= bottom;
- }
-
- FX_BOOL Contains(int x, int y) const {
- return x >= left && x < right && y >= top && y < bottom;
- }
-};
-struct FX_SMALL_RECT {
- int16_t Left;
-
- int16_t Top;
-
- int16_t Right;
-
- int16_t Bottom;
-};
-
-class CFX_FloatPoint {
- public:
- CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {}
-
- FX_FLOAT x;
- FX_FLOAT y;
-};
-
-class CFX_FloatRect {
- public:
- CFX_FloatRect() { left = right = bottom = top = 0; }
-
- CFX_FloatRect(FX_FLOAT left1,
- FX_FLOAT bottom1,
- FX_FLOAT right1,
- FX_FLOAT top1) {
- left = left1;
- bottom = bottom1;
- right = right1;
- top = top1;
- }
-
- CFX_FloatRect(const FX_FLOAT* pArray) {
- left = pArray[0];
- bottom = pArray[1];
- right = pArray[2];
- top = pArray[3];
- }
-
- CFX_FloatRect(const FX_RECT& rect);
-
- FX_BOOL IsEmpty() const { return left >= right || bottom >= top; }
-
- void Normalize();
-
- void Reset() { left = right = bottom = top = 0; }
-
- FX_BOOL Contains(const CFX_FloatRect& other_rect) const;
-
- FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const;
-
- void Transform(const CFX_Matrix* pMatrix);
-
- void Intersect(const CFX_FloatRect& other_rect);
-
- void Union(const CFX_FloatRect& other_rect);
-
- FX_RECT GetInnerRect() const;
-
- FX_RECT GetOutterRect() const;
-
- FX_RECT GetClosestRect() const;
-
- int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects);
-
- void InitRect(FX_FLOAT x, FX_FLOAT y) {
- left = right = x;
- bottom = top = y;
- }
-
- void UpdateRect(FX_FLOAT x, FX_FLOAT y);
-
- FX_FLOAT Width() const { return right - left; }
-
- FX_FLOAT Height() const { return top - bottom; }
-
- void Inflate(FX_FLOAT x, FX_FLOAT y) {
- Normalize();
- left -= x;
- right += x;
- bottom -= y;
- top += y;
- }
-
- void Inflate(FX_FLOAT other_left,
- FX_FLOAT other_bottom,
- FX_FLOAT other_right,
- FX_FLOAT other_top) {
- Normalize();
- left -= other_left;
- bottom -= other_bottom;
- right += other_right;
- top += other_top;
- }
-
- void Inflate(const CFX_FloatRect& rt) {
- Inflate(rt.left, rt.bottom, rt.right, rt.top);
- }
-
- void Deflate(FX_FLOAT x, FX_FLOAT y) {
- Normalize();
- left += x;
- right -= x;
- bottom += y;
- top -= y;
- }
-
- void Deflate(FX_FLOAT other_left,
- FX_FLOAT other_bottom,
- FX_FLOAT other_right,
- FX_FLOAT other_top) {
- Normalize();
- left += other_left;
- bottom += other_bottom;
- right -= other_right;
- top -= other_top;
- }
-
- void Deflate(const CFX_FloatRect& rt) {
- Deflate(rt.left, rt.bottom, rt.right, rt.top);
- }
-
- void Translate(FX_FLOAT e, FX_FLOAT f) {
- left += e;
- right += e;
- top += f;
- bottom += f;
- }
-
- 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: