mirror of https://github.com/Chlumsky/msdfgen.git
Merge branch 'point_tolerance'
* point_tolerance: Clean up degenerate segments during normalization
This commit is contained in:
commit
7cc65a66d2
|
|
@ -38,6 +38,17 @@ bool Shape::validate() const {
|
|||
|
||||
void Shape::normalize() {
|
||||
for (std::vector<Contour>::iterator contour = contours.begin(); contour != contours.end(); ++contour) {
|
||||
// First, erase all degenerate edges.
|
||||
std::vector<EdgeHolder>::iterator edge_it = contour->edges.begin();
|
||||
while( edge_it != contour->edges.end() ) {
|
||||
if( (*edge_it)->isDegenerate() ) {
|
||||
edge_it = contour->edges.erase(edge_it);
|
||||
}
|
||||
else {
|
||||
edge_it++;
|
||||
}
|
||||
}
|
||||
|
||||
if (contour->edges.size() == 1) {
|
||||
EdgeSegment *parts[3] = { };
|
||||
contour->edges[0]->splitInThirds(parts[0], parts[1], parts[2]);
|
||||
|
|
|
|||
|
|
@ -295,5 +295,17 @@ void CubicSegment::splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeS
|
|||
point(2/3.), color);
|
||||
part3 = new CubicSegment(point(2/3.), mix(mix(p[1], p[2], 2/3.), mix(p[2], p[3], 2/3.), 2/3.), p[2] == p[3] ? p[3] : mix(p[2], p[3], 2/3.), p[3], color);
|
||||
}
|
||||
|
||||
bool LinearSegment::isDegenerate() const {
|
||||
return p[0].same(p[1]);
|
||||
}
|
||||
|
||||
bool QuadraticSegment::isDegenerate() const {
|
||||
return p[0].same(p[2]);
|
||||
}
|
||||
|
||||
bool CubicSegment::isDegenerate() const {
|
||||
return p[0].same(p[3]) && (p[0].same(p[1]) || p[2].same(p[1]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public:
|
|||
virtual void moveEndPoint(Point2 to) = 0;
|
||||
/// Splits the edge segments into thirds which together represent the original edge.
|
||||
virtual void splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeSegment *&part3) const = 0;
|
||||
|
||||
virtual bool isDegenerate() const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -57,6 +59,8 @@ public:
|
|||
void moveStartPoint(Point2 to);
|
||||
void moveEndPoint(Point2 to);
|
||||
void splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeSegment *&part3) const;
|
||||
|
||||
bool isDegenerate() const;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -77,6 +81,8 @@ public:
|
|||
void moveEndPoint(Point2 to);
|
||||
void splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeSegment *&part3) const;
|
||||
|
||||
bool isDegenerate() const;
|
||||
|
||||
};
|
||||
|
||||
/// A cubic Bezier curve.
|
||||
|
|
@ -96,6 +102,8 @@ public:
|
|||
void moveEndPoint(Point2 to);
|
||||
void splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeSegment *&part3) const;
|
||||
|
||||
bool isDegenerate() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue