Inlined Vector2 and SignedDistance for performance, minor coding style change

This commit is contained in:
Chlumsky 2023-10-11 23:59:32 +02:00
parent e69b7962d1
commit bd5f145672
33 changed files with 289 additions and 349 deletions

View File

@ -18,17 +18,17 @@ public:
Bitmap(Bitmap<T, N> &&orig);
#endif
~Bitmap();
Bitmap<T, N> & operator=(const BitmapConstRef<T, N> &orig);
Bitmap<T, N> & operator=(const Bitmap<T, N> &orig);
Bitmap<T, N> &operator=(const BitmapConstRef<T, N> &orig);
Bitmap<T, N> &operator=(const Bitmap<T, N> &orig);
#ifdef MSDFGEN_USE_CPP11
Bitmap<T, N> & operator=(Bitmap<T, N> &&orig);
Bitmap<T, N> &operator=(Bitmap<T, N> &&orig);
#endif
/// Bitmap width in pixels.
int width() const;
/// Bitmap height in pixels.
int height() const;
T * operator()(int x, int y);
const T * operator()(int x, int y) const;
T *operator()(int x, int y);
const T *operator()(int x, int y) const;
#ifdef MSDFGEN_USE_CPP11
explicit operator T *();
explicit operator const T *() const;

View File

@ -40,7 +40,7 @@ Bitmap<T, N>::~Bitmap() {
}
template <typename T, int N>
Bitmap<T, N> & Bitmap<T, N>::operator=(const BitmapConstRef<T, N> &orig) {
Bitmap<T, N> &Bitmap<T, N>::operator=(const BitmapConstRef<T, N> &orig) {
if (pixels != orig.pixels) {
delete [] pixels;
w = orig.width, h = orig.height;
@ -51,7 +51,7 @@ Bitmap<T, N> & Bitmap<T, N>::operator=(const BitmapConstRef<T, N> &orig) {
}
template <typename T, int N>
Bitmap<T, N> & Bitmap<T, N>::operator=(const Bitmap<T, N> &orig) {
Bitmap<T, N> &Bitmap<T, N>::operator=(const Bitmap<T, N> &orig) {
if (this != &orig) {
delete [] pixels;
w = orig.w, h = orig.h;
@ -63,7 +63,7 @@ Bitmap<T, N> & Bitmap<T, N>::operator=(const Bitmap<T, N> &orig) {
#ifdef MSDFGEN_USE_CPP11
template <typename T, int N>
Bitmap<T, N> & Bitmap<T, N>::operator=(Bitmap<T, N> &&orig) {
Bitmap<T, N> &Bitmap<T, N>::operator=(Bitmap<T, N> &&orig) {
if (this != &orig) {
delete [] pixels;
pixels = orig.pixels;
@ -85,12 +85,12 @@ int Bitmap<T, N>::height() const {
}
template <typename T, int N>
T * Bitmap<T, N>::operator()(int x, int y) {
T *Bitmap<T, N>::operator()(int x, int y) {
return pixels+N*(w*y+x);
}
template <typename T, int N>
const T * Bitmap<T, N>::operator()(int x, int y) const {
const T *Bitmap<T, N>::operator()(int x, int y) const {
return pixels+N*(w*y+x);
}

View File

@ -17,7 +17,7 @@ struct BitmapRef {
inline BitmapRef() : pixels(NULL), width(0), height(0) { }
inline BitmapRef(T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
inline T * operator()(int x, int y) const {
inline T *operator()(int x, int y) const {
return pixels+N*(width*y+x);
}
@ -34,7 +34,7 @@ struct BitmapConstRef {
inline BitmapConstRef(const T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
inline BitmapConstRef(const BitmapRef<T, N> &orig) : pixels(orig.pixels), width(orig.width), height(orig.height) { }
inline const T * operator()(int x, int y) const {
inline const T *operator()(int x, int y) const {
return pixels+N*(width*y+x);
}

View File

@ -19,7 +19,7 @@ void Contour::addEdge(EdgeHolder &&edge) {
}
#endif
EdgeHolder & Contour::addEdge() {
EdgeHolder &Contour::addEdge() {
edges.resize(edges.size()+1);
return edges.back();
}

View File

@ -19,7 +19,7 @@ public:
void addEdge(EdgeHolder &&edge);
#endif
/// Creates a new edge in the contour and returns its reference.
EdgeHolder & addEdge();
EdgeHolder &addEdge();
/// Adjusts the bounding box to fit the contour.
void bound(double &l, double &b, double &r, double &t) const;
/// Adjusts the bounding box to fit the contour border's mitered corners.

View File

@ -33,7 +33,7 @@ EdgeHolder::~EdgeHolder() {
delete edgeSegment;
}
EdgeHolder & EdgeHolder::operator=(const EdgeHolder &orig) {
EdgeHolder &EdgeHolder::operator=(const EdgeHolder &orig) {
if (this != &orig) {
delete edgeSegment;
edgeSegment = orig.edgeSegment ? orig.edgeSegment->clone() : NULL;
@ -42,7 +42,7 @@ EdgeHolder & EdgeHolder::operator=(const EdgeHolder &orig) {
}
#ifdef MSDFGEN_USE_CPP11
EdgeHolder & EdgeHolder::operator=(EdgeHolder &&orig) {
EdgeHolder &EdgeHolder::operator=(EdgeHolder &&orig) {
if (this != &orig) {
delete edgeSegment;
edgeSegment = orig.edgeSegment;
@ -52,19 +52,19 @@ EdgeHolder & EdgeHolder::operator=(EdgeHolder &&orig) {
}
#endif
EdgeSegment & EdgeHolder::operator*() {
EdgeSegment &EdgeHolder::operator*() {
return *edgeSegment;
}
const EdgeSegment & EdgeHolder::operator*() const {
const EdgeSegment &EdgeHolder::operator*() const {
return *edgeSegment;
}
EdgeSegment * EdgeHolder::operator->() {
EdgeSegment *EdgeHolder::operator->() {
return edgeSegment;
}
const EdgeSegment * EdgeHolder::operator->() const {
const EdgeSegment *EdgeHolder::operator->() const {
return edgeSegment;
}

View File

@ -22,14 +22,14 @@ public:
EdgeHolder(EdgeHolder &&orig);
#endif
~EdgeHolder();
EdgeHolder & operator=(const EdgeHolder &orig);
EdgeHolder &operator=(const EdgeHolder &orig);
#ifdef MSDFGEN_USE_CPP11
EdgeHolder & operator=(EdgeHolder &&orig);
EdgeHolder &operator=(EdgeHolder &&orig);
#endif
EdgeSegment & operator*();
const EdgeSegment & operator*() const;
EdgeSegment * operator->();
const EdgeSegment * operator->() const;
EdgeSegment &operator*();
const EdgeSegment &operator*() const;
EdgeSegment *operator->();
const EdgeSegment *operator->() const;
operator EdgeSegment *();
operator const EdgeSegment *() const;

View File

@ -1,7 +1,7 @@
#pragma once
#include "Vector2.h"
#include "Vector2.hpp"
namespace msdfgen {

View File

@ -18,7 +18,7 @@ void Shape::addContour(Contour &&contour) {
}
#endif
Contour & Shape::addContour() {
Contour &Shape::addContour() {
contours.resize(contours.size()+1);
return contours.back();
}

View File

@ -32,7 +32,7 @@ public:
void addContour(Contour &&contour);
#endif
/// Adds a blank contour and returns its reference.
Contour & addContour();
Contour &addContour();
/// Normalizes the shape geometry for distance field generation.
void normalize();
/// Performs basic checks to determine if the object represents a valid shape.

View File

@ -2,7 +2,7 @@
#pragma once
#include <vector>
#include "Vector2.h"
#include "Vector2.hpp"
#include "edge-selectors.h"
#include "contour-combiners.h"

View File

@ -1,29 +0,0 @@
#include "SignedDistance.h"
#include <cmath>
#include <cfloat>
namespace msdfgen {
SignedDistance::SignedDistance() : distance(-DBL_MAX), dot(1) { }
SignedDistance::SignedDistance(double dist, double d) : distance(dist), dot(d) { }
bool operator<(SignedDistance a, SignedDistance b) {
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot < b.dot);
}
bool operator>(SignedDistance a, SignedDistance b) {
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot > b.dot);
}
bool operator<=(SignedDistance a, SignedDistance b) {
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot <= b.dot);
}
bool operator>=(SignedDistance a, SignedDistance b) {
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot >= b.dot);
}
}

View File

@ -1,23 +0,0 @@
#pragma once
namespace msdfgen {
/// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment.
class SignedDistance {
public:
double distance;
double dot;
SignedDistance();
SignedDistance(double dist, double d);
friend bool operator<(SignedDistance a, SignedDistance b);
friend bool operator>(SignedDistance a, SignedDistance b);
friend bool operator<=(SignedDistance a, SignedDistance b);
friend bool operator>=(SignedDistance a, SignedDistance b);
};
}

37
core/SignedDistance.hpp Normal file
View File

@ -0,0 +1,37 @@
#pragma once
#include <cmath>
#include <cfloat>
namespace msdfgen {
/// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment.
class SignedDistance {
public:
double distance;
double dot;
inline SignedDistance() : distance(-DBL_MAX), dot(0) { }
inline SignedDistance(double dist, double d) : distance(dist), dot(d) { }
};
inline bool operator<(const SignedDistance a, const SignedDistance b) {
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot < b.dot);
}
inline bool operator>(const SignedDistance a, const SignedDistance b) {
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot > b.dot);
}
inline bool operator<=(const SignedDistance a, const SignedDistance b) {
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot <= b.dot);
}
inline bool operator>=(const SignedDistance a, const SignedDistance b) {
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot >= b.dot);
}
}

View File

@ -1,149 +0,0 @@
#include "Vector2.h"
#include <cstddef>
#include <cmath>
namespace msdfgen {
Vector2::Vector2(double val) : x(val), y(val) { }
Vector2::Vector2(double x, double y) : x(x), y(y) { }
void Vector2::reset() {
x = 0, y = 0;
}
void Vector2::set(double x, double y) {
Vector2::x = x, Vector2::y = y;
}
double Vector2::length() const {
return sqrt(x*x+y*y);
}
double Vector2::direction() const {
return atan2(y, x);
}
Vector2 Vector2::normalize(bool allowZero) const {
double len = length();
if (len == 0)
return Vector2(0, !allowZero);
return Vector2(x/len, y/len);
}
Vector2 Vector2::getOrthogonal(bool polarity) const {
return polarity ? Vector2(-y, x) : Vector2(y, -x);
}
Vector2 Vector2::getOrthonormal(bool polarity, bool allowZero) const {
double len = length();
if (len == 0)
return polarity ? Vector2(0, !allowZero) : Vector2(0, -!allowZero);
return polarity ? Vector2(-y/len, x/len) : Vector2(y/len, -x/len);
}
Vector2 Vector2::project(const Vector2 &vector, bool positive) const {
Vector2 n = normalize(true);
double t = dotProduct(vector, n);
if (positive && t <= 0)
return Vector2();
return t*n;
}
Vector2::operator const void*() const {
return x || y ? this : NULL;
}
bool Vector2::operator!() const {
return !x && !y;
}
bool Vector2::operator==(const Vector2 &other) const {
return x == other.x && y == other.y;
}
bool Vector2::operator!=(const Vector2 &other) const {
return x != other.x || y != other.y;
}
Vector2 Vector2::operator+() const {
return *this;
}
Vector2 Vector2::operator-() const {
return Vector2(-x, -y);
}
Vector2 Vector2::operator+(const Vector2 &other) const {
return Vector2(x+other.x, y+other.y);
}
Vector2 Vector2::operator-(const Vector2 &other) const {
return Vector2(x-other.x, y-other.y);
}
Vector2 Vector2::operator*(const Vector2 &other) const {
return Vector2(x*other.x, y*other.y);
}
Vector2 Vector2::operator/(const Vector2 &other) const {
return Vector2(x/other.x, y/other.y);
}
Vector2 Vector2::operator*(double value) const {
return Vector2(x*value, y*value);
}
Vector2 Vector2::operator/(double value) const {
return Vector2(x/value, y/value);
}
Vector2 & Vector2::operator+=(const Vector2 &other) {
x += other.x, y += other.y;
return *this;
}
Vector2 & Vector2::operator-=(const Vector2 &other) {
x -= other.x, y -= other.y;
return *this;
}
Vector2 & Vector2::operator*=(const Vector2 &other) {
x *= other.x, y *= other.y;
return *this;
}
Vector2 & Vector2::operator/=(const Vector2 &other) {
x /= other.x, y /= other.y;
return *this;
}
Vector2 & Vector2::operator*=(double value) {
x *= value, y *= value;
return *this;
}
Vector2 & Vector2::operator/=(double value) {
x /= value, y /= value;
return *this;
}
double dotProduct(const Vector2 &a, const Vector2 &b) {
return a.x*b.x+a.y*b.y;
}
double crossProduct(const Vector2 &a, const Vector2 &b) {
return a.x*b.y-a.y*b.x;
}
Vector2 operator*(double value, const Vector2 &vector) {
return Vector2(value*vector.x, value*vector.y);
}
Vector2 operator/(double value, const Vector2 &vector) {
return Vector2(value/vector.x, value/vector.y);
}
}

View File

@ -1,63 +0,0 @@
#pragma once
namespace msdfgen {
/**
* A 2-dimensional euclidean vector with double precision.
* Implementation based on the Vector2 template from Artery Engine.
* @author Viktor Chlumsky
*/
struct Vector2 {
double x, y;
Vector2(double val = 0);
Vector2(double x, double y);
/// Sets the vector to zero.
void reset();
/// Sets individual elements of the vector.
void set(double x, double y);
/// Returns the vector's length.
double length() const;
/// Returns the angle of the vector in radians (atan2).
double direction() const;
/// Returns the normalized vector - one that has the same direction but unit length.
Vector2 normalize(bool allowZero = false) const;
/// Returns a vector with the same length that is orthogonal to this one.
Vector2 getOrthogonal(bool polarity = true) const;
/// Returns a vector with unit length that is orthogonal to this one.
Vector2 getOrthonormal(bool polarity = true, bool allowZero = false) const;
/// Returns a vector projected along this one.
Vector2 project(const Vector2 &vector, bool positive = false) const;
operator const void *() const;
bool operator!() const;
bool operator==(const Vector2 &other) const;
bool operator!=(const Vector2 &other) const;
Vector2 operator+() const;
Vector2 operator-() const;
Vector2 operator+(const Vector2 &other) const;
Vector2 operator-(const Vector2 &other) const;
Vector2 operator*(const Vector2 &other) const;
Vector2 operator/(const Vector2 &other) const;
Vector2 operator*(double value) const;
Vector2 operator/(double value) const;
Vector2 & operator+=(const Vector2 &other);
Vector2 & operator-=(const Vector2 &other);
Vector2 & operator*=(const Vector2 &other);
Vector2 & operator/=(const Vector2 &other);
Vector2 & operator*=(double value);
Vector2 & operator/=(double value);
/// Dot product of two vectors.
friend double dotProduct(const Vector2 &a, const Vector2 &b);
/// A special version of the cross product for 2D vectors (returns scalar value).
friend double crossProduct(const Vector2 &a, const Vector2 &b);
friend Vector2 operator*(double value, const Vector2 &vector);
friend Vector2 operator/(double value, const Vector2 &vector);
};
/// A vector may also represent a point, which shall be differentiated semantically using the alias Point2.
typedef Vector2 Point2;
}

167
core/Vector2.hpp Normal file
View File

@ -0,0 +1,167 @@
#pragma once
#include <cstddef>
#include <cmath>
namespace msdfgen {
/**
* A 2-dimensional euclidean floating-point vector.
* @author Viktor Chlumsky
*/
struct Vector2 {
double x, y;
inline Vector2(double val = 0) : x(val), y(val) { }
inline Vector2(double x, double y) : x(x), y(y) { }
/// Sets the vector to zero.
inline void reset() {
x = 0, y = 0;
}
/// Sets individual elements of the vector.
inline void set(double x, double y) {
this->x = x, this->y = y;
}
/// Returns the vector's squared length.
inline double squaredLength() const {
return x*x+y*y;
}
/// Returns the vector's length.
inline double length() const {
return sqrt(x*x+y*y);
}
/// Returns the normalized vector - one that has the same direction but unit length.
inline Vector2 normalize(bool allowZero = false) const {
if (double len = length())
return Vector2(x/len, y/len);
return Vector2(0, !allowZero);
}
/// Returns a vector with the same length that is orthogonal to this one.
inline Vector2 getOrthogonal(bool polarity = true) const {
return polarity ? Vector2(-y, x) : Vector2(y, -x);
}
/// Returns a vector with unit length that is orthogonal to this one.
inline Vector2 getOrthonormal(bool polarity = true, bool allowZero = false) const {
if (double len = length())
return polarity ? Vector2(-y/len, x/len) : Vector2(y/len, -x/len);
return polarity ? Vector2(0, !allowZero) : Vector2(0, -!allowZero);
}
#ifdef MSDFGEN_USE_CPP11
inline explicit operator bool() const {
return x || y;
}
#else
inline operator const void *() const {
return x || y ? this : NULL;
}
#endif
inline Vector2 &operator+=(const Vector2 other) {
x += other.x, y += other.y;
return *this;
}
inline Vector2 &operator-=(const Vector2 other) {
x -= other.x, y -= other.y;
return *this;
}
inline Vector2 &operator*=(const Vector2 other) {
x *= other.x, y *= other.y;
return *this;
}
inline Vector2 &operator/=(const Vector2 other) {
x /= other.x, y /= other.y;
return *this;
}
inline Vector2 &operator*=(double value) {
x *= value, y *= value;
return *this;
}
inline Vector2 &operator/=(double value) {
x /= value, y /= value;
return *this;
}
};
/// A vector may also represent a point, which shall be differentiated semantically using the alias Point2.
typedef Vector2 Point2;
/// Dot product of two vectors.
inline double dotProduct(const Vector2 a, const Vector2 b) {
return a.x*b.x+a.y*b.y;
}
/// A special version of the cross product for 2D vectors (returns scalar value).
inline double crossProduct(const Vector2 a, const Vector2 b) {
return a.x*b.y-a.y*b.x;
}
inline bool operator==(const Vector2 a, const Vector2 b) {
return a.x == b.x && a.y == b.y;
}
inline bool operator!=(const Vector2 a, const Vector2 b) {
return a.x != b.x || a.y != b.y;
}
inline Vector2 operator+(const Vector2 v) {
return v;
}
inline Vector2 operator-(const Vector2 v) {
return Vector2(-v.x, -v.y);
}
inline bool operator!(const Vector2 v) {
return !v.x && !v.y;
}
inline Vector2 operator+(const Vector2 a, const Vector2 b) {
return Vector2(a.x+b.x, a.y+b.y);
}
inline Vector2 operator-(const Vector2 a, const Vector2 b) {
return Vector2(a.x-b.x, a.y-b.y);
}
inline Vector2 operator*(const Vector2 a, const Vector2 b) {
return Vector2(a.x*b.x, a.y*b.y);
}
inline Vector2 operator/(const Vector2 a, const Vector2 b) {
return Vector2(a.x/b.x, a.y/b.y);
}
inline Vector2 operator*(double a, const Vector2 b) {
return Vector2(a*b.x, a*b.y);
}
inline Vector2 operator/(double a, const Vector2 b) {
return Vector2(a/b.x, a/b.y);
}
inline Vector2 operator*(const Vector2 a, double b) {
return Vector2(a.x*b, a.y*b);
}
inline Vector2 operator/(const Vector2 a, double b) {
return Vector2(a.x/b, a.y/b);
}
}

View File

@ -2,7 +2,7 @@
#pragma once
#include "arithmetics.hpp"
#include "Vector2.h"
#include "Vector2.hpp"
#include "BitmapRef.hpp"
namespace msdfgen {

View File

@ -33,7 +33,7 @@ void SimpleContourCombiner<EdgeSelector>::reset(const Point2 &p) {
}
template <class EdgeSelector>
EdgeSelector & SimpleContourCombiner<EdgeSelector>::edgeSelector(int) {
EdgeSelector &SimpleContourCombiner<EdgeSelector>::edgeSelector(int) {
return shapeEdgeSelector;
}
@ -63,7 +63,7 @@ void OverlappingContourCombiner<EdgeSelector>::reset(const Point2 &p) {
}
template <class EdgeSelector>
EdgeSelector & OverlappingContourCombiner<EdgeSelector>::edgeSelector(int i) {
EdgeSelector &OverlappingContourCombiner<EdgeSelector>::edgeSelector(int i) {
return edgeSelectors[i];
}

View File

@ -16,7 +16,7 @@ public:
explicit SimpleContourCombiner(const Shape &shape);
void reset(const Point2 &p);
EdgeSelector & edgeSelector(int i);
EdgeSelector &edgeSelector(int i);
DistanceType distance() const;
private:
@ -34,7 +34,7 @@ public:
explicit OverlappingContourCombiner(const Shape &shape);
void reset(const Point2 &p);
EdgeSelector & edgeSelector(int i);
EdgeSelector &edgeSelector(int i);
DistanceType distance() const;
private:

View File

@ -245,7 +245,7 @@ static double edgeToEdgeDistance(const EdgeSegment &a, const EdgeSegment &b, int
return minDistance;
}
static double splineToSplineDistance(EdgeSegment * const *edgeSegments, int aStart, int aEnd, int bStart, int bEnd, int precision) {
static double splineToSplineDistance(EdgeSegment *const *edgeSegments, int aStart, int aEnd, int bStart, int bEnd, int precision) {
double minDistance = DBL_MAX;
for (int ai = aStart; ai < aEnd; ++ai)
for (int bi = bStart; bi < bEnd && minDistance; ++bi) {
@ -255,7 +255,7 @@ static double splineToSplineDistance(EdgeSegment * const *edgeSegments, int aSta
return minDistance;
}
static void colorSecondDegreeGraph(int *coloring, const int * const *edgeMatrix, int vertexCount, unsigned long long seed) {
static void colorSecondDegreeGraph(int *coloring, const int *const *edgeMatrix, int vertexCount, unsigned long long seed) {
for (int i = 0; i < vertexCount; ++i) {
int possibleColors = 7;
for (int j = 0; j < i; ++j) {
@ -302,7 +302,7 @@ static int vertexPossibleColors(const int *coloring, const int *edgeVector, int
return 7&~usedColors;
}
static void uncolorSameNeighbors(std::queue<int> &uncolored, int *coloring, const int * const *edgeMatrix, int vertex, int vertexCount) {
static void uncolorSameNeighbors(std::queue<int> &uncolored, int *coloring, const int *const *edgeMatrix, int vertex, int vertexCount) {
for (int i = vertex+1; i < vertexCount; ++i) {
if (edgeMatrix[vertex][i] && coloring[i] == coloring[vertex]) {
coloring[i] = -1;
@ -317,7 +317,7 @@ static void uncolorSameNeighbors(std::queue<int> &uncolored, int *coloring, cons
}
}
static bool tryAddEdge(int *coloring, int * const *edgeMatrix, int vertexCount, int vertexA, int vertexB, int *coloringBuffer) {
static bool tryAddEdge(int *coloring, int *const *edgeMatrix, int vertexCount, int vertexA, int vertexB, int *coloringBuffer) {
static const int FIRST_POSSIBLE_COLOR[8] = { -1, 0, 1, 0, 2, 2, 1, 0 };
edgeMatrix[vertexA][vertexB] = 1;
edgeMatrix[vertexB][vertexA] = 1;
@ -359,7 +359,7 @@ static bool tryAddEdge(int *coloring, int * const *edgeMatrix, int vertexCount,
}
static int cmpDoublePtr(const void *a, const void *b) {
return sign(**reinterpret_cast<const double * const *>(a)-**reinterpret_cast<const double * const *>(b));
return sign(**reinterpret_cast<const double *const *>(a)-**reinterpret_cast<const double *const *>(b));
}
void edgeColoringByDistance(Shape &shape, double angleThreshold, unsigned long long seed) {

View File

@ -56,15 +56,15 @@ CubicSegment::CubicSegment(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor
p[3] = p3;
}
LinearSegment * LinearSegment::clone() const {
LinearSegment *LinearSegment::clone() const {
return new LinearSegment(p[0], p[1], color);
}
QuadraticSegment * QuadraticSegment::clone() const {
QuadraticSegment *QuadraticSegment::clone() const {
return new QuadraticSegment(p[0], p[1], p[2], color);
}
CubicSegment * CubicSegment::clone() const {
CubicSegment *CubicSegment::clone() const {
return new CubicSegment(p[0], p[1], p[2], p[3], color);
}
@ -80,15 +80,15 @@ int CubicSegment::type() const {
return (int) EDGE_TYPE;
}
const Point2 * LinearSegment::controlPoints() const {
const Point2 *LinearSegment::controlPoints() const {
return p;
}
const Point2 * QuadraticSegment::controlPoints() const {
const Point2 *QuadraticSegment::controlPoints() const {
return p;
}
const Point2 * CubicSegment::controlPoints() const {
const Point2 *CubicSegment::controlPoints() const {
return p;
}
@ -507,7 +507,7 @@ void CubicSegment::splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeS
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);
}
EdgeSegment * QuadraticSegment::convertToCubic() const {
EdgeSegment *QuadraticSegment::convertToCubic() const {
return new CubicSegment(p[0], mix(p[0], p[1], 2/3.), mix(p[1], p[2], 1/3.), p[2], color);
}

View File

@ -1,8 +1,8 @@
#pragma once
#include "Vector2.h"
#include "SignedDistance.h"
#include "Vector2.hpp"
#include "SignedDistance.hpp"
#include "EdgeColor.h"
namespace msdfgen {
@ -20,11 +20,11 @@ public:
EdgeSegment(EdgeColor edgeColor = WHITE) : color(edgeColor) { }
virtual ~EdgeSegment() { }
/// 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;
virtual const Point2 *controlPoints() const = 0;
/// Returns the point on the edge specified by the parameter (between 0 and 1).
virtual Point2 point(double param) const = 0;
/// Returns the direction the edge has at the point specified by the parameter.
@ -62,9 +62,9 @@ public:
Point2 p[2];
LinearSegment(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE);
LinearSegment * clone() const;
LinearSegment *clone() const;
int type() const;
const Point2 * controlPoints() const;
const Point2 *controlPoints() const;
Point2 point(double param) const;
Vector2 direction(double param) const;
Vector2 directionChange(double param) const;
@ -91,9 +91,9 @@ public:
Point2 p[3];
QuadraticSegment(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor = WHITE);
QuadraticSegment * clone() const;
QuadraticSegment *clone() const;
int type() const;
const Point2 * controlPoints() const;
const Point2 *controlPoints() const;
Point2 point(double param) const;
Vector2 direction(double param) const;
Vector2 directionChange(double param) const;
@ -107,7 +107,7 @@ public:
void moveEndPoint(Point2 to);
void splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeSegment *&part3) const;
EdgeSegment * convertToCubic() const;
EdgeSegment *convertToCubic() const;
};
@ -122,9 +122,9 @@ public:
Point2 p[4];
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;
const Point2 *controlPoints() const;
Point2 point(double param) const;
Vector2 direction(double param) const;
Vector2 directionChange(double param) const;

View File

@ -1,8 +1,8 @@
#pragma once
#include "Vector2.h"
#include "SignedDistance.h"
#include "Vector2.hpp"
#include "SignedDistance.hpp"
#include "edge-segments.h"
namespace msdfgen {

View File

@ -1,7 +1,7 @@
#pragma once
#include "Vector2.h"
#include "Vector2.hpp"
#include "Projection.h"
#include "Shape.h"
#include "BitmapRef.hpp"

View File

@ -1,7 +1,7 @@
#pragma once
#include "Vector2.h"
#include "Vector2.hpp"
#include "Shape.h"
#include "Projection.h"
#include "Scanline.h"

View File

@ -1,7 +1,7 @@
#pragma once
#include "Vector2.h"
#include "Vector2.hpp"
#include "BitmapRef.hpp"
namespace msdfgen {

View File

@ -1,7 +1,7 @@
#pragma once
#include "Vector2.h"
#include "Vector2.hpp"
#include "Shape.h"
#include "Projection.h"
#include "Scanline.h"

View File

@ -17,10 +17,10 @@ namespace msdfgen {
#define DOUBLE_TO_F16DOT16(x) FT_Fixed(65536.*x)
class FreetypeHandle {
friend FreetypeHandle * initializeFreetype();
friend FreetypeHandle *initializeFreetype();
friend void deinitializeFreetype(FreetypeHandle *library);
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
friend FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
friend FontHandle *loadFont(FreetypeHandle *library, const char *filename);
friend FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length);
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
friend bool setFontVariationAxis(FreetypeHandle *library, FontHandle *font, const char *name, double coordinate);
friend bool listFontVariationAxes(std::vector<FontVariationAxis> &axes, FreetypeHandle *library, FontHandle *font);
@ -31,9 +31,9 @@ class FreetypeHandle {
};
class FontHandle {
friend FontHandle * adoptFreetypeFont(FT_Face ftFace);
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
friend FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
friend FontHandle *adoptFreetypeFont(FT_Face ftFace);
friend FontHandle *loadFont(FreetypeHandle *library, const char *filename);
friend FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length);
friend void destroyFont(FontHandle *font);
friend bool getFontMetrics(FontMetrics &metrics, FontHandle *font);
friend bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font);
@ -100,7 +100,7 @@ unsigned GlyphIndex::getIndex() const {
return index;
}
FreetypeHandle * initializeFreetype() {
FreetypeHandle *initializeFreetype() {
FreetypeHandle *handle = new FreetypeHandle;
FT_Error error = FT_Init_FreeType(&handle->library);
if (error) {
@ -115,7 +115,7 @@ void deinitializeFreetype(FreetypeHandle *library) {
delete library;
}
FontHandle * adoptFreetypeFont(FT_Face ftFace) {
FontHandle *adoptFreetypeFont(FT_Face ftFace) {
FontHandle *handle = new FontHandle;
handle->face = ftFace;
handle->ownership = false;
@ -140,7 +140,7 @@ FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline) {
return error;
}
FontHandle * loadFont(FreetypeHandle *library, const char *filename) {
FontHandle *loadFont(FreetypeHandle *library, const char *filename) {
if (!library)
return NULL;
FontHandle *handle = new FontHandle;
@ -153,7 +153,7 @@ FontHandle * loadFont(FreetypeHandle *library, const char *filename) {
return handle;
}
FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length) {
FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length) {
if (!library)
return NULL;
FontHandle *handle = new FontHandle;

View File

@ -48,21 +48,21 @@ struct FontVariationAxis {
};
/// Initializes the FreeType library.
FreetypeHandle * initializeFreetype();
FreetypeHandle *initializeFreetype();
/// Deinitializes the FreeType library.
void deinitializeFreetype(FreetypeHandle *library);
#ifdef FT_LOAD_DEFAULT // FreeType included
/// Creates a FontHandle from FT_Face that was loaded by the user. destroyFont must still be called but will not affect the FT_Face.
FontHandle * adoptFreetypeFont(FT_Face ftFace);
FontHandle *adoptFreetypeFont(FT_Face ftFace);
/// Converts the geometry of FreeType's FT_Outline to a Shape object.
FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline);
#endif
/// Loads a font file and returns its handle.
FontHandle * loadFont(FreetypeHandle *library, const char *filename);
FontHandle *loadFont(FreetypeHandle *library, const char *filename);
/// Loads a font from binary data and returns its handle.
FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length);
/// Unloads a font file.
void destroyFont(FontHandle *font);
/// Outputs the metrics of a font file.

View File

@ -5,7 +5,7 @@
#include <skia/core/SkPath.h>
#include <skia/pathops/SkPathOps.h>
#include "../core/Vector2.h"
#include "../core/Vector2.hpp"
#include "../core/edge-segments.h"
#include "../core/Contour.h"

View File

@ -148,7 +148,7 @@ static bool parseUnicode(unicode_t &unicode, const char *arg) {
}
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
static FontHandle * loadVarFont(FreetypeHandle *library, const char *filename) {
static FontHandle *loadVarFont(FreetypeHandle *library, const char *filename) {
std::string buffer;
while (*filename && *filename != '?')
buffer.push_back(*filename++);
@ -240,7 +240,7 @@ static bool cmpExtension(const char *path, const char *ext) {
}
template <int N>
static const char * writeOutput(const BitmapConstRef<float, N> &bitmap, const char *filename, Format &format) {
static const char *writeOutput(const BitmapConstRef<float, N> &bitmap, const char *filename, Format &format) {
if (filename) {
if (format == AUTO) {
#if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG)
@ -329,11 +329,11 @@ static const char * writeOutput(const BitmapConstRef<float, N> &bitmap, const ch
#define SUFFIX_UNDERLINE
#endif
static const char * const versionText =
static const char *const versionText =
"MSDFgen v" MSDFGEN_VERSION_STRING TITLE_SUFFIX "\n"
"(c) 2016 - " STRINGIZE(MSDFGEN_COPYRIGHT_YEAR) " Viktor Chlumsky";
static const char * const helpText =
static const char *const helpText =
"\n"
"Multi-channel signed distance field generator by Viktor Chlumsky v" MSDFGEN_VERSION_STRING TITLE_SUFFIX "\n"
"------------------------------------------------------------------" VERSION_UNDERLINE SUFFIX_UNDERLINE "\n"
@ -485,7 +485,7 @@ static const char *errorCorrectionHelpText =
"\tDisplays this help.\n"
"\n";
int main(int argc, const char * const *argv) {
int main(int argc, const char *const *argv) {
#define ABORT(msg) do { fputs(msg "\n", stderr); return 1; } while (false)
// Parse command line arguments

View File

@ -16,7 +16,7 @@
*/
#include "core/arithmetics.hpp"
#include "core/Vector2.h"
#include "core/Vector2.hpp"
#include "core/Projection.h"
#include "core/Scanline.h"
#include "core/Shape.h"