msdfgen: Update to version 1.9.2
This commit is contained in:
parent
c768189bd2
commit
346a4b4f50
|
@ -465,7 +465,7 @@ Collection of single-file libraries used in Godot components.
|
||||||
## msdfgen
|
## msdfgen
|
||||||
|
|
||||||
- Upstream: https://github.com/Chlumsky/msdfgen
|
- Upstream: https://github.com/Chlumsky/msdfgen
|
||||||
- Version: 1.9.1 (1b3b6b985094e6f12751177490add3ad11dd91a9, 2010)
|
- Version: 1.9.2 (64a91eec3ca3787e6f78b4c99fcd3052ad3e37c0, 2021)
|
||||||
- License: MIT
|
- License: MIT
|
||||||
|
|
||||||
Files extracted from the upstream source:
|
Files extracted from the upstream source:
|
||||||
|
|
|
@ -473,7 +473,7 @@ void edgeColoringByDistance(Shape &shape, double angleThreshold, unsigned long l
|
||||||
edgeMatrix[i] = &edgeMatrixStorage[i*splineCount];
|
edgeMatrix[i] = &edgeMatrixStorage[i*splineCount];
|
||||||
int nextEdge = 0;
|
int nextEdge = 0;
|
||||||
for (; nextEdge < graphEdgeCount && !*graphEdgeDistances[nextEdge]; ++nextEdge) {
|
for (; nextEdge < graphEdgeCount && !*graphEdgeDistances[nextEdge]; ++nextEdge) {
|
||||||
int elem = graphEdgeDistances[nextEdge]-distanceMatrixBase;
|
int elem = (int) (graphEdgeDistances[nextEdge]-distanceMatrixBase);
|
||||||
int row = elem/splineCount;
|
int row = elem/splineCount;
|
||||||
int col = elem%splineCount;
|
int col = elem%splineCount;
|
||||||
edgeMatrix[row][col] = 1;
|
edgeMatrix[row][col] = 1;
|
||||||
|
@ -483,7 +483,7 @@ void edgeColoringByDistance(Shape &shape, double angleThreshold, unsigned long l
|
||||||
std::vector<int> coloring(2*splineCount);
|
std::vector<int> coloring(2*splineCount);
|
||||||
colorSecondDegreeGraph(&coloring[0], &edgeMatrix[0], splineCount, seed);
|
colorSecondDegreeGraph(&coloring[0], &edgeMatrix[0], splineCount, seed);
|
||||||
for (; nextEdge < graphEdgeCount; ++nextEdge) {
|
for (; nextEdge < graphEdgeCount; ++nextEdge) {
|
||||||
int elem = graphEdgeDistances[nextEdge]-distanceMatrixBase;
|
int elem = (int) (graphEdgeDistances[nextEdge]-distanceMatrixBase);
|
||||||
tryAddEdge(&coloring[0], &edgeMatrix[0], splineCount, elem/splineCount, elem%splineCount, &coloring[splineCount]);
|
tryAddEdge(&coloring[0], &edgeMatrix[0], splineCount, elem/splineCount, elem%splineCount, &coloring[splineCount]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,17 +4,15 @@
|
||||||
#define _USE_MATH_DEFINES
|
#define _USE_MATH_DEFINES
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#define TOO_LARGE_RATIO 1e12
|
|
||||||
|
|
||||||
namespace msdfgen {
|
namespace msdfgen {
|
||||||
|
|
||||||
int solveQuadratic(double x[2], double a, double b, double c) {
|
int solveQuadratic(double x[2], double a, double b, double c) {
|
||||||
// a = 0 -> linear equation
|
// a == 0 -> linear equation
|
||||||
if (a == 0 || fabs(b)+fabs(c) > TOO_LARGE_RATIO*fabs(a)) {
|
if (a == 0 || fabs(b) > 1e12*fabs(a)) {
|
||||||
// a, b = 0 -> no solution
|
// a == 0, b == 0 -> no solution
|
||||||
if (b == 0 || fabs(c) > TOO_LARGE_RATIO*fabs(b)) {
|
if (b == 0) {
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
return -1; // 0 = 0
|
return -1; // 0 == 0
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
x[0] = -c/b;
|
x[0] = -c/b;
|
||||||
|
@ -35,41 +33,38 @@ int solveQuadratic(double x[2], double a, double b, double c) {
|
||||||
|
|
||||||
static int solveCubicNormed(double x[3], double a, double b, double c) {
|
static int solveCubicNormed(double x[3], double a, double b, double c) {
|
||||||
double a2 = a*a;
|
double a2 = a*a;
|
||||||
double q = (a2 - 3*b)/9;
|
double q = 1/9.*(a2-3*b);
|
||||||
double r = (a*(2*a2-9*b) + 27*c)/54;
|
double r = 1/54.*(a*(2*a2-9*b)+27*c);
|
||||||
double r2 = r*r;
|
double r2 = r*r;
|
||||||
double q3 = q*q*q;
|
double q3 = q*q*q;
|
||||||
double A, B;
|
a *= 1/3.;
|
||||||
if (r2 < q3) {
|
if (r2 < q3) {
|
||||||
double t = r/sqrt(q3);
|
double t = r/sqrt(q3);
|
||||||
if (t < -1) t = -1;
|
if (t < -1) t = -1;
|
||||||
if (t > 1) t = 1;
|
if (t > 1) t = 1;
|
||||||
t = acos(t);
|
t = acos(t);
|
||||||
a /= 3; q = -2*sqrt(q);
|
q = -2*sqrt(q);
|
||||||
x[0] = q*cos(t/3)-a;
|
x[0] = q*cos(1/3.*t)-a;
|
||||||
x[1] = q*cos((t+2*M_PI)/3)-a;
|
x[1] = q*cos(1/3.*(t+2*M_PI))-a;
|
||||||
x[2] = q*cos((t-2*M_PI)/3)-a;
|
x[2] = q*cos(1/3.*(t-2*M_PI))-a;
|
||||||
return 3;
|
return 3;
|
||||||
} else {
|
} else {
|
||||||
A = -pow(fabs(r)+sqrt(r2-q3), 1/3.);
|
double u = (r < 0 ? 1 : -1)*pow(fabs(r)+sqrt(r2-q3), 1/3.);
|
||||||
if (r < 0) A = -A;
|
double v = u == 0 ? 0 : q/u;
|
||||||
B = A == 0 ? 0 : q/A;
|
x[0] = (u+v)-a;
|
||||||
a /= 3;
|
if (u == v || fabs(u-v) < 1e-12*fabs(u+v)) {
|
||||||
x[0] = (A+B)-a;
|
x[1] = -.5*(u+v)-a;
|
||||||
x[1] = -0.5*(A+B)-a;
|
|
||||||
x[2] = 0.5*sqrt(3.)*(A-B);
|
|
||||||
if (fabs(x[2]) < 1e-14)
|
|
||||||
return 2;
|
return 2;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int solveCubic(double x[3], double a, double b, double c, double d) {
|
int solveCubic(double x[3], double a, double b, double c, double d) {
|
||||||
if (a != 0) {
|
if (a != 0) {
|
||||||
double bn = b/a, cn = c/a, dn = d/a;
|
double bn = b/a;
|
||||||
// Check that a isn't "almost zero"
|
if (fabs(bn) < 1e6) // Above this ratio, the numerical error gets larger than if we treated a as zero
|
||||||
if (fabs(bn) < TOO_LARGE_RATIO && fabs(cn) < TOO_LARGE_RATIO && fabs(dn) < TOO_LARGE_RATIO)
|
return solveCubicNormed(x, bn, c/a, d/a);
|
||||||
return solveCubicNormed(x, bn, cn, dn);
|
|
||||||
}
|
}
|
||||||
return solveQuadratic(x, b, c, d);
|
return solveQuadratic(x, b, c, d);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue