mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-11-12 03:17:55 +08:00
Minor cleanups in various corner code
This commit is contained in:
26
getchar.py
26
getchar.py
@@ -78,9 +78,9 @@ class Corner(object):
|
|||||||
print (self.point, other.point, features, result)
|
print (self.point, other.point, features, result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def merge(self, other):
|
def merge_into(self, other):
|
||||||
'''
|
'''
|
||||||
Merges this corner with the other corner, updating the other's data.
|
Merges this corner into the other corner, updating the other's data.
|
||||||
The merged corner takes the position of the sharper corner of the two.
|
The merged corner takes the position of the sharper corner of the two.
|
||||||
'''
|
'''
|
||||||
if abs(self.angle) > abs(other.angle):
|
if abs(self.angle) > abs(other.angle):
|
||||||
@@ -277,16 +277,16 @@ def get_bridges(corners):
|
|||||||
def get_corners(paths):
|
def get_corners(paths):
|
||||||
result = {}
|
result = {}
|
||||||
for i, path in enumerate(paths):
|
for i, path in enumerate(paths):
|
||||||
corners = [Corner(paths, (i, j)) for j in xrange(len(path))]
|
candidates = [Corner(paths, (i, j)) for j in xrange(len(path))]
|
||||||
j = 0
|
j = 0
|
||||||
while j < len(corners):
|
while j < len(candidates):
|
||||||
if corners[j].should_merge(corners[(j + 1) % len(corners)]):
|
next_j = (j + 1) % len(candidates)
|
||||||
corners[j].merge(corners[(j + 1) % len(corners)])
|
if candidates[j].should_merge(candidates[next_j]):
|
||||||
corners.pop(j)
|
candidates[j].merge_into(candidates[next_j])
|
||||||
|
candidates.pop(j)
|
||||||
else:
|
else:
|
||||||
j += 1
|
j += 1
|
||||||
corners = filter(lambda x: abs(x.angle) > MIN_CORNER_ANGLE, corners)
|
for corner in filter(lambda x: abs(x.angle) > MIN_CORNER_ANGLE, candidates):
|
||||||
for corner in corners:
|
|
||||||
result[corner.index] = corner
|
result[corner.index] = corner
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -299,13 +299,13 @@ def get_svg_path_data(glyph):
|
|||||||
return glyph[start + len(left):end].replace('\n', ' ')
|
return glyph[start + len(left):end].replace('\n', ' ')
|
||||||
|
|
||||||
def should_split(corners, index1, index2):
|
def should_split(corners, index1, index2):
|
||||||
start = corners[index1].point
|
base = corners[index1].point
|
||||||
diff = corners[index2].point - start
|
diff = corners[index2].point - base
|
||||||
for corner in corners.itervalues():
|
for corner in corners.itervalues():
|
||||||
if corner.index in (index1, index2):
|
if corner.index in (index1, index2):
|
||||||
continue
|
continue
|
||||||
t = ((corner.point.real - start.real)*diff.real +
|
t = ((corner.point.real - base.real)*diff.real +
|
||||||
(corner.point.imag - start.imag)*diff.imag)/(abs(diff)**2)
|
(corner.point.imag - base.imag)*diff.imag)/(abs(diff)**2)
|
||||||
distance_to_line = abs(corners[index1].point + t*diff - corner.point)
|
distance_to_line = abs(corners[index1].point + t*diff - corner.point)
|
||||||
if 0 < t < 1 and distance_to_line < MAX_CORNER_MERGE_DISTANCE:
|
if 0 < t < 1 and distance_to_line < MAX_CORNER_MERGE_DISTANCE:
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user