-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangle-checker-print_only.py
72 lines (58 loc) · 2.53 KB
/
angle-checker-print_only.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from math import *
# from fontTools.pens.cocoaPen import CocoaPen
from mojo.UI import UpdateCurrentGlyphView
class AngleChecker():
def __init__(self):
self.g = CurrentGlyph()
def checkAngles(self):
for contour in self.g:
prevPoint = contour[-1].points[-1]
for seg in contour:
if seg.type == "line":
currentPoint = seg.points[-1]
x1, y1 = prevPoint.x, prevPoint.y
x2, y2 = currentPoint.x, currentPoint.y
dx, dy = x2 - x1, y2 - y1
# lineAngle = abs(degrees(atan2(dy, dx)) + 90)
lineAngle = round(degrees(atan2(dy, dx)),2)
# # if lineAngle < 0:
# # lineAngle += 90
if lineAngle <= 0:
lineAngleAdjusted = abs(lineAngle + 90)
elif lineAngle > 0:
lineAngleAdjusted = abs(lineAngle - 90)
print x1, ",", y1, "|", x2, ",", y2, "|", "line angle:", lineAngle, "| line angle adj:", lineAngleAdjusted
# if lineAngle < -15 and lineAngle > -18:
# currentPoint.selected = True
#### simplify the math with this
tolerance = 1
rangeToCheck = 8
desAngle = 16
diff = abs(desAngle - lineAngleAdjusted)
if diff < tolerance:
print diff, "fine"
# self.draw((0,0,1))
elif diff < rangeToCheck:
print seg.points, diff, "not fine"
# self.draw((1,0,0))
else:
pass
prevPoint = seg.points[-1]
print "\n"
# def draw(self, color):
# # glyph = notification["glyph"]
# # scale = notification["scale"]
# width = 10
# lineCap = "round"
# lineJoin = "round"
# #path = glyph.naked().getRepresentation("defconAppKit.NSBezierPath")
# pen = CocoaPen(self.g.getParent())
# self.g.draw(pen)
# path = pen.path
# path.setLineWidth_(width)
# path.setLineCapStyle_(lineCap)
# path.setLineJoinStyle_(lineJoin)
# color.set()
# path.stroke()
AngleChecker().checkAngles()
# AngleChecker().draw()