Skip to content

Commit

Permalink
Do not include the leading point for cubic polylines (#29)
Browse files Browse the repository at this point in the history
This avoids having duplicated points present in the polyline.
  • Loading branch information
dnfield committed Apr 27, 2022
1 parent e94acaa commit b26c6ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 11 additions & 0 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "flutter/testing/testing.h"
#include "impeller/geometry/path.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/geometry/path_component.h"
#include "impeller/geometry/point.h"
#include "impeller/geometry/rect.h"
#include "impeller/geometry/size.h"
Expand Down Expand Up @@ -524,5 +525,15 @@ TEST(GeometryTest, RectContainsRect) {
}
}

TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
CubicPathComponent component({10, 10}, {20,35}, {35, 20}, {40, 40});
SmoothingApproximation approximation;
auto polyline = component.CreatePolyline(approximation);
ASSERT_NE(polyline.front().x, 10);
ASSERT_NE(polyline.front().y, 10);
ASSERT_EQ(polyline.back().x, 40);
ASSERT_EQ(polyline.back().y, 40);
}

} // namespace testing
} // namespace impeller
1 change: 0 additions & 1 deletion impeller/geometry/path_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ static void CubicPathSmoothenRecursive(const SmoothingApproximation& approx,
std::vector<Point> CubicPathComponent::CreatePolyline(
const SmoothingApproximation& approximation) const {
std::vector<Point> points;
points.emplace_back(p1);
CubicPathSmoothenRecursive(approximation, points, p1, cp1, cp2, p2, 0);
points.emplace_back(p2);
return points;
Expand Down

0 comments on commit b26c6ac

Please sign in to comment.