| Flutter Linux 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
10 namespace flutter {
11
12 // A point in Cartesian space relative to a separately-maintained origin.
13 class Point {
14 public:
15 Point() = default;
16 Point(double x, double y) : x_(x), y_(y) {}
17 Point(const Point& point) = default;
18 Point& operator=(const Point& other) = default;
19
20 double x() const { return x_; }
21 double y() const { return y_; }
22
23 bool operator==(const Point& other) const {
24 return x_ == other.x_ && y_ == other.y_;
25 }
26
27 private:
28 double x_ = 0.0;
29 double y_ = 0.0;
30 };
31
32 // A 2D floating-point size with non-negative dimensions.
33 class Size {
34 public:
35 Size() = default;
36 Size(double width, double height)
37 : width_(std::fmax(0.0, width)), height_(std::fmax(0.0, height)) {}
38
39 Size(const Size& size) = default;
40 Size& operator=(const Size& other) = default;
41
42 double width() const { return width_; }
43 double height() const { return height_; }
44
45 bool operator==(const Size& other) const {
46 return width_ == other.width_ && height_ == other.height_;
47 }
48
49 private:
50 double width_ = 0.0;
51 double height_ = 0.0;
52 };
53
54 // A rectangle with position in Cartesian space specified relative to a
55 // separately-maintained origin.
56 class Rect {
57 public:
58 Rect() = default;
59 Rect(const Point& origin, const Size& size) : origin_(origin), size_(size) {}
60 Rect(const Rect& rect) = default;
61 Rect& operator=(const Rect& other) = default;
62
63 double left() const { return origin_.x(); }
64 double top() const { return origin_.y(); }
65 double right() const { return origin_.x() + size_.width(); }
66 double bottom() const { return origin_.y() + size_.height(); }
67 double width() const { return size_.width(); }
68 double height() const { return size_.height(); }
69 Point origin() const { return origin_; }
70 Size size() const { return size_; }
71
72 bool operator==(const Rect& other) const {
73 return origin_ == other.origin_ && size_ == other.size_;
74 }
75
76 private:
77 Point origin_;
78 Size size_;
79 };
80
81 } // namespace flutter
82
83 #endif // FLUTTER_SHELL_PLATFORM_COMMON_GEOMETRY_H_
flutter::Point
Definition: geometry.h:13
flutter::Point::Point
Point()=default
flutter::Point::operator==
bool operator==(const Point &other) const
Definition: geometry.h:23
flutter::Point::operator=
Point & operator=(const Point &other)=default
flutter::Point::Point
Point(double x, double y)
Definition: geometry.h:16
flutter::Point::x
double x() const
Definition: geometry.h:20
flutter::Point::y
double y() const
Definition: geometry.h:21
flutter::Point::Point
Point(const Point &point)=default
flutter::Rect
Definition: geometry.h:56
flutter::Rect::bottom
double bottom() const
Definition: geometry.h:66
flutter::Rect::right
double right() const
Definition: geometry.h:65
flutter::Rect::top
double top() const
Definition: geometry.h:64
flutter::Rect::size
Size size() const
Definition: geometry.h:70
flutter::Rect::height
double height() const
Definition: geometry.h:68
flutter::Rect::left
double left() const
Definition: geometry.h:63
flutter::Rect::Rect
Rect(const Point &origin, const Size &size)
Definition: geometry.h:59
flutter::Rect::origin
Point origin() const
Definition: geometry.h:69
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:67
flutter::Rect::Rect
Rect()=default
flutter::Rect::operator==
bool operator==(const Rect &other) const
Definition: geometry.h:72
flutter::Size
Definition: geometry.h:33
flutter::Size::Size
Size(const Size &size)=default
flutter::Size::Size
Size()=default
flutter::Size::Size
Size(double width, double height)
Definition: geometry.h:36
flutter::Size::height
double height() const
Definition: geometry.h:43
flutter::Size::operator==
bool operator==(const Size &other) const
Definition: geometry.h:45
flutter::Size::operator=
Size & operator=(const Size &other)=default
flutter::Size::width
double width() const
Definition: geometry.h:42
flutter
Definition: accessibility_bridge.cc:14