FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
plotdevice/tests/geometry.py at main · plotdevice/plotdevice · GitHub
plotdevice
plotdevice
Repository navigation
Code
Issues
10
(10)
Pull requests
4
(4)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
plotdevice
/
tests
/
geometry.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
251 lines (218 loc) · 6.81 KB
Breadcrumbs
plotdevice
/
tests
/
geometry.py
Copy path
File metadata and controls
251 lines (218 loc) · 6.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# encoding: utf-8
import
unittest
from
.
import
PlotDeviceTestCase
,
reference
from
plotdevice
import
*
class
GeometryTests
(
PlotDeviceTestCase
):
@
reference
(
'geometry/graphics_state7.png'
)
def
test_graphics_state7
(
self
):
# tut/Geometry (1)
size
(
280
,
80
)
rect
(
20
,
20
,
40
,
40
)
with
transform
():
rotate
(
45
)
rect
(
120
,
20
,
40
,
40
)
rect
(
220
,
20
,
40
,
40
)
@
reference
(
'geometry/math-angle.png'
)
def
test_math_angle
(
self
):
# tut/Geometry (2)
size
(
194
,
194
)
r
=
2.0
origin
=
Point
(
WIDTH
/
2
,
HEIGHT
/
2
)
for
i
in
range
(
5
):
pt
=
Point
(
random
(
WIDTH
),
random
(
HEIGHT
))
arc
(
pt
,
r
)
a
=
origin
.
angle
(
pt
)
with
transform
(
CORNER
):
translate
(
origin
.
x
,
origin
.
y
)
rotate
(
-
a
)
arrow
(
30
,
0
,
10
)
@
reference
(
'geometry/math-coordinates.png'
)
def
test_math_coordinates
(
self
):
# tut/Geometry (3)
size
(
194
,
194
)
r
=
2.0
origin
=
Point
(
WIDTH
/
2
,
HEIGHT
/
2
)
arc
(
origin
,
r
)
# a.k.a. arc(origin.x, origin.y, r)
for
i
in
range
(
10
):
a
=
36
*
i
pt
=
origin
.
coordinates
(
85
,
a
)
arc
(
pt
,
r
)
line
(
origin
,
pt
)
@
reference
(
'geometry/math-perpendicular.png'
)
def
test_math_perpendicular
(
self
):
# tut/Geometry (4)
size
(
194
,
194
)
stroke
(
0.5
)
and
nofill
()
path
=
oval
(
45
,
45
,
105
,
105
)
for
t
in
range
(
50
):
curve
=
path
.
point
(
t
/
50.0
)
a
=
curve
.
angle
(
curve
.
ctrl2
)
with
transform
(
CORNER
):
translate
(
curve
.
x
,
curve
.
y
)
rotate
(
-
a
+
90
)
# rotate by 90°
line
(
0
,
0
,
35
,
0
)
@
reference
(
'geometry/math-angles.png'
)
def
test_math_angles
(
self
):
# tut/Geometry (5)
size
(
109
,
177
)
with
stroke
(
0
),
nofill
():
arc
(
50
,
25
,
25
,
range
=
180
)
geometry
(
RADIANS
)
arc
(
50
,
75
,
25
,
range
=
pi
)
geometry
(
PERCENT
)
arc
(
50
,
125
,
25
,
range
=
.5
)
@
reference
(
'geometry/point-angle.png'
)
def
test_point_angle
(
self
):
# ref/Misc/types/Point
size
(
125
,
125
)
src
=
Point
(
25
,
75
)
dst
=
Point
(
75
,
25
)
theta
=
src
.
angle
(
dst
)
arc
(
src
,
4
,
fill
=
'red'
)
arc
(
dst
,
4
,
fill
=
'orange'
)
with
pen
(
dash
=
5
),
stroke
(
.5
),
nofill
():
arc
(
src
,
32
,
range
=
theta
)
self
.
assertAlmostEqual
(
theta
,
-
45.0
)
@
reference
(
'geometry/point-distance.png'
)
def
test_point_distance
(
self
):
# ref/Misc/types/Point
size
(
125
,
125
)
src
=
Point
(
25
,
25
)
dst
=
Point
(
100
,
100
)
length
=
src
.
distance
(
dst
)
arc
(
src
,
4
,
fill
=
'red'
)
arc
(
dst
,
4
,
fill
=
'orange'
)
with
pen
(
dash
=
5
),
stroke
(
.8
):
line
(
src
,
dst
)
self
.
assertAlmostEqual
(
length
,
106.066017178
)
@
reference
(
'geometry/point-reflect.png'
)
def
test_point_reflect
(
self
):
# ref/Misc/types/Point
size
(
125
,
125
)
origin
=
Point
(
50
,
50
)
src
=
Point
(
25
,
40
)
dst
=
origin
.
reflect
(
src
,
d
=
2.0
)
arc
(
src
,
4
,
fill
=
'red'
)
arc
(
dst
,
4
,
fill
=
'orange'
)
arc
(
origin
,
4
,
fill
=
.7
)
@
reference
(
'geometry/point-coordinates.png'
)
def
test_point_coordinates
(
self
):
# ref/Misc/types/Point
size
(
125
,
125
)
origin
=
Point
(
50
,
50
)
dst
=
origin
.
coordinates
(
50
,
45
)
arc
(
origin
,
4
,
fill
=
.7
)
arc
(
dst
,
4
,
fill
=
'orange'
)
with
pen
(
dash
=
3
),
stroke
(
.5
),
nofill
():
arc
(
origin
,
25
,
range
=
45
)
@
reference
(
'geometry/region-intersect.png'
)
def
test_region_intersect
(
self
):
# ref/Misc/types/Region
size
(
125
,
125
)
r1
=
Region
(
20
,
20
,
40
,
30
)
r2
=
Region
(
40
,
40
,
30
,
40
)
overlap
=
r1
.
intersect
(
r2
)
with
nofill
(),
stroke
(
.7
):
rect
(
r1
)
rect
(
r2
)
rect
(
overlap
,
stroke
=
'red'
,
dash
=
3
)
@
reference
(
'geometry/region-union.png'
)
def
test_region_union
(
self
):
# ref/Misc/types/Region
size
(
125
,
125
)
r1
=
Region
(
20
,
20
,
40
,
30
)
r2
=
Region
(
40
,
40
,
30
,
40
)
union
=
r1
.
union
(
r2
)
with
nofill
(),
stroke
(
.7
):
rect
(
r1
)
rect
(
r2
)
rect
(
union
,
stroke
=
'red'
,
dash
=
3
)
@
reference
(
'geometry/region-shift.png'
)
def
test_region_shift
(
self
):
# ref/Misc/types/Region
size
(
125
,
125
)
r
=
Region
(
20
,
20
,
40
,
30
)
shifted
=
r
.
shift
(
20
,
15
)
nofill
()
rect
(
r
,
stroke
=
.7
)
rect
(
shifted
,
stroke
=
'red'
,
dash
=
3
)
@
reference
(
'geometry/region-inset.png'
)
def
test_region_inset
(
self
):
# ref/Misc/types/Region
size
(
125
,
125
)
r
=
Region
(
30
,
40
,
60
,
40
)
shrunk
=
r
.
inset
(
20
,
5
)
grown
=
r
.
inset
(
-
20
)
nofill
()
rect
(
r
,
stroke
=
.7
)
rect
(
shrunk
,
stroke
=
'orange'
,
dash
=
3
)
rect
(
grown
,
stroke
=
'red'
,
dash
=
3
)
@
reference
(
'geometry/reset.jpg'
)
def
test_reset
(
self
):
# ref/Transform/commands/reset()
size
(
125
,
125
)
font
(
14
),
fill
(
0.2
)
rotate
(
90
)
text
(
"one"
,
30
,
80
)
text
(
"two"
,
45
,
80
)
reset
()
text
(
"three"
,
70
,
80
)
@
reference
(
'geometry/rotate.jpg'
)
def
test_rotate
(
self
):
# ref/Transform/commands/rotate()
size
(
125
,
125
)
fill
(
0.2
)
rotate
(
-
45
)
rect
(
30
,
30
,
40
,
40
)
@
reference
(
'geometry/scale.png'
)
def
test_scale
(
self
):
# ref/Transform/commands/scale()
size
(
125
,
125
)
fill
(
0.2
)
poly
(
30
,
30
,
20
)
scale
(
0.5
)
poly
(
70
,
30
,
20
)
@
reference
(
'geometry/skew.jpg'
)
def
test_skew
(
self
):
# ref/Transform/commands/skew()
size
(
125
,
125
)
fill
(
0.2
)
skew
(
10.0
)
rect
(
20
,
10
,
40
,
40
)
@
reference
(
'geometry/pop.png'
)
def
test_pop
(
self
):
# ref/Transform/commands/transform()
size
(
125
,
125
)
fill
(
0.2
)
fontsize
(
14
)
rotate
(
90
)
text
(
"one"
,
40
,
80
)
with
transform
():
rotate
(
-
90
)
text
(
"two"
,
40
,
40
)
text
(
"three"
,
50
,
80
)
@
reference
(
'geometry/translate.jpg'
)
def
test_translate
(
self
):
# ref/Transform/commands/translate()
size
(
125
,
125
)
fill
(
0.2
)
arc
(
10
,
10
,
20
)
translate
(
50
,
50
)
arc
(
10
,
10
,
20
)
@
reference
(
'geometry/push.png'
)
def
test_push
(
self
):
# ref/Transform/compat/push()
size
(
125
,
125
)
fill
(
0.2
)
fontsize
(
14
)
rotate
(
90
)
text
(
"one"
,
40
,
80
)
push
()
rotate
(
-
90
)
text
(
"two"
,
40
,
40
)
pop
()
text
(
"three"
,
50
,
80
)
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
defaultTestLoader
.
loadTestsFromTestCase
(
GeometryTests
))
return
suite
Back
|
FazBrowse Home
|
New Git URL