| Flutter Impeller |

Public Member Functions | List of all members
impeller::DashedLinePathSource Class Reference

A PathSource that generates the various segments of a dashed line. More...

`#include <dashed_line_path_source.h>`

Inheritance diagram for impeller::DashedLinePathSource:

## Public Member Functions
| DashedLinePathSource (Point p0, Point p1, Scalar on_length, Scalar off_length)
| ~DashedLinePathSource ()
FillType | GetFillType () const override
Rect | GetBounds () const override
bool | IsConvex () const override
void | Dispatch (PathReceiver &receiver) const override
Public Member Functions inherited from impeller::PathSource
virtual | ~PathSource ()=default

## Detailed Description

A PathSource that generates the various segments of a dashed line.

Definition at line 15 of file dashed_line_path_source.h.

## Constructor & Destructor Documentation

## ◆ DashedLinePathSource()

impeller::DashedLinePathSource::DashedLinePathSource | ( | Point | p0,
|  | Point | p1,
|  | Scalar | on_length,
|  | Scalar | off_length
| ) |  |

Definition at line 9 of file dashed_line_path_source.cc.

13 : p0_(p0), p1_(p1), on_length_(on_length), off_length_(off_length) {}

## ◆ ~DashedLinePathSource()

impeller::DashedLinePathSource::~DashedLinePathSource | ( |  | ) |
| default

## Member Function Documentation

## ◆ Dispatch()

void impeller::DashedLinePathSource::Dispatch | ( | PathReceiver & | receiver | ) | const
| override virtual

Implements impeller::PathSource.

Definition at line 29 of file dashed_line_path_source.cc.

29 {
30 // Exceptional conditions:
31 // - length is non-positive - result will draw only a "dot"
32 // - off_length is non-positive - no gaps, result is a solid line
33 // - on_length is negative - invalid dashing
34 // Note that a 0 length "on" dash will draw "dot"s every "off" distance
35 // apart so we still generate the dashing for that case.
36 //
37 // Note that Canvas will detect these conditions and use its own DrawLine
38 // method directly for performance reasons for a single line, but in case
39 // someone uses this PathSource with these exceptional cases, we degenerate
40 // gracefully into a single line segment path description below.
41 Scalar length = p0_.GetDistance(p1_);
42 if (length > 0.0f && on_length_ >= 0.0f && off_length_ > 0.0f) {
43 Point delta = (p1_ - p0_) / length; // length > 0 already verified
44
45 Scalar consumed = 0.0f;
46 while (consumed < length) {
47 receiver.MoveTo(p0_ + delta * consumed, false);
48
49 Scalar dash_end = consumed + on_length_;
50 if (dash_end < length) {
51 receiver.LineTo(p0_ + delta * dash_end);
52 } else {
53 receiver.LineTo(p1_);
54 // Should happen anyway due to the math, but let's make it explicit
55 // in case of bit errors. We're done with this line.
56 break;
57 }
58
59 consumed = dash_end + off_length_;
60 }
61 } else {
62 receiver.MoveTo(p0_, false);
63 receiver.LineTo(p1_);
64 }
65 }
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::Point
TPoint< Scalar > Point
Definition: point.h:425
impeller::TPoint::GetDistance
constexpr Type GetDistance(const TPoint &p) const
Definition: point.h:201

References impeller::TPoint< T >::GetDistance(), impeller::PathReceiver::LineTo(), and impeller::PathReceiver::MoveTo().

Referenced by impeller::testing::TEST().

## ◆ GetBounds()

Rect impeller::DashedLinePathSource::GetBounds | ( |  | ) | const
| override virtual

Implements impeller::PathSource.

Definition at line 21 of file dashed_line_path_source.cc.

21 {
22 return Rect::MakeLTRB(p0_.x, p0_.y, p1_.x, p1_.y).GetPositive();
23 }
impeller::TPoint::y
Type y
Definition: point.h:32
impeller::TPoint::x
Type x
Definition: point.h:31
impeller::TRect::GetPositive
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:398
impeller::TRect< Scalar >::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129

References impeller::TRect< T >::GetPositive(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::testing::TEST().

## ◆ GetFillType()

FillType impeller::DashedLinePathSource::GetFillType | ( |  | ) | const
| override virtual

Implements impeller::PathSource.

Definition at line 17 of file dashed_line_path_source.cc.

17 {
18 return FillType::kNonZero;
19 }
impeller::FillType::kNonZero
@ kNonZero

References impeller::kNonZero.

Referenced by impeller::testing::TEST().

## ◆ IsConvex()

bool impeller::DashedLinePathSource::IsConvex | ( |  | ) | const
| override virtual

Implements impeller::PathSource.

Definition at line 25 of file dashed_line_path_source.cc.

25 {
26 return false;
27 }

Referenced by impeller::testing::TEST().

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

- impeller/geometry/dashed_line_path_source.h
- impeller/geometry/dashed_line_path_source.cc