Do not include the leading point for cubic polylines (flutter/engine#29)

This avoids having duplicated points present in the polyline.
This commit is contained in:
Dan Field
2022-02-24 10:34:01 -08:00
committed by Dan Field
parent f0ec41b89e
commit f22879f695
2 changed files with 11 additions and 1 deletions

View File

@@ -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"
@@ -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

View File

@@ -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;