1
2#pragma once
3
4#include <vector>
5#include "Contour.h"
6#include "Scanline.h"
7
8namespace msdfgen {
9
10// Threshold of the dot product of adjacent edge directions to be considered convergent.
11#define MSDFGEN_CORNER_DOT_EPSILON .000001
12// The proportional amount by which a curve's control point will be adjusted to eliminate convergent corners.
13#define MSDFGEN_DECONVERGENCE_FACTOR .000001
14
15/// Vector shape representation.
16class Shape {
17
18public:
19 struct Bounds {
20 double l, b, r, t;
21 };
22
23 /// The list of contours the shape consists of.
24 std::vector<Contour> contours;
25 /// Specifies whether the shape uses bottom-to-top (false) or top-to-bottom (true) Y coordinates.
26 bool inverseYAxis;
27
28 Shape();
29 /// Adds a contour.
30 void addContour(const Contour &contour);
31#ifdef MSDFGEN_USE_CPP11
32 void addContour(Contour &&contour);
33#endif
34 /// Adds a blank contour and returns its reference.
35 Contour & addContour();
36 /// Normalizes the shape geometry for distance field generation.
37 void normalize();
38 /// Performs basic checks to determine if the object represents a valid shape.
39 bool validate() const;
40 /// Adjusts the bounding box to fit the shape.
41 void bound(double &l, double &b, double &r, double &t) const;
42 /// Adjusts the bounding box to fit the shape border's mitered corners.
43 void boundMiters(double &l, double &b, double &r, double &t, double border, double miterLimit, int polarity) const;
44 /// Computes the minimum bounding box that fits the shape, optionally with a (mitered) border.
45 Bounds getBounds(double border = 0, double miterLimit = 0, int polarity = 0) const;
46 /// Outputs the scanline that intersects the shape at y.
47 void scanline(Scanline &line, double y) const;
48 /// Returns the total number of edge segments
49 int edgeCount() const;
50 /// Assumes its contours are unoriented (even-odd fill rule). Attempts to orient them to conform to the non-zero winding rule.
51 void orientContours();
52
53};
54
55}
56