| 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 CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ |
| 8 #define CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ |
| 9 | 9 |
| 10 #include "core/fxcrt/include/fx_basic.h" | 10 #include "core/fxcrt/include/fx_basic.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 y = x * sinValue + y * cosValue; | 117 y = x * sinValue + y * cosValue; |
| 118 } | 118 } |
| 119 }; | 119 }; |
| 120 typedef CFX_VTemplate<int32_t> CFX_Vector; | 120 typedef CFX_VTemplate<int32_t> CFX_Vector; |
| 121 typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; | 121 typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; |
| 122 | 122 |
| 123 // Rectangles. | 123 // Rectangles. |
| 124 // TODO(tsepez): Consolidate all these different rectangle classes. | 124 // TODO(tsepez): Consolidate all these different rectangle classes. |
| 125 | 125 |
| 126 // LTRB rectangles (y-axis runs downwards). | 126 // LTRB rectangles (y-axis runs downwards). |
| 127 struct FX_SMALL_RECT { | |
| 128 FX_SMALL_RECT() : FX_SMALL_RECT(kInvalid, kInvalid, kInvalid, kInvalid) {} | |
| 129 | |
| 130 FX_SMALL_RECT(int16_t l, int16_t t, int16_t r, int16_t b) | |
| 131 : left(l), top(t), right(r), bottom(b) {} | |
| 132 | |
| 133 static const int16_t kInvalid = -1; | |
| 134 | |
| 135 int16_t left; | |
| 136 int16_t top; | |
| 137 int16_t right; | |
| 138 int16_t bottom; | |
| 139 }; | |
| 140 | |
| 141 struct FX_RECT { | 127 struct FX_RECT { |
| 142 FX_RECT() : left(0), top(0), right(0), bottom(0) {} | 128 FX_RECT() : left(0), top(0), right(0), bottom(0) {} |
| 143 | 129 |
| 144 FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {} | 130 FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {} |
| 145 | 131 |
| 146 explicit FX_RECT(const FX_SMALL_RECT& other) | |
| 147 : FX_RECT(other.left, other.top, other.right, other.bottom) {} | |
| 148 | |
| 149 int Width() const { return right - left; } | 132 int Width() const { return right - left; } |
| 150 int Height() const { return bottom - top; } | 133 int Height() const { return bottom - top; } |
| 151 bool IsEmpty() const { return right <= left || bottom <= top; } | 134 bool IsEmpty() const { return right <= left || bottom <= top; } |
| 152 | 135 |
| 153 bool Valid() const { | 136 bool Valid() const { |
| 154 pdfium::base::CheckedNumeric<int> w = right; | 137 pdfium::base::CheckedNumeric<int> w = right; |
| 155 pdfium::base::CheckedNumeric<int> h = bottom; | 138 pdfium::base::CheckedNumeric<int> h = bottom; |
| 156 w -= left; | 139 w -= left; |
| 157 h -= top; | 140 h -= top; |
| 158 return w.IsValid() && h.IsValid(); | 141 return w.IsValid() && h.IsValid(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 171 right += dx; | 154 right += dx; |
| 172 top += dy; | 155 top += dy; |
| 173 bottom += dy; | 156 bottom += dy; |
| 174 } | 157 } |
| 175 | 158 |
| 176 bool operator==(const FX_RECT& src) const { | 159 bool operator==(const FX_RECT& src) const { |
| 177 return left == src.left && right == src.right && top == src.top && | 160 return left == src.left && right == src.right && top == src.top && |
| 178 bottom == src.bottom; | 161 bottom == src.bottom; |
| 179 } | 162 } |
| 180 | 163 |
| 181 FX_BOOL Contains(const FX_RECT& other_rect) const { | 164 bool Contains(const FX_RECT& other_rect) const { |
| 182 return other_rect.left >= left && other_rect.right <= right && | 165 return other_rect.left >= left && other_rect.right <= right && |
| 183 other_rect.top >= top && other_rect.bottom <= bottom; | 166 other_rect.top >= top && other_rect.bottom <= bottom; |
| 184 } | 167 } |
| 185 | 168 |
| 186 FX_BOOL Contains(int x, int y) const { | 169 bool Contains(int x, int y) const { |
| 187 return x >= left && x < right && y >= top && y < bottom; | 170 return x >= left && x < right && y >= top && y < bottom; |
| 188 } | 171 } |
| 189 | 172 |
| 190 FX_SMALL_RECT ToSmallRect() const { | |
| 191 return FX_SMALL_RECT( | |
| 192 static_cast<uint16_t>(left), static_cast<uint16_t>(top), | |
| 193 static_cast<uint16_t>(right), static_cast<uint16_t>(bottom)); | |
| 194 } | |
| 195 | |
| 196 int32_t left; | 173 int32_t left; |
| 197 int32_t top; | 174 int32_t top; |
| 198 int32_t right; | 175 int32_t right; |
| 199 int32_t bottom; | 176 int32_t bottom; |
| 200 }; | 177 }; |
| 201 | 178 |
| 202 // LBRT rectangles (y-axis runs upwards). | 179 // LBRT rectangles (y-axis runs upwards). |
| 203 class CFX_FloatPoint { | 180 class CFX_FloatPoint { |
| 204 public: | 181 public: |
| 205 CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {} | 182 CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {} |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 height -= off_top + off_bottom; | 403 height -= off_top + off_bottom; |
| 427 } | 404 } |
| 428 void Deflate(const FXT_RECT& rt) { | 405 void Deflate(const FXT_RECT& rt) { |
| 429 Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); | 406 Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); |
| 430 } | 407 } |
| 431 FX_BOOL IsEmpty() const { return width <= 0 || height <= 0; } | 408 FX_BOOL IsEmpty() const { return width <= 0 || height <= 0; } |
| 432 FX_BOOL IsEmpty(FX_FLOAT fEpsilon) const { | 409 FX_BOOL IsEmpty(FX_FLOAT fEpsilon) const { |
| 433 return width <= fEpsilon || height <= fEpsilon; | 410 return width <= fEpsilon || height <= fEpsilon; |
| 434 } | 411 } |
| 435 void Empty() { width = height = 0; } | 412 void Empty() { width = height = 0; } |
| 436 FX_BOOL Contains(baseType x, baseType y) const { | 413 bool Contains(baseType x, baseType y) const { |
| 437 return x >= left && x < left + width && y >= top && y < top + height; | 414 return x >= left && x < left + width && y >= top && y < top + height; |
| 438 } | 415 } |
| 439 FX_BOOL Contains(const FXT_POINT& p) const { return Contains(p.x, p.y); } | 416 bool Contains(const FXT_POINT& p) const { return Contains(p.x, p.y); } |
| 440 FX_BOOL Contains(const FXT_RECT& rt) const { | 417 bool Contains(const FXT_RECT& rt) const { |
| 441 return rt.left >= left && rt.right() <= right() && rt.top >= top && | 418 return rt.left >= left && rt.right() <= right() && rt.top >= top && |
| 442 rt.bottom() <= bottom(); | 419 rt.bottom() <= bottom(); |
| 443 } | 420 } |
| 444 baseType Width() const { return width; } | 421 baseType Width() const { return width; } |
| 445 baseType Height() const { return height; } | 422 baseType Height() const { return height; } |
| 446 FXT_SIZE Size() const { | 423 FXT_SIZE Size() const { |
| 447 FXT_SIZE size; | 424 FXT_SIZE size; |
| 448 size.Set(width, height); | 425 size.Set(width, height); |
| 449 return size; | 426 return size; |
| 450 } | 427 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 public: | 662 public: |
| 686 FX_FLOAT a; | 663 FX_FLOAT a; |
| 687 FX_FLOAT b; | 664 FX_FLOAT b; |
| 688 FX_FLOAT c; | 665 FX_FLOAT c; |
| 689 FX_FLOAT d; | 666 FX_FLOAT d; |
| 690 FX_FLOAT e; | 667 FX_FLOAT e; |
| 691 FX_FLOAT f; | 668 FX_FLOAT f; |
| 692 }; | 669 }; |
| 693 | 670 |
| 694 #endif // CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ | 671 #endif // CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ |
| OLD | NEW |