[varLib.featureVars] Add quadratic test
We get the optimal solution.
This commit is contained in:
parent
34241a819b
commit
f6bfc4139d
@ -4,34 +4,56 @@ from fontTools.varLib.featureVars import (
|
|||||||
overlayFeatureVariations)
|
overlayFeatureVariations)
|
||||||
|
|
||||||
|
|
||||||
def test_explosion(n = 10):
|
def test_linear(n = 10):
|
||||||
conds = []
|
conds = []
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
end = i / n
|
end = i / n
|
||||||
start = end - 1.
|
start = end - 1.
|
||||||
region = [{'axis': (start, end)}]
|
region = [{'X': (start, end)}]
|
||||||
subst = {'g%.2g'%start: 'g%.2g'%end}
|
subst = {'g%.2g'%start: 'g%.2g'%end}
|
||||||
conds.append((region, subst))
|
conds.append((region, subst))
|
||||||
overlaps = overlayFeatureVariations(conds)
|
overlaps = overlayFeatureVariations(conds)
|
||||||
assert len(overlaps) == 2 * n - 1, overlaps
|
assert len(overlaps) == 2 * n - 1, overlaps
|
||||||
return conds, overlaps
|
return conds, overlaps
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def test_quadratic(n = 10):
|
||||||
import sys
|
conds = []
|
||||||
from pprint import pprint
|
for i in range(1, n + 1):
|
||||||
quiet = False
|
region = [{'X': (0, i / n),
|
||||||
args = {}
|
'Y': (0, (n + 1 - i) / n)}]
|
||||||
if len(sys.argv) > 1:
|
subst = {str(i): str(n + 1 - i)}
|
||||||
if sys.argv[1] == '-q':
|
conds.append((region, subst))
|
||||||
quiet = True
|
overlaps = overlayFeatureVariations(conds)
|
||||||
del sys.argv[1]
|
assert len(overlaps) == n * (n + 1) // 2, overlaps
|
||||||
args['n'] = int(sys.argv[1])
|
return conds, overlaps
|
||||||
input, output = test_explosion(**args)
|
|
||||||
|
|
||||||
|
def run(test, n, quiet):
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("%s:" % test.__name__)
|
||||||
|
input, output = test(n)
|
||||||
if quiet:
|
if quiet:
|
||||||
print(len(output))
|
print(len(output))
|
||||||
else:
|
else:
|
||||||
|
print()
|
||||||
print("Input:")
|
print("Input:")
|
||||||
pprint(input)
|
pprint(input)
|
||||||
print()
|
print()
|
||||||
print("Output:")
|
print("Output:")
|
||||||
pprint(output)
|
pprint(output)
|
||||||
|
print()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import sys
|
||||||
|
from pprint import pprint
|
||||||
|
quiet = False
|
||||||
|
n = 3
|
||||||
|
if len(sys.argv) > 1 and sys.argv[1] == '-q':
|
||||||
|
quiet = True
|
||||||
|
del sys.argv[1]
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
n = int(sys.argv[1])
|
||||||
|
|
||||||
|
run(test_linear, n=n, quiet=quiet)
|
||||||
|
run(test_quadratic, n=n, quiet=quiet)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user