7#include "core/fxcrt/fx_coordinates.h"
15#include "build/build_config.h"
16#include "core/fxcrt/fx_extension.h"
17#include "core/fxcrt/fx_safe_types.h"
18#include "core/fxcrt/fx_system.h"
26void MatchFloatRange(
float f1,
float f2,
int* i1,
int* i2) {
27 float length = ceilf(f2 - f1);
28 float f1_floor = floorf(f1);
29 float f1_ceil = ceilf(f1);
30 float error1 = f1 - f1_floor + fabsf(f2 - f1_floor - length);
31 float error2 = f1_ceil - f1 + fabsf(f2 - f1_ceil - length);
32 float start = error1 > error2 ? f1_ceil : f1_floor;
33 FX_SAFE_INT32 safe1 = start;
34 FX_SAFE_INT32 safe2 = start + length;
35 if (safe1.IsValid() && safe2.IsValid()) {
36 *i1 = safe1.ValueOrDie();
37 *i2 = safe2.ValueOrDie();
45static_assert(
sizeof(FX_RECT) ==
sizeof(RECT),
"FX_RECT vs. RECT mismatch");
46static_assert(offsetof(FX_RECT, left) == offsetof(RECT, left),
47 "FX_RECT vs. RECT mismatch");
48static_assert(offsetof(FX_RECT, top) == offsetof(RECT, top),
49 "FX_RECT vs. RECT mismatch");
50static_assert(offsetof(FX_RECT, right) == offsetof(RECT, right),
51 "FX_RECT vs. RECT mismatch");
52static_assert(offsetof(FX_RECT, bottom) == offsetof(RECT, bottom),
53 "FX_RECT vs. RECT mismatch");
54static_assert(
sizeof(FX_RECT::left) ==
sizeof(RECT::left),
55 "FX_RECT vs. RECT mismatch");
56static_assert(
sizeof(FX_RECT::top) ==
sizeof(RECT::top),
57 "FX_RECT vs. RECT mismatch");
58static_assert(
sizeof(FX_RECT::right) ==
sizeof(RECT::right),
59 "FX_RECT vs. RECT mismatch");
60static_assert(
sizeof(FX_RECT::bottom) ==
sizeof(RECT::bottom),
61 "FX_RECT vs. RECT mismatch");
67float CFX_VTemplate<
float>::Length()
const {
68 return FXSYS_sqrt2(x, y);
72void CFX_VTemplate<
float>::Normalize() {
73 float fLen = Length();
82 FX_SAFE_INT32 w = right;
83 FX_SAFE_INT32 h = bottom;
86 return w.IsValid() && h.IsValid();
144 float min_x = pPoints.front().x;
145 float max_x = pPoints.front().x;
146 float min_y = pPoints.front().y;
147 float max_y = pPoints.front().y;
148 for (
const auto& point : pPoints.subspan(1)) {
149 min_x = std::min(min_x, point.x);
150 max_x = std::max(max_x, point.x);
151 min_y = std::min(min_y, point.y);
152 max_y = std::max(max_y, point.y);
188 rect
.left = pdfium::base::saturated_cast<
int>(floor(
left));
189 rect
.bottom = pdfium::base::saturated_cast<
int>(ceil(
top));
190 rect
.right = pdfium::base::saturated_cast<
int>(ceil(
right));
191 rect
.top = pdfium::base::saturated_cast<
int>(floor(
bottom));
198 rect
.left = pdfium::base::saturated_cast<
int>(ceil(
left));
199 rect
.bottom = pdfium::base::saturated_cast<
int>(floor(
top));
200 rect
.right = pdfium::base::saturated_cast<
int>(floor(
right));
201 rect
.top = pdfium::base::saturated_cast<
int>(ceil(
bottom));
217 float fHalfWidth = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2;
222 fCenterX + fHalfWidth
, fCenterY + fHalfWidth
);
228 return point.x <= n1
.right && point.x >= n1
.left && point.y <= n1
.top &&
259 right += other_right;
275 Inflate(-other_left
, -other_bottom
, -other_right
, -other_top
);
307 float fHalfWidth = (
right -
left) / 2.0f;
308 float fHalfHeight = (
top -
bottom) / 2.0f;
313 left = center_x - fHalfWidth * fScale;
314 bottom = center_y - fHalfHeight * fScale;
315 right = center_x + fHalfWidth * fScale;
316 top = center_y + fHalfHeight * fScale;
370 static_cast<int32_t>(floor(
top))
,
371 static_cast<int32_t>(ceil(
right()))
,
384 << rect
.left <<
", top " << rect
.top <<
")]";
391 float i =
a *
d -
b *
c;
400 inverse
.e = (
c *
f -
d *
e) / i;
401 inverse
.f = (
a *
f -
b *
e) / j;
406 return fabs(
a * 1000) < fabs(
b) && fabs(
d * 1000) < fabs(
c);
410 return fabs(
b * 1000) < fabs(
a) && fabs(
c * 1000) < fabs(
d);
433 float cosValue = cos(fRadian);
434 float sinValue = sin(fRadian);
441 a = fabs(fDiff) < 0.001f ? 1 : (dest
.left - dest
.right) / fDiff;
444 d = fabs(fDiff) < 0.001f ? 1 : (dest
.bottom - dest
.top) / fDiff;
453 return (
a > 0 ?
a : -
a);
455 return (
b > 0 ?
b : -
b);
461 return (
d > 0 ?
d : -
d);
463 return (
c > 0 ?
c : -
c);
482 return CFX_PointF(
a * point.x +
c * point.y +
e,
483 b * point.x +
d * point.y +
f);
493 CFX_PointF points[] = {{rect.left, rect.top},
494 {rect.left, rect.bottom},
495 {rect.right, rect.top},
496 {rect.right, rect.bottom}};
497 for (CFX_PointF& point : points)
498 point = Transform(point);
500 float new_right = points[0].x;
501 float new_left = points[0].x;
502 float new_top = points[0].y;
503 float new_bottom = points[0].y;
504 for (size_t i = 1; i <
std::size(points); i++) {
505 new_right =
std::max(new_right, points[i].x);
506 new_left =
std::min(new_left, points[i].x);
507 new_top =
std::max(new_top, points[i].y);
508 new_bottom =
std::min(new_bottom, points[i].y);
void Deflate(const CFX_FloatRect &rt)
void Deflate(float other_left, float other_bottom, float other_right, float other_top)
FX_RECT ToRoundedFxRect() const
bool Contains(const CFX_PointF &point) const
CFX_FloatRect(const CFX_FloatRect &that)=default
CFX_FloatRect GetCenterSquare() const
constexpr CFX_FloatRect(float l, float b, float r, float t)
constexpr CFX_FloatRect()=default
FX_RECT GetClosestRect() const
CFX_FloatRect(const FX_RECT &rect)
void UpdateRect(const CFX_PointF &point)
void Intersect(const CFX_FloatRect &other_rect)
void ScaleFromCenterPoint(float fScale)
void Inflate(float x, float y)
FX_RECT GetInnerRect() const
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
void Deflate(float x, float y)
bool Contains(const CFX_FloatRect &other_rect) const
FX_RECT GetOuterRect() const
void Inflate(const CFX_FloatRect &rt)
static CFX_FloatRect GetBBox(pdfium::span< const CFX_PointF > pPoints)
void Translate(float e, float f)
CFX_FloatRect GetDeflated(float x, float y) const
void Inflate(float other_left, float other_bottom, float other_right, float other_top)
void Union(const CFX_FloatRect &other_rect)
CFX_FloatRect(const CFX_PointF &point)
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
float TransformDistance(float distance) const
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
CFX_RectF TransformRect(const CFX_RectF &rect) const
void MatchRect(const CFX_FloatRect &dest, const CFX_FloatRect &src)
CFX_PointF Transform(const CFX_PointF &point) const
CFX_FloatRect GetUnitRect() const
CFX_Matrix GetInverse() const
void TranslatePrepend(float x, float y)
void Rotate(float fRadian)
void Scale(float sx, float sy)
void Translate(float x, float y)
void Concat(const CFX_Matrix &right)
float TransformXDistance(float dx) const
CFX_FloatRect ToFloatRect() const
void Intersect(const CFX_RectF &rt)
FX_RECT GetOuterRect() const
void Union(float x, float y)
constexpr CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
void Union(const CFX_RectF &rt)
int FXSYS_roundf(float f)
float FXSYS_sqrt2(float a, float b)
FX_RECT SwappedClipBox(int width, int height, bool bFlipX, bool bFlipY) const
void Intersect(const FX_RECT &src)
constexpr FX_RECT(int l, int t, int r, int b)