Flutter Engine
The Flutter Engine
rect_conversions.cc
Go to the documentation of this file.
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "rect_conversions.h"
6
7#include <algorithm>
8#include <cmath>
9
10#include "base/logging.h"
12
13namespace gfx {
14
15namespace {
16
17int FloorIgnoringError(float f, float error) {
18 int rounded = base::ClampRound(f);
19 return std::abs(rounded - f) < error ? rounded : base::ClampFloor(f);
20}
21
22int CeilIgnoringError(float f, float error) {
23 int rounded = base::ClampRound(f);
24 return std::abs(rounded - f) < error ? rounded : base::ClampCeil(f);
25}
26
27} // anonymous namespace
28
30 int left = base::ClampFloor(r.x());
31 int right = r.width() ? base::ClampCeil(r.right()) : left;
32 int top = base::ClampFloor(r.y());
33 int bottom = r.height() ? base::ClampCeil(r.bottom()) : top;
34
36 result.SetByBounds(left, top, right, bottom);
37 return result;
38}
39
41 int left = FloorIgnoringError(r.x(), error);
42 int right = r.width() ? CeilIgnoringError(r.right(), error) : left;
43 int top = FloorIgnoringError(r.y(), error);
44 int bottom = r.height() ? CeilIgnoringError(r.bottom(), error) : top;
45
47 result.SetByBounds(left, top, right, bottom);
48 return result;
49}
50
53 result.SetByBounds(base::ClampCeil(rect.x()), base::ClampCeil(rect.y()),
54 base::ClampFloor(rect.right()),
55 base::ClampFloor(rect.bottom()));
56 return result;
57}
58
60 int left = CeilIgnoringError(r.x(), error);
61 int right = r.width() ? FloorIgnoringError(r.right(), error) : left;
62 int top = CeilIgnoringError(r.y(), error);
63 int bottom = r.height() ? FloorIgnoringError(r.bottom(), error) : top;
64
66 result.SetByBounds(left, top, right, bottom);
67 return result;
68}
69
71 float float_min_x = rect.x();
72 float float_min_y = rect.y();
73 float float_max_x = rect.right();
74 float float_max_y = rect.bottom();
75
76 int min_x = base::ClampRound(float_min_x);
77 int min_y = base::ClampRound(float_min_y);
78 int max_x = base::ClampRound(float_max_x);
79 int max_y = base::ClampRound(float_max_y);
80
81 // If these DCHECKs fail, you're using the wrong method, consider using
82 // ToEnclosingRect or ToEnclosedRect instead.
83 BASE_DCHECK(std::abs(min_x - float_min_x) < 0.01f);
84 BASE_DCHECK(std::abs(min_y - float_min_y) < 0.01f);
85 BASE_DCHECK(std::abs(max_x - float_max_x) < 0.01f);
86 BASE_DCHECK(std::abs(max_y - float_max_y) < 0.01f);
87
89 result.SetByBounds(min_x, min_y, max_x, max_y);
90
91 return result;
92}
93
95 float float_min_x = rect.x();
96 float float_min_y = rect.y();
97 float float_max_x = rect.right();
98 float float_max_y = rect.bottom();
99
100 int min_x = base::ClampRound(float_min_x);
101 int min_y = base::ClampRound(float_min_y);
102 int max_x = base::ClampRound(float_max_x);
103 int max_y = base::ClampRound(float_max_y);
104
105 return (std::abs(min_x - float_min_x) < distance) &&
106 (std::abs(min_y - float_min_y) < distance) &&
107 (std::abs(max_x - float_max_x) < distance) &&
108 (std::abs(max_y - float_max_y) < distance);
109}
110
112 int left = base::ClampRound(rect.x());
113 int top = base::ClampRound(rect.y());
114 int right = base::ClampRound(rect.right());
115 int bottom = base::ClampRound(rect.bottom());
117 result.SetByBounds(left, top, right, bottom);
118 return result;
119}
120
123 base::ClampFloor(rect.width()), base::ClampFloor(rect.height()));
124}
125
126} // namespace gfx
constexpr float y() const
Definition: rect_f.h:50
constexpr float width() const
Definition: rect_f.h:53
constexpr float height() const
Definition: rect_f.h:56
constexpr float right() const
Definition: rect_f.h:65
constexpr float bottom() const
Definition: rect_f.h:66
constexpr float x() const
Definition: rect_f.h:47
Definition: rect.h:36
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Dst ClampFloor(Src value)
Dst ClampCeil(Src value)
Dst ClampRound(Src value)
Definition: insets.cc:10
Rect ToEnclosingRectIgnoringError(const RectF &r, float error)
Rect ToEnclosingRect(const RectF &r)
gfx::Rect ToRoundedRect(const gfx::RectF &rect)
bool IsNearestRectWithinDistance(const gfx::RectF &rect, float distance)
Rect ToEnclosedRectIgnoringError(const RectF &r, float error)
Rect ToEnclosedRect(const RectF &rect)
Rect ToFlooredRectDeprecated(const RectF &rect)
Rect ToNearestRect(const RectF &rect)
TRect< Scalar > Rect
Definition: rect.h:769
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition: SkVx.h:707
#define BASE_DCHECK(condition)
Definition: logging.h:63