Rename utilities for adaptive subdivision.
This commit is contained in:
@@ -144,32 +144,30 @@ bool Path::UpdateCubicComponentAtIndex(size_t index,
|
||||
return true;
|
||||
}
|
||||
|
||||
void Path::EnumerateSmoothPoints(
|
||||
SmoothPointsEnumerator enumerator,
|
||||
const SmoothingApproximation& approximation) const {
|
||||
if (enumerator == nullptr) {
|
||||
return;
|
||||
}
|
||||
static void AddPoints(std::vector<Point>& dest, const std::vector<Point>& src) {
|
||||
dest.reserve(dest.size() + src.size());
|
||||
dest.insert(dest.end(), src.begin(), src.end());
|
||||
}
|
||||
|
||||
std::vector<Point> Path::SubdivideAdaptively(
|
||||
const SmoothingApproximation& approximation) const {
|
||||
std::vector<Point> points;
|
||||
for (const auto& component : components_) {
|
||||
switch (component.type) {
|
||||
case ComponentType::kLinear: {
|
||||
if (!enumerator(linears_[component.index].SmoothPoints())) {
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
case ComponentType::kQuadratic: {
|
||||
if (!enumerator(quads_[component.index].SmoothPoints(approximation))) {
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
case ComponentType::kCubic: {
|
||||
if (!enumerator(cubics_[component.index].SmoothPoints(approximation))) {
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
case ComponentType::kLinear:
|
||||
AddPoints(points, linears_[component.index].SubdivideAdaptively());
|
||||
break;
|
||||
case ComponentType::kQuadratic:
|
||||
AddPoints(points,
|
||||
quads_[component.index].SubdivideAdaptively(approximation));
|
||||
break;
|
||||
case ComponentType::kCubic:
|
||||
AddPoints(points,
|
||||
cubics_[component.index].SubdivideAdaptively(approximation));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
Rect Path::GetBoundingBox() const {
|
||||
|
||||
@@ -53,9 +53,8 @@ class Path {
|
||||
|
||||
bool UpdateCubicComponentAtIndex(size_t index, CubicPathComponent& cubic);
|
||||
|
||||
using SmoothPointsEnumerator = std::function<bool(std::vector<Point> points)>;
|
||||
void EnumerateSmoothPoints(SmoothPointsEnumerator enumerator,
|
||||
const SmoothingApproximation& approximation) const;
|
||||
std::vector<Point> SubdivideAdaptively(
|
||||
const SmoothingApproximation& approximation) const;
|
||||
|
||||
Rect GetBoundingBox() const;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ Point LinearPathComponent::Solve(Scalar time) const {
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<Point> LinearPathComponent::SmoothPoints() const {
|
||||
std::vector<Point> LinearPathComponent::SubdivideAdaptively() const {
|
||||
return {p1, p2};
|
||||
}
|
||||
|
||||
@@ -85,10 +85,10 @@ Point QuadraticPathComponent::SolveDerivative(Scalar time) const {
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<Point> QuadraticPathComponent::SmoothPoints(
|
||||
std::vector<Point> QuadraticPathComponent::SubdivideAdaptively(
|
||||
const SmoothingApproximation& approximation) const {
|
||||
CubicPathComponent elevated(*this);
|
||||
return elevated.SmoothPoints(approximation);
|
||||
return elevated.SubdivideAdaptively(approximation);
|
||||
}
|
||||
|
||||
std::vector<Point> QuadraticPathComponent::Extrema() const {
|
||||
@@ -336,7 +336,7 @@ static void CubicPathSmoothenRecursive(const SmoothingApproximation& approx,
|
||||
CubicPathSmoothenRecursive(approx, points, p1234, p234, p34, p4, level + 1);
|
||||
}
|
||||
|
||||
std::vector<Point> CubicPathComponent::SmoothPoints(
|
||||
std::vector<Point> CubicPathComponent::SubdivideAdaptively(
|
||||
const SmoothingApproximation& approximation) const {
|
||||
std::vector<Point> points;
|
||||
points.emplace_back(p1);
|
||||
|
||||
@@ -41,7 +41,7 @@ struct LinearPathComponent {
|
||||
|
||||
Point Solve(Scalar time) const;
|
||||
|
||||
std::vector<Point> SmoothPoints() const;
|
||||
std::vector<Point> SubdivideAdaptively() const;
|
||||
|
||||
std::vector<Point> Extrema() const;
|
||||
|
||||
@@ -64,7 +64,7 @@ struct QuadraticPathComponent {
|
||||
|
||||
Point SolveDerivative(Scalar time) const;
|
||||
|
||||
std::vector<Point> SmoothPoints(
|
||||
std::vector<Point> SubdivideAdaptively(
|
||||
const SmoothingApproximation& approximation) const;
|
||||
|
||||
std::vector<Point> Extrema() const;
|
||||
@@ -95,7 +95,7 @@ struct CubicPathComponent {
|
||||
|
||||
Point SolveDerivative(Scalar time) const;
|
||||
|
||||
std::vector<Point> SmoothPoints(
|
||||
std::vector<Point> SubdivideAdaptively(
|
||||
const SmoothingApproximation& approximation) const;
|
||||
|
||||
std::vector<Point> Extrema() const;
|
||||
|
||||
Reference in New Issue
Block a user