mirror of https://github.com/Chlumsky/msdfgen.git
Removed dynamic_cast
This commit is contained in:
parent
26143a3e9f
commit
052f5fffd7
|
|
@ -40,15 +40,12 @@ bool Shape::validate() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deconvergeEdge(EdgeHolder &edgeHolder, int param) {
|
static void deconvergeEdge(EdgeHolder &edgeHolder, int param) {
|
||||||
{
|
switch (edgeHolder->type()) {
|
||||||
const QuadraticSegment *quadraticSegment = dynamic_cast<const QuadraticSegment *>(&*edgeHolder);
|
case (int) QuadraticSegment::EDGE_TYPE:
|
||||||
if (quadraticSegment)
|
edgeHolder = static_cast<const QuadraticSegment *>(&*edgeHolder)->convertToCubic();
|
||||||
edgeHolder = quadraticSegment->convertToCubic();
|
// fallthrough
|
||||||
}
|
case (int) CubicSegment::EDGE_TYPE:
|
||||||
{
|
static_cast<CubicSegment *>(&*edgeHolder)->deconverge(param, MSDFGEN_DECONVERGENCE_FACTOR);
|
||||||
CubicSegment *cubicSegment = dynamic_cast<CubicSegment *>(&*edgeHolder);
|
|
||||||
if (cubicSegment)
|
|
||||||
cubicSegment->deconverge(param, MSDFGEN_DECONVERGENCE_FACTOR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,30 @@ CubicSegment * CubicSegment::clone() const {
|
||||||
return new CubicSegment(p[0], p[1], p[2], p[3], color);
|
return new CubicSegment(p[0], p[1], p[2], p[3], color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LinearSegment::type() const {
|
||||||
|
return (int) EDGE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int QuadraticSegment::type() const {
|
||||||
|
return (int) EDGE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CubicSegment::type() const {
|
||||||
|
return (int) EDGE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Point2 * LinearSegment::controlPoints() const {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Point2 * QuadraticSegment::controlPoints() const {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Point2 * CubicSegment::controlPoints() const {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
Point2 LinearSegment::point(double param) const {
|
Point2 LinearSegment::point(double param) const {
|
||||||
return mix(p[0], p[1], param);
|
return mix(p[0], p[1], param);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ public:
|
||||||
virtual ~EdgeSegment() { }
|
virtual ~EdgeSegment() { }
|
||||||
/// Creates a copy of the edge segment.
|
/// Creates a copy of the edge segment.
|
||||||
virtual EdgeSegment * clone() const = 0;
|
virtual EdgeSegment * clone() const = 0;
|
||||||
|
/// Returns the numeric code of the edge segment's type.
|
||||||
|
virtual int type() const = 0;
|
||||||
|
/// Returns the array of control points.
|
||||||
|
virtual const Point2 * controlPoints() const = 0;
|
||||||
/// Returns the point on the edge specified by the parameter (between 0 and 1).
|
/// Returns the point on the edge specified by the parameter (between 0 and 1).
|
||||||
virtual Point2 point(double param) const = 0;
|
virtual Point2 point(double param) const = 0;
|
||||||
/// Returns the direction the edge has at the point specified by the parameter.
|
/// Returns the direction the edge has at the point specified by the parameter.
|
||||||
|
|
@ -51,10 +55,16 @@ public:
|
||||||
class LinearSegment : public EdgeSegment {
|
class LinearSegment : public EdgeSegment {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum EdgeType {
|
||||||
|
EDGE_TYPE = 1
|
||||||
|
};
|
||||||
|
|
||||||
Point2 p[2];
|
Point2 p[2];
|
||||||
|
|
||||||
LinearSegment(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE);
|
LinearSegment(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE);
|
||||||
LinearSegment * clone() const;
|
LinearSegment * clone() const;
|
||||||
|
int type() const;
|
||||||
|
const Point2 * controlPoints() const;
|
||||||
Point2 point(double param) const;
|
Point2 point(double param) const;
|
||||||
Vector2 direction(double param) const;
|
Vector2 direction(double param) const;
|
||||||
Vector2 directionChange(double param) const;
|
Vector2 directionChange(double param) const;
|
||||||
|
|
@ -74,10 +84,16 @@ public:
|
||||||
class QuadraticSegment : public EdgeSegment {
|
class QuadraticSegment : public EdgeSegment {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum EdgeType {
|
||||||
|
EDGE_TYPE = 2
|
||||||
|
};
|
||||||
|
|
||||||
Point2 p[3];
|
Point2 p[3];
|
||||||
|
|
||||||
QuadraticSegment(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor = WHITE);
|
QuadraticSegment(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor = WHITE);
|
||||||
QuadraticSegment * clone() const;
|
QuadraticSegment * clone() const;
|
||||||
|
int type() const;
|
||||||
|
const Point2 * controlPoints() const;
|
||||||
Point2 point(double param) const;
|
Point2 point(double param) const;
|
||||||
Vector2 direction(double param) const;
|
Vector2 direction(double param) const;
|
||||||
Vector2 directionChange(double param) const;
|
Vector2 directionChange(double param) const;
|
||||||
|
|
@ -99,10 +115,16 @@ public:
|
||||||
class CubicSegment : public EdgeSegment {
|
class CubicSegment : public EdgeSegment {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum EdgeType {
|
||||||
|
EDGE_TYPE = 3
|
||||||
|
};
|
||||||
|
|
||||||
Point2 p[4];
|
Point2 p[4];
|
||||||
|
|
||||||
CubicSegment(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor = WHITE);
|
CubicSegment(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor = WHITE);
|
||||||
CubicSegment * clone() const;
|
CubicSegment * clone() const;
|
||||||
|
int type() const;
|
||||||
|
const Point2 * controlPoints() const;
|
||||||
Point2 point(double param) const;
|
Point2 point(double param) const;
|
||||||
Vector2 direction(double param) const;
|
Vector2 direction(double param) const;
|
||||||
Vector2 directionChange(double param) const;
|
Vector2 directionChange(double param) const;
|
||||||
|
|
|
||||||
|
|
@ -244,34 +244,37 @@ bool writeShapeDescription(FILE *output, const Shape &shape) {
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (const LinearSegment *e = dynamic_cast<const LinearSegment *>(&**edge)) {
|
const Point2 *p = (*edge)->controlPoints();
|
||||||
fprintf(output, "\t");
|
switch ((*edge)->type()) {
|
||||||
writeCoord(output, e->p[0]);
|
case (int) LinearSegment::EDGE_TYPE:
|
||||||
fprintf(output, ";\n");
|
fprintf(output, "\t");
|
||||||
if (colorCode)
|
writeCoord(output, p[0]);
|
||||||
fprintf(output, "\t\t%c;\n", colorCode);
|
fprintf(output, ";\n");
|
||||||
}
|
if (colorCode)
|
||||||
if (const QuadraticSegment *e = dynamic_cast<const QuadraticSegment *>(&**edge)) {
|
fprintf(output, "\t\t%c;\n", colorCode);
|
||||||
fprintf(output, "\t");
|
break;
|
||||||
writeCoord(output, e->p[0]);
|
case (int) QuadraticSegment::EDGE_TYPE:
|
||||||
fprintf(output, ";\n\t\t");
|
fprintf(output, "\t");
|
||||||
if (colorCode)
|
writeCoord(output, p[0]);
|
||||||
fprintf(output, "%c", colorCode);
|
fprintf(output, ";\n\t\t");
|
||||||
fprintf(output, "(");
|
if (colorCode)
|
||||||
writeCoord(output, e->p[1]);
|
fprintf(output, "%c", colorCode);
|
||||||
fprintf(output, ");\n");
|
fprintf(output, "(");
|
||||||
}
|
writeCoord(output, p[1]);
|
||||||
if (const CubicSegment *e = dynamic_cast<const CubicSegment *>(&**edge)) {
|
fprintf(output, ");\n");
|
||||||
fprintf(output, "\t");
|
break;
|
||||||
writeCoord(output, e->p[0]);
|
case (int) CubicSegment::EDGE_TYPE:
|
||||||
fprintf(output, ";\n\t\t");
|
fprintf(output, "\t");
|
||||||
if (colorCode)
|
writeCoord(output, p[0]);
|
||||||
fprintf(output, "%c", colorCode);
|
fprintf(output, ";\n\t\t");
|
||||||
fprintf(output, "(");
|
if (colorCode)
|
||||||
writeCoord(output, e->p[1]);
|
fprintf(output, "%c", colorCode);
|
||||||
fprintf(output, "; ");
|
fprintf(output, "(");
|
||||||
writeCoord(output, e->p[2]);
|
writeCoord(output, p[1]);
|
||||||
fprintf(output, ");\n");
|
fprintf(output, "; ");
|
||||||
|
writeCoord(output, p[2]);
|
||||||
|
fprintf(output, ");\n");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(output, "\t#\n");
|
fprintf(output, "\t#\n");
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,18 @@ void shapeToSkiaPath(SkPath &skPath, const Shape &shape) {
|
||||||
if (!contour->edges.empty()) {
|
if (!contour->edges.empty()) {
|
||||||
skPath.moveTo(pointToSkiaPoint(contour->edges.front()->point(0)));
|
skPath.moveTo(pointToSkiaPoint(contour->edges.front()->point(0)));
|
||||||
for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge) {
|
for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge) {
|
||||||
if (const LinearSegment *linearSegment = dynamic_cast<const LinearSegment *>(&**edge))
|
const Point2 *p = (*edge)->controlPoints();
|
||||||
skPath.lineTo(pointToSkiaPoint(linearSegment->p[1]));
|
switch ((*edge)->type()) {
|
||||||
else if (const QuadraticSegment *quadraticSegment = dynamic_cast<const QuadraticSegment *>(&**edge))
|
case (int) LinearSegment::EDGE_TYPE:
|
||||||
skPath.quadTo(pointToSkiaPoint(quadraticSegment->p[1]), pointToSkiaPoint(quadraticSegment->p[2]));
|
skPath.lineTo(pointToSkiaPoint(p[1]));
|
||||||
else if (const CubicSegment *cubicSegment = dynamic_cast<const CubicSegment *>(&**edge))
|
break;
|
||||||
skPath.cubicTo(pointToSkiaPoint(cubicSegment->p[1]), pointToSkiaPoint(cubicSegment->p[2]), pointToSkiaPoint(cubicSegment->p[3]));
|
case (int) QuadraticSegment::EDGE_TYPE:
|
||||||
|
skPath.quadTo(pointToSkiaPoint(p[1]), pointToSkiaPoint(p[2]));
|
||||||
|
break;
|
||||||
|
case (int) CubicSegment::EDGE_TYPE:
|
||||||
|
skPath.cubicTo(pointToSkiaPoint(p[1]), pointToSkiaPoint(p[2]), pointToSkiaPoint(p[3]));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue