Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/msdfgen/core/Shape.h
21119 views
1
2
#pragma once
3
4
#include <vector>
5
#include "Contour.h"
6
#include "YAxisOrientation.h"
7
#include "Scanline.h"
8
9
namespace msdfgen {
10
11
// Threshold of the dot product of adjacent edge directions to be considered convergent.
12
#define MSDFGEN_CORNER_DOT_EPSILON .000001
13
14
/// Vector shape representation.
15
class Shape {
16
17
public:
18
struct Bounds {
19
// NOTE: b is actually the lower Y-coordinate and t the higher Y-coordinate. For Y_DOWNWARD orientation, b is actually the top and t the bottom. May be renamed in a future version.
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
/// DEPRECATED - use getYAxisOrientation / setYAxisOrientation instead.
27
bool inverseYAxis;
28
29
Shape();
30
/// Adds a contour.
31
void addContour(const Contour &contour);
32
#ifdef MSDFGEN_USE_CPP11
33
void addContour(Contour &&contour);
34
#endif
35
/// Adds a blank contour and returns its reference.
36
Contour &addContour();
37
/// Normalizes the shape geometry for distance field generation.
38
void normalize();
39
/// Performs basic checks to determine if the object represents a valid shape.
40
bool validate() const;
41
/// Adjusts the bounding box to fit the shape.
42
void bound(double &xMin, double &yMin, double &xMax, double &yMax) const;
43
/// Adjusts the bounding box to fit the shape border's mitered corners.
44
void boundMiters(double &xMin, double &yMin, double &xMax, double &yMax, double border, double miterLimit, int polarity) const;
45
/// Computes the minimum bounding box that fits the shape, optionally with a (mitered) border.
46
Bounds getBounds(double border = 0, double miterLimit = 0, int polarity = 0) const;
47
/// Outputs the scanline that intersects the shape at y.
48
void scanline(Scanline &line, double y) const;
49
/// Returns the total number of edge segments
50
int edgeCount() const;
51
/// Assumes its contours are unoriented (even-odd fill rule). Attempts to orient them to conform to the non-zero winding rule.
52
void orientContours();
53
/// Returns the orientation of the axis of the shape's Y coordinates.
54
YAxisOrientation getYAxisOrientation() const;
55
/// Sets the orientation of the axis of the shape's Y coordinates.
56
void setYAxisOrientation(YAxisOrientation yAxisOrientation);
57
58
};
59
60
}
61
62