| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::LineGeometry Class Referencefinal

`#include <line_geometry.h>`

Inheritance diagram for impeller::LineGeometry:

## Public Member Functions
| LineGeometry (Point p0, Point p1, const StrokeParameters &stroke)
| ~LineGeometry () override
bool | CoversArea (const Matrix &transform, const Rect &rect) const override
| Determines if this geometry, transformed by the given `transform`, will completely cover all surface area of the given `rect`. More...
bool | IsAxisAlignedRect () const override
Scalar | ComputeAlphaCoverage (const Matrix &transform) const override
std::optional< Rect > | GetCoverage (const Matrix &transform) const override
Point | GetP0 () const
Point | GetP1 () const
Scalar | GetWidth () const
Cap | GetCap () const
Public Member Functions inherited from impeller::Geometry
virtual | ~Geometry ()
virtual GeometryResult::Mode | GetResultMode () const
virtual bool | CanApplyMaskFilter () const

## Static Public Member Functions
static Scalar | ComputePixelHalfWidth (const Matrix &transform, Scalar width)
static Vector2 | ComputeAlongVector (const Matrix &transform, bool allow_zero_length, Point p0, Point p1, Scalar width)
static bool | ComputeCorners (Point corners[4], const Matrix &transform, bool extend_endpoints, Point p0, Point p1, Scalar width)
Static Public Member Functions inherited from impeller::Geometry
static std::unique_ptr< Geometry > | MakeFillPath (const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
static std::unique_ptr< Geometry > | MakeStrokePath (const flutter::DlPath &path, const StrokeParameters &stroke={})
static std::unique_ptr< Geometry > | MakeCover ()
static std::unique_ptr< Geometry > | MakeRect (const Rect &rect)
static std::unique_ptr< Geometry > | MakeOval (const Rect &rect)
static std::unique_ptr< Geometry > | MakeLine (const Point &p0, const Point &p1, const StrokeParameters &stroke)
static std::unique_ptr< Geometry > | MakeCircle (const Point &center, Scalar radius)
static std::unique_ptr< Geometry > | MakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
static std::unique_ptr< Geometry > | MakeFilledArc (const Rect &oval_bounds, Degrees start, Degrees sweep, bool include_center)
static std::unique_ptr< Geometry > | MakeStrokedArc (const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
static std::unique_ptr< Geometry > | MakeRoundRect (const Rect &rect, const Size &radii)
static std::unique_ptr< Geometry > | MakeRoundSuperellipse (const Rect &rect, Scalar corner_radius)
static Scalar | ComputeStrokeAlphaCoverage (const Matrix &entity, Scalar stroke_width)
| Compute an alpha value to simulate lower coverage of fractional pixel strokes. More...
static GeometryResult | ComputePositionGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)

## Detailed Description

Definition at line 12 of file line_geometry.h.

## Constructor & Destructor Documentation

## ◆ LineGeometry()

impeller::LineGeometry::LineGeometry | ( | Point | p0,
|  | Point | p1,
|  | const StrokeParameters & | stroke
| ) |  |
| explicit

Definition at line 11 of file line_geometry.cc.

12 : p0_(p0), p1_(p1), width_(stroke.width), cap_(stroke.cap) {
13 FML_DCHECK(width_ >= 0);
14 }

## ◆ ~LineGeometry()

impeller::LineGeometry::~LineGeometry | ( |  | ) |
| override default

## Member Function Documentation

## ◆ ComputeAlongVector()

Vector2 impeller::LineGeometry::ComputeAlongVector | ( | const Matrix & | transform,
|  | bool | allow_zero_length,
|  | Point | p0,
|  | Point | p1,
|  | Scalar | width
| ) |  |
| static

Definition at line 29 of file line_geometry.cc.

33 {
34 Scalar stroke_half_width = ComputePixelHalfWidth(transform, width);
35 if (stroke_half_width < kEhCloseEnough) {
36 return {};
37 }
38
39 auto along = p1 - p0;
40 Scalar length = along.GetLength();
41 if (length < kEhCloseEnough) {
42 if (!allow_zero_length) {
43 // We won't enclose any pixels unless the endpoints are extended
44 return {};
45 }
46 return {stroke_half_width, 0};
47 } else {
48 return along * stroke_half_width / length;
49 }
50 }
impeller::LineGeometry::ComputePixelHalfWidth
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
Definition: line_geometry.cc:18
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::kEhCloseEnough
constexpr float kEhCloseEnough
Definition: constants.h:57

References ComputePixelHalfWidth(), impeller::TPoint< T >::GetLength(), impeller::kEhCloseEnough, and transform.

Referenced by ComputeCorners().

## ◆ ComputeAlphaCoverage()

Scalar impeller::LineGeometry::ComputeAlphaCoverage | ( | const Matrix & | transform | ) | const
| override virtual

Reimplemented from impeller::Geometry.

Definition at line 77 of file line_geometry.cc.

77 {
78 return Geometry::ComputeStrokeAlphaCoverage(entity, width_);
79 }
impeller::Geometry::ComputeStrokeAlphaCoverage
static Scalar ComputeStrokeAlphaCoverage(const Matrix &entity, Scalar stroke_width)
Compute an alpha value to simulate lower coverage of fractional pixel strokes.
Definition: geometry.cc:149

References impeller::Geometry::ComputeStrokeAlphaCoverage().

## ◆ ComputeCorners()

bool impeller::LineGeometry::ComputeCorners | ( | Point | corners[4],
|  | const Matrix & | transform,
|  | bool | extend_endpoints,
|  | Point | p0,
|  | Point | p1,
|  | Scalar | width
| ) |  |
| static

Definition at line 52 of file line_geometry.cc.

57 {
58 auto along = ComputeAlongVector(transform, extend_endpoints, p0, p1, width);
59 if (along.IsZero()) {
60 return false;
61 }
62
63 auto across = Vector2(along.y, -along.x);
64 corners[0] = p0 - across;
65 corners[1] = p1 - across;
66 corners[2] = p0 + across;
67 corners[3] = p1 + across;
68 if (extend_endpoints) {
69 corners[0] -= along;
70 corners[1] += along;
71 corners[2] -= along;
72 corners[3] += along;
73 }
74 return true;
75 }
impeller::LineGeometry::ComputeAlongVector
static Vector2 ComputeAlongVector(const Matrix &transform, bool allow_zero_length, Point p0, Point p1, Scalar width)
Definition: line_geometry.cc:29
impeller::Vector2
Point Vector2
Definition: point.h:331

References ComputeAlongVector(), and transform.

Referenced by impeller::LineContents::CalculatePerVertex(), and GetCoverage().

## ◆ ComputePixelHalfWidth()

Scalar impeller::LineGeometry::ComputePixelHalfWidth | ( | const Matrix & | transform,
|  | Scalar | width
| ) |  |
| static

Definition at line 18 of file line_geometry.cc.

19 {
20 Scalar max_basis = transform.GetMaxBasisLengthXY();
21 if (max_basis == 0) {
22 return {};
23 }
24
25 Scalar min_size = kMinStrokeSize / max_basis;
26 return std::max(width, min_size) * 0.5f;
27 }
impeller::kMinStrokeSize
static constexpr Scalar kMinStrokeSize
Definition: geometry.h:19

References impeller::kMinStrokeSize, and transform.

Referenced by ComputeAlongVector().

## ◆ CoversArea()

bool impeller::LineGeometry::CoversArea | ( | const Matrix & | transform,
|  | const Rect & | rect
| ) |  | const
| override virtual

Determines if this geometry, transformed by the given `transform`, will completely cover all surface area of the given `rect`.

This is a conservative estimate useful for certain optimizations.

Returns
  `true` if the transformed geometry is guaranteed to cover the given `rect`. May return `false` in many undetected cases where the transformed geometry does in fact cover the `rect`.

Reimplemented from impeller::Geometry.

Definition at line 170 of file line_geometry.cc.

170 {
171 if (!transform.IsTranslationScaleOnly() || !IsAxisAlignedRect()) {
172 return false;
173 }
174 auto coverage = GetCoverage(transform);
175 return coverage.has_value() ? coverage->Contains(rect) : false;
176 }
impeller::LineGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: line_geometry.cc:178
impeller::LineGeometry::GetCoverage
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Definition: line_geometry.cc:156

References GetCoverage(), IsAxisAlignedRect(), and transform.

## ◆ GetCap()

Cap impeller::LineGeometry::GetCap | ( |  | ) | const
| inline

Definition at line 34 of file line_geometry.h.

34 { return cap_; }

Referenced by impeller::LineContents::CalculatePerVertex().

## ◆ GetCoverage()

std::optional< Rect > impeller::LineGeometry::GetCoverage | ( | const Matrix & | transform | ) | const
| override virtual

Implements impeller::Geometry.

Definition at line 156 of file line_geometry.cc.

156 {
157 Point corners[4];
158 // Note: MSAA boolean doesn't matter for coverage computation.
159 if (!ComputeCorners(corners, transform, cap_ != Cap::kButt, p0_, p1_,
160 width_)) {
161 return {};
162 }
163
164 for (int i = 0; i < 4; i++) {
165 corners[i] = transform * corners[i];
166 }
167 return Rect::MakePointBounds(std::begin(corners), std::end(corners));
168 }
impeller::LineGeometry::ComputeCorners
static bool ComputeCorners(Point corners[4], const Matrix &transform, bool extend_endpoints, Point p0, Point p1, Scalar width)
Definition: line_geometry.cc:52
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::Cap::kButt
@ kButt
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:165
end
const size_t end
Definition: tessellator_libtess.cc:63

References ComputeCorners(), end, impeller::kButt, impeller::TRect< Scalar >::MakePointBounds(), and transform.

Referenced by CoversArea().

## ◆ GetP0()

Point impeller::LineGeometry::GetP0 | ( |  | ) | const
| inline

Definition at line 31 of file line_geometry.h.

31 { return p0_; }

Referenced by impeller::LineContents::CalculatePerVertex().

## ◆ GetP1()

Point impeller::LineGeometry::GetP1 | ( |  | ) | const
| inline

Definition at line 32 of file line_geometry.h.

32 { return p1_; }

Referenced by impeller::LineContents::CalculatePerVertex().

## ◆ GetWidth()

Scalar impeller::LineGeometry::GetWidth | ( |  | ) | const
| inline

Definition at line 33 of file line_geometry.h.

33 { return width_; }

Referenced by impeller::LineContents::CalculatePerVertex().

## ◆ IsAxisAlignedRect()

bool impeller::LineGeometry::IsAxisAlignedRect | ( |  | ) | const
| override virtual

Reimplemented from impeller::Geometry.

Definition at line 178 of file line_geometry.cc.

178 {
179 return cap_ != Cap::kRound && (p0_.x == p1_.x || p0_.y == p1_.y);
180 }
impeller::Cap::kRound
@ kRound
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::TPoint::x
Type x
Definition: point.h:30

References impeller::kRound.

Referenced by CoversArea().

The documentation for this class was generated from the following files:

- impeller/entity/geometry/line_geometry.h
- impeller/entity/geometry/line_geometry.cc