Flutter Engine
 
Loading...
Searching...
No Matches
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_GEOMETRY_GEOMETRY_H_
6#define FLUTTER_SHELL_GEOMETRY_GEOMETRY_H_
7
8#include <cmath>
9#include <limits>
10#include <optional>
11
12namespace flutter {
13
14// A point in Cartesian space relative to a separately-maintained origin.
15class 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.
35class 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 = default;
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.
56class 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// Encapsulates a min and max size that represents the constraints that some
82// arbitrary box is able to take up.
84 public:
85 BoxConstraints() = default;
86 BoxConstraints(const std::optional<Size>& smallest,
87 const std::optional<Size>& biggest)
88 : smallest_(smallest.value_or(Size(0, 0))),
89 biggest_(
90 biggest.value_or(Size(std::numeric_limits<double>::infinity(),
91 std::numeric_limits<double>::infinity()))) {}
92 BoxConstraints(const BoxConstraints& other) = default;
93 Size biggest() const { return biggest_; }
94 Size smallest() const { return smallest_; }
95
97 return smallest().width() <= size.width() &&
98 size.width() <= biggest().width() &&
99 smallest().height() <= size.height() &&
100 size.height() <= biggest().height();
101 }
102
103 private:
104 Size smallest_ = Size(0, 0);
105 Size biggest_ = Size(std::numeric_limits<double>::infinity(),
106 std::numeric_limits<double>::infinity());
107};
108
109} // namespace flutter
110
111#endif // FLUTTER_SHELL_GEOMETRY_GEOMETRY_H_
BoxConstraints(const BoxConstraints &other)=default
BoxConstraints(const std::optional< Size > &smallest, const std::optional< Size > &biggest)
Definition geometry.h:86
bool IsSatisfiedBy(Size size)
Definition geometry.h:96
Size smallest() const
Definition geometry.h:94
Size biggest() const
Definition geometry.h:93
Point()=default
bool operator==(const Point &other) const
Definition geometry.h:25
Point & operator=(const Point &other)=default
Point(double x, double y)
Definition geometry.h:18
double x() const
Definition geometry.h:22
double y() const
Definition geometry.h:23
Point(const Point &point)=default
double bottom() const
Definition geometry.h:66
double right() const
Definition geometry.h:65
double top() const
Definition geometry.h:64
Rect & operator=(const Rect &other)=default
Size size() const
Definition geometry.h:70
double height() const
Definition geometry.h:68
double left() const
Definition geometry.h:63
Rect(const Point &origin, const Size &size)
Definition geometry.h:59
Point origin() const
Definition geometry.h:69
Rect(const Rect &rect)=default
double width() const
Definition geometry.h:67
Rect()=default
bool operator==(const Rect &other) const
Definition geometry.h:72
bool operator==(const Size &other) const =default
Size(const Size &size)=default
Size()=default
Size(double width, double height)
Definition geometry.h:38
double height() const
Definition geometry.h:45
Size & operator=(const Size &other)=default
double width() const
Definition geometry.h:44
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition ref_ptr.h:261