re-enable complexity measurement

This commit is contained in:
be5invis 2021-02-27 21:10:44 -08:00
parent a81c477fab
commit d0862e25eb
3 changed files with 26 additions and 14 deletions

View file

@ -7,7 +7,6 @@ const util = require("util");
module.exports = finalizeGlyphs;
function finalizeGlyphs(para, glyphStore) {
suppressNaN(glyphStore);
const skew = Math.tan(((para.slopeAngle || 0) / 180) * Math.PI);
regulateGlyphStore(skew, glyphStore);
return glyphStore;
@ -15,14 +14,6 @@ function finalizeGlyphs(para, glyphStore) {
///////////////////////////////////////////////////////////////////////////////////////////////////
function suppressNaN(glyphStore) {
for (const g of glyphStore.glyphs()) {
// if (g.geometry) g.geometry.suppressNaN();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
function regulateGlyphStore(skew, glyphStore) {
for (const g of glyphStore.glyphs()) {
if (g.geometry.isEmpty()) continue;

View file

@ -83,8 +83,7 @@ export all : define [buildGlyphs para recursive recursiveCodes] : begin
return glyphObject
define [warnAboutBrokenGlyph g ensuredGlyphName saveGlyphName] : begin
local complexity 0
# if g.geometry : set complexity : g.geometry.suppressNaN
local complexity : g.geometry.measureComplexity
if ([not recursive] && complexity > 4096) : begin
console.log 'Possible broken shape found in' ensuredGlyphName 'Complexity' complexity

View file

@ -16,12 +16,18 @@ class GeometryBase {
isEmpty() {
return true;
}
measureComplexity() {
return 0;
}
}
class ContourGeometry extends GeometryBase {
constructor(points) {
super();
this.m_points = points;
this.m_points = [];
for (const z of points) {
this.m_points.push(Point.from(z.type, z));
}
}
asContours() {
if (this.isEmpty()) return [];
@ -36,6 +42,9 @@ class ContourGeometry extends GeometryBase {
isEmpty() {
return !this.m_points.length;
}
measureComplexity() {
return this.m_points.length;
}
}
class ReferenceGeometry extends GeometryBase {
@ -43,8 +52,8 @@ class ReferenceGeometry extends GeometryBase {
super();
if (!glyph || !glyph.geometry) throw new TypeError("Invalid glyph");
this.m_glyph = glyph;
this.m_x = x;
this.m_y = y;
this.m_x = x || 0;
this.m_y = y || 0;
}
unwrap() {
return new TransformedGeometry(
@ -68,6 +77,9 @@ class ReferenceGeometry extends GeometryBase {
if (!this.m_glyph || !this.m_glyph.geometry) return true;
return this.m_glyph.geometry.isEmpty();
}
measureComplexity() {
return this.m_glyph.geometry.measureComplexity();
}
}
class TaggedGeometry extends GeometryBase {
@ -89,6 +101,9 @@ class TaggedGeometry extends GeometryBase {
isEmpty() {
return this.m_geom.isEmpty();
}
measureComplexity() {
return this.m_geom.measureComplexity();
}
}
class TransformedGeometry extends GeometryBase {
@ -122,6 +137,9 @@ class TransformedGeometry extends GeometryBase {
isEmpty() {
return this.m_geom.isEmpty();
}
measureComplexity() {
return this.m_geom.measureComplexity();
}
}
class CombineGeometry extends GeometryBase {
@ -168,6 +186,10 @@ class CombineGeometry extends GeometryBase {
for (const part of this.m_parts) if (!part.isEmpty()) return false;
return true;
}
measureComplexity() {
let s = 0;
for (const part of this.m_parts) s += part.measureComplexity();
}
}
function combineWith(a, b) {