| Flutter Windows Embedder |

geometry.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_GEOMETRY_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_GEOMETRY_H_
7
8 #include <cmath>
9 #include <limits>
10 #include <optional>
11
12 namespace flutter {
13
14 // A point in Cartesian space relative to a separately-maintained origin.
15 class Point {
16 public:
17 Point() = default;
18 Point(double x, double y) : x_(x), y_(y) {}
19 Point(const Point& point) = default;
20 Point& operator=(const Point& other) = default;
21
22 double x() const { return x_; }
23 double y() const { return y_; }
24
25 bool operator==(const Point& other) const {
26 return x_ == other.x_ && y_ == other.y_;
27 }
28
29 private:
30 double x_ = 0.0;
31 double y_ = 0.0;
32 };
33
34 // A 2D floating-point size with non-negative dimensions.
35 class Size {
36 public:
37 Size() = default;
38 Size(double width, double height)
39 : width_(std::fmax(0.0, width)), height_(std::fmax(0.0, height)) {}
40
41 Size(const Size& size) = default;
42 Size& operator=(const Size& other) = default;
43
44 double width() const { return width_; }
45 double height() const { return height_; }
46
47 bool operator==(const Size& other) const {
48 return width_ == other.width_ && height_ == other.height_;
49 }
50 bool operator!=(const Size& other) const { return !(*this == other); }
51
52 private:
53 double width_ = 0.0;
54 double height_ = 0.0;
55 };
56
57 // A rectangle with position in Cartesian space specified relative to a
58 // separately-maintained origin.
59 class Rect {
60 public:
61 Rect() = default;
62 Rect(const Point& origin, const Size& size) : origin_(origin), size_(size) {}
63 Rect(const Rect& rect) = default;
64 Rect& operator=(const Rect& other) = default;
65
66 double left() const { return origin_.x(); }
67 double top() const { return origin_.y(); }
68 double right() const { return origin_.x() + size_.width(); }
69 double bottom() const { return origin_.y() + size_.height(); }
70 double width() const { return size_.width(); }
71 double height() const { return size_.height(); }
72 Point origin() const { return origin_; }
73 Size size() const { return size_; }
74
75 bool operator==(const Rect& other) const {
76 return origin_ == other.origin_ && size_ == other.size_;
77 }
78
79 private:
80 Point origin_;
81 Size size_;
82 };
83
84 // Encapsulates a min and max size that represents the constraints that some
85 // arbitrary box is able to take up.
86 class BoxConstraints {
87 public:
88 BoxConstraints() = default;
89 BoxConstraints(const std::optional<Size>& smallest,
90 const std::optional<Size>& biggest)
91 : smallest_(smallest.value_or(Size(0, 0))),
92 biggest_(
93 biggest.value_or(Size(std::numeric_limits<double>::infinity(),
94 std::numeric_limits<double>::infinity()))) {}
95 BoxConstraints(const BoxConstraints& other) = default;
96 Size biggest() const { return biggest_; }
97 Size smallest() const { return smallest_; }
98
99 private:
100 Size smallest_ = Size(0, 0);
101 Size biggest_ = Size(std::numeric_limits<double>::infinity(),
102 std::numeric_limits<double>::infinity());
103 };
104
105 } // namespace flutter
106
107 #endif // FLUTTER_SHELL_PLATFORM_COMMON_GEOMETRY_H_
flutter::BoxConstraints
Definition: geometry.h:86
flutter::BoxConstraints::BoxConstraints
BoxConstraints(const BoxConstraints &other)=default
flutter::BoxConstraints::BoxConstraints
BoxConstraints(const std::optional< Size > &smallest, const std::optional< Size > &biggest)
Definition: geometry.h:89
flutter::BoxConstraints::smallest
Size smallest() const
Definition: geometry.h:97
flutter::BoxConstraints::BoxConstraints
BoxConstraints()=default
flutter::BoxConstraints::biggest
Size biggest() const
Definition: geometry.h:96
flutter::Point
Definition: geometry.h:15
flutter::Point::Point
Point()=default
flutter::Point::operator==
bool operator==(const Point &other) const
Definition: geometry.h:25
flutter::Point::operator=
Point & operator=(const Point &other)=default
flutter::Point::Point
Point(double x, double y)
Definition: geometry.h:18
flutter::Point::x
double x() const
Definition: geometry.h:22
flutter::Point::y
double y() const
Definition: geometry.h:23
flutter::Point::Point
Point(const Point &point)=default
flutter::Rect
Definition: geometry.h:59
flutter::Rect::bottom
double bottom() const
Definition: geometry.h:69
flutter::Rect::right
double right() const
Definition: geometry.h:68
flutter::Rect::top
double top() const
Definition: geometry.h:67
flutter::Rect::size
Size size() const
Definition: geometry.h:73
flutter::Rect::height
double height() const
Definition: geometry.h:71
flutter::Rect::left
double left() const
Definition: geometry.h:66
flutter::Rect::Rect
Rect(const Point &origin, const Size &size)
Definition: geometry.h:62
flutter::Rect::origin
Point origin() const
Definition: geometry.h:72
flutter::Rect::operator=
Rect & operator=(const Rect &other)=default
flutter::Rect::Rect
Rect(const Rect &rect)=default
flutter::Rect::width
double width() const
Definition: geometry.h:70
flutter::Rect::Rect
Rect()=default
flutter::Rect::operator==
bool operator==(const Rect &other) const
Definition: geometry.h:75
flutter::Size
Definition: geometry.h:35
flutter::Size::Size
Size(const Size &size)=default
flutter::Size::Size
Size()=default
flutter::Size::operator!=
bool operator!=(const Size &other) const
Definition: geometry.h:50
flutter::Size::Size
Size(double width, double height)
Definition: geometry.h:38
flutter::Size::height
double height() const
Definition: geometry.h:45
flutter::Size::operator==
bool operator==(const Size &other) const
Definition: geometry.h:47
flutter::Size::operator=
Size & operator=(const Size &other)=default
flutter::Size::width
double width() const
Definition: geometry.h:44
flutter
Definition: accessibility_bridge_windows.cc:11