1010#include " impeller/geometry/constants.h"
1111#include " impeller/geometry/path_builder.h"
1212#include " impeller/geometry/path_component.h"
13+ #include " impeller/geometry/separated_vector.h"
1314
1415namespace impeller {
1516using VS = SolidFillVertexShader;
@@ -163,45 +164,13 @@ class StrokeGenerator {
163164 }
164165 }
165166
166- // / @brief Represents a ray in 2D space.
167- // /
168- // / This is a simple convenience struct for handling polyline offset
169- // / values when generating stroke geometry. For performance reasons,
170- // / it's sometimes adventageous to track the direction and magnitude
171- // / for offsets separately.
172- struct Ray {
173- // / The normalized direction of the ray.
174- Vector2 direction;
175-
176- // / The magnitude of the ray.
177- Scalar magnitude = 0.0 ;
178-
179- // / Returns the vector representation of the ray.
180- Vector2 GetVector () const { return direction * magnitude; }
181-
182- // / Returns the scalar alignment of the two rays.
183- // /
184- // / Domain: [-1, 1]
185- // / A value of 1 indicates the rays are parallel and pointing in the same
186- // / direction. A value of -1 indicates the rays are parallel and pointing in
187- // / opposite directions. A value of 0 indicates the rays are perpendicular.
188- Scalar GetAlignment (const Ray& other) const {
189- return direction.Dot (other.direction );
190- }
191-
192- // / Returns the scalar angle between the two rays.
193- Radians AngleTo (const Ray& other) const {
194- return direction.AngleTo (other.direction );
195- }
196- };
197-
198167 // / Computes offset by calculating the direction from point_i - 1 to point_i
199168 // / if point_i is within `contour_start_point_i` and `contour_end_point_i`;
200169 // / Otherwise, it uses direction from contour.
201- Ray ComputeOffset (const size_t point_i,
202- const size_t contour_start_point_i,
203- const size_t contour_end_point_i,
204- const Path::PolylineContour& contour) const {
170+ SeparatedVector2 ComputeOffset (const size_t point_i,
171+ const size_t contour_start_point_i,
172+ const size_t contour_end_point_i,
173+ const Path::PolylineContour& contour) const {
205174 Point direction;
206175 if (point_i >= contour_end_point_i) {
207176 direction = contour.end_direction ;
@@ -211,8 +180,8 @@ class StrokeGenerator {
211180 direction = (polyline.GetPoint (point_i) - polyline.GetPoint (point_i - 1 ))
212181 .Normalize ();
213182 }
214- return {. direction = Vector2{-direction.y , direction.x },
215- . magnitude = stroke_width * 0 .5f } ;
183+ return SeparatedVector2 ( Vector2{-direction.y , direction.x },
184+ stroke_width * 0 .5f ) ;
216185 }
217186
218187 void AddVerticesForLinearComponent (VertexWriter& vtx_builder,
@@ -338,8 +307,8 @@ class StrokeGenerator {
338307 const CapProc<VertexWriter>& cap_proc;
339308 const Scalar scale;
340309
341- Ray previous_offset;
342- Ray offset;
310+ SeparatedVector2 previous_offset;
311+ SeparatedVector2 offset;
343312 SolidFillVertexShader::PerVertexData vtx;
344313};
345314
0 commit comments