-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuclidean.style
1008 lines (909 loc) · 26.2 KB
/
euclidean.style
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Original Style: https://github.com/penrose/penrose/blob/90e88c5a075d6a75698c49c2feb101275ae64af8/examples/geometry-domain/euclidean.sty
-- Original comp. functions: https://github.com/penrose/penrose/blob/90e88c5a075d6a75698c49c2feb101275ae64af8/src/Penrose/Functions.hs
Colors {
-- Keenan palette
black = #000000
white = #fff
darkpurple = #8c90c1
lightpurple = #d0d3e6
purple2 = rgba(0.106, 0.122, 0.54, 0.2)
verylightpurple = rgba(0.953, 0.957, 0.977, 1.0)
purple3 = rgba(0.557, 0.627, 0.769, 1.0)
midnightblue = rgba(0.14, 0.16, 0.52, 1.0)
none = none()
}
const {
pi = 3.14159
arrowheadSize = 0.65
strokeWidth = 1.75
textPadding = 7.0
textPadding2 = 40.0
repelWeight = 0.7 -- TODO: Reverted from 0.0
repelWeight2 = 0.5
fontSize = "35px"
containPadding = 50.0
rayLength = 100.0
pointRadius = 4.0
pointStroke = 0.0
thetaRadius = 30.0
circleRadius = 150.0
labelPadding = 30.0
minSegmentLength = 80.0
minLineLength = 200.0
}
--------------------------------------------------------------------------------
-- START of "euclidean.style"
--Plane
forall Plane p {
width = canvas.width - 1
height = canvas.height - 1
p.text = Equation {
center : ((width / 2.0) - const.textPadding2, (height / 2.0) - const.textPadding2)
string : p.label
fontSize : const.fontSize
}
-- inner: #f3f4f9, outer: #8e93c4
p.icon = Rectangle {
-- angle : 0.0
-- fillColor : Colors.purple2
fillColor : Colors.none -- TODO: arrange angle markers so plane can be opaque
strokeColor : Colors.purple3
strokeWidth : 2.0
center : (0.0, 0.0)
width : width
height : height
}
p.text above p.icon
}
--Point
forall Point p {
p.x = ?
p.y = ?
p.vec = (p.x, p.y)
p.color = Colors.black
p.icon = Circle {
center: p.vec
r : const.pointRadius
fillColor : Colors.black
strokeWidth : 0.0
strokeColor : Colors.black
}
p.text = Equation {
string : p.label
fillColor : Colors.black
fontSize : const.fontSize
}
ensure equal(signedDistance(p.text, p.vec), const.textPadding + const.pointRadius)
}
-- default: if `Point` is not on a `Plane`, the point should be below the plane to stay hidden
forall Point p
with Plane P {
p.iconOnPlane = ensure disjoint(p.icon, P.icon)
p.textOnPlane = ensure disjoint(p.text, P.icon)
}
forall Point p
with Plane P
where In(p, P) {
-- TODO: the problem is that this ensures the padding is const? Or is > padding okay?
-- There's a choice of whether to put padding on the point or the text for containment
override p.iconOnPlane = ensure contains(P.icon, p.icon, const.containPadding)
override p.textOnPlane = ensure contains(P.icon, p.text, 0.0)
p.icon above P.icon
p.text above P.icon
}
forall Point p, q, r
where Collinear(p, q, r) {
ensure collinear(p.icon.center, q.icon.center, r.icon.center)
-- HACK: make sure q is between p and r
-- TODO: should this be in Substance instead?
ensure inRange(q.icon.center[0], p.icon.center[0], r.icon.center[0])
ensure inRange(q.icon.center[1], p.icon.center[1], r.icon.center[1])
encourage notTooClose(p.icon, q.icon, const.repelWeight)
encourage notTooClose(q.icon, r.icon, const.repelWeight)
}
forall Point p
with Linelike l
where On(p, l) {
ensure equal(signedDistance(l.icon, p.vec), 0)
}
forall Point p
with Linelike l
where On(p, l); p has label {
ensure disjoint(l.icon, p.text)
}
--Linelike
forall Linelike l {
l.color = Colors.black
l.icon = Line {
start : (?, ?)
end : (?, ?)
strokeColor : l.color
strokeWidth : const.strokeWidth
style : "solid"
}
}
forall Ray r
where r := Ray(base, direction)
with Point base; Point direction {
r.start = base.vec
r.end = direction.vec
r.vec = direction.vec - base.vec
override r.icon = Line {
start : base.icon.center
end : ptOnLine(base.vec, direction.vec, norm(r.vec) + 40.)
strokeColor : r.color
strokeWidth : const.strokeWidth
style : "solid"
endArrowhead : "straight"
endArrowheadSize: const.arrowheadSize
}
-- labeling
ensure disjoint(r.icon, base.text)
ensure disjoint(r.icon, direction.text)
}
forall Ray r {
r.length = const.rayLength
}
forall Ray r
with Angle theta; Point x; Point y; Point z
where r := Bisector(theta); theta := InteriorAngle(y, x, z) {
-- find the vector for the bisector ray
xy = normalize(y.vec - x.vec)
xz = normalize(z.vec - x.vec)
r_vec = xy + xz
-- change from generic `Linelike` shape to a specific shape for `Ray`
override r.icon = Line {
start: x.vec
end: (r.length * normalize(r_vec)) + x.vec
strokeWidth : const.strokeWidth
strokeColor : Colors.black
endArrowhead: "straight"
endArrowheadSize : const.arrowheadSize
}
r.icon below x.icon
}
forall Line l
where l := Line(p, q)
with Point p; Point q {
l.start = p.vec
l.end = q.vec
l.vec = q.vec - p.vec
override l.icon = Line {
start : ptOnLine(p.vec,q.vec, -40.)
end : ptOnLine(p.vec, q.vec, norm(l.vec) + 40.)
strokeColor : l.color
strokeWidth : const.strokeWidth
style : "solid"
endArrowhead : "straight"
startArrowhead: "straight"
startArrowheadSize: const.arrowheadSize
endArrowheadSize: const.arrowheadSize
}
-- edge case
ensure lessThan(const.minLineLength, norm(l.vec))
-- labeling
ensure disjoint(l.icon, p.text)
ensure disjoint(l.icon, q.text)
}
forall Linelike l1, l2 -- should this work with rays and lines?
where ParallelMarker1(l1, l2) {
l1.tick1 = Path {
d : pathFromPoints("open", chevron(l1.icon, 20.))
strokeWidth : 2.0
strokeColor : Colors.black
fillColor : Colors.none
}
l2.tick1 = Path {
d : pathFromPoints("open", chevron(l2.icon, 20.))
strokeWidth : 2.0
strokeColor : Colors.black
fillColor : Colors.none
}
}
forall Linelike l1, l2
where Parallel(l1, l2) {
-- the dot product of the unit vectors of parallel lines is 1
-- HACK: scaling to 10000s for convergence
ensure equal(10000, dot(normalize(l1.vec), normalize(l2.vec)) * 10000)
}
--Segment
forall Segment e
where e := Segment(p, q)
with Point p; Point q {
e.vec = [q.x - p.x, q.y - p.y]
e.start = p.vec
e.end = q.vec
override e.icon = Line {
start : p.icon.center
end : q.icon.center
strokeColor : e.color
strokeWidth : const.strokeWidth
style : "solid"
}
p.icon above e.icon
q.icon above e.icon
-- edge case
ensure lessThan(const.minSegmentLength, norm(e.vec))
-- labeling
ensure disjoint(p.text, e.icon)
ensure disjoint(q.text, e.icon)
}
forall Segment e; Plane p {
e.icon above p.icon
}
forall Linelike s, t
where EqualLength(s, t) {
ensure equal(vdist(s.icon.start, s.icon.end), vdist(t.icon.start, t.icon.end))
}
--TODO eventually this should also provide an equal length marker since it is bisecting the segment
forall Segment s
where s := PerpendicularBisector(s2, p)
with Segment s2; Point p {
override s.icon = Line {
start : p.icon.center
end : midpoint(s2.icon.start, s2.icon.end)
strokeColor : s.color
strokeWidth : const.strokeWidth
style : "solid"
}
startA = ptOnLine(s.icon.end, s.icon.start, const.thetaRadius)
endA = ptOnLine(s.icon.end, s2.icon.end, const.thetaRadius)
sweepA = arcSweepFlag(s.icon.end, startA, endA)
s.mark = Path {
d : pathFromPoints("open", [ptOnLine(s.icon.end, s.icon.start, 20.), innerPointOffset(s.icon.end, s.icon.start, s2.icon.end, 20.), ptOnLine(s.icon.end, s2.icon.end, 20.)])
strokeWidth : 2.0
strokeColor : Colors.black
fillColor : Colors.none
}
ensure perpendicular(s.icon.start, s.icon.end, s2.icon.end)
}
forall Segment s
where s := PerpendicularBisectorLabelPts(s2, p1, p2)
with Segment s2; Point p1, p2 {
override p2.vec = midpoint(s2.icon.start, s2.icon.end)
override s.icon = Line {
start : p1.icon.center
end : p2.vec
strokeColor : s.color
strokeWidth : const.strokeWidth
style : "solid"
}
startA = ptOnLine(s.icon.end, s.icon.start, const.thetaRadius)
endA = ptOnLine(s.icon.end, s2.icon.end, const.thetaRadius)
sweepA = arcSweepFlag(s.icon.end, startA, endA)
s.mark = Path {
d : pathFromPoints("open", [ptOnLine(s.icon.end, s.icon.start, 20.), innerPointOffset(s.icon.end, s.icon.start, s2.icon.end, 20.), ptOnLine(s.icon.end, s2.icon.end, 20.)])
strokeWidth : 2.0
strokeColor : Colors.black
fillColor : Colors.none
}
ensure perpendicular(s.icon.start, s.icon.end, s2.icon.end)
}
forall Linelike s, t
where EqualLengthMarker(s, t) as e {
e.equivGroup = match_id
override s.tick = Path {
d : ticksOnLine(s.icon.start, s.icon.end, 15., e.equivGroup, 10.)
strokeWidth : 2.0
strokeColor : Colors.black
fillColor: Colors.none
}
override t.tick = Path {
d : ticksOnLine(t.icon.start, t.icon.end, 15., e.equivGroup, 10.)
strokeWidth : 2.0
strokeColor : Colors.black
fillColor: Colors.none
}
s.tick above s.icon
t.tick above t.icon
}
-- HACK: since we cannot handle transitive predicates and don't allow recursive expressions, we redeclare the shapes so the tick counts are the same
forall Linelike s, t, u
where EqualLengthMarker(s, t) as e1; EqualLengthMarker(t, u) as e2 {
minEquivGroup = min(e1.equivGroup, e2.equivGroup)
-- minEquivGroup = e2.equivGroup
override s.tick.d = ticksOnLine(s.icon.start, s.icon.end, 15., minEquivGroup, 10.)
override u.tick.d = ticksOnLine(u.icon.start, u.icon.end, 15., minEquivGroup, 10.)
override t.tick.d = ticksOnLine(t.icon.start, t.icon.end, 15., minEquivGroup, 10.)
}
--Angle
forall Angle theta
where theta := InteriorAngle(p, q, r)
with Point p; Point q; Point r {
theta.p = p.vec
theta.q = q.vec
theta.r = r.vec
theta.color = #000
theta.side1 = Line {
start : p.icon.center
end : q.icon.center
strokeColor : theta.color
strokeWidth : const.strokeWidth
style : "solid"
}
theta.side2 = Line {
start : q.icon.center
end : r.icon.center
strokeColor : theta.color
strokeWidth : const.strokeWidth
style : "solid"
}
theta.radius = const.thetaRadius
encourage nonDegenerateAngle(p.icon, q.icon, r.icon)
theta.side1 below p.icon, q.icon
theta.side2 below q.icon, r.icon
}
forall Angle theta
where theta := InteriorAngle(p, q, r); theta has label
with Point p; Point q; Point r {
padding = const.textPadding + const.pointRadius + theta.text.width
labelDir = normalize((p.vec - q.vec) + (r.vec - q.vec))
theta.text = Equation {
string : theta.label
fillColor : Colors.black
fontSize : const.fontSize
center: q.vec + labelDir*padding
}
}
forall Angle a, b
where EqualAngleMarker(a, b) {
--find points from p->q, then q->r for each vector. draw vectors for each
startA = ptOnLine(a.q, a.p, a.radius)
endA = ptOnLine(a.q, a.r, a.radius)
sweepA = arcSweepFlag(a.q, startA, endA)
startB = ptOnLine(b.q, b.p, b.radius)
endB = ptOnLine(b.q, b.r, b.radius)
sweepB = arcSweepFlag(b.q, startB, endB)
spacing = 10
override a.mark = Path {
d : repeatedArcs(startA, endA, a.p, a.r, (a.radius, a.radius), match_id, spacing, sweepA)
strokeWidth : 2.0
strokeColor : Colors.black
fillColor: Colors.none
}
override b.mark = Path {
d : repeatedArcs(startB, endB, b.p, b.r, (a.radius, a.radius), match_id, spacing, sweepB)
strokeWidth : 2.0
strokeColor : Colors.black
fillColor: Colors.none
}
}
forall Angle a, b
where EqualAngle(a, b) {
-- make sure angle a is equal to angle b
-- HACK: increase the magnitude of angles
weight = 100
angleA = angleBetween(a.p - a.q, a.r - a.q) * weight
angleB = angleBetween(b.p - b.q, b.r - b.q) * weight
ensure equal(angleA, angleB)
}
forall Angle a
where RightUnmarked(a) {
-- ensure perpendicular(a.p, a.q, a.r)
vec2 u = a.p - a.q
vec2 v = a.r - a.q
ensure equal(0, dot(u, v))
}
forall Angle a
where RightMarked(a) {
--render half square path of size a.radius
markSize = 10
override a.mark = Path {
d : pathFromPoints("open", [ptOnLine(a.q, a.p, markSize), innerPointOffset(a.q, a.p, a.r, markSize), ptOnLine(a.q, a.r, markSize)])
strokeWidth : 2.0
strokeColor : #000
fillColor : Colors.none
}
vec2 u = a.p - a.q
vec2 v = a.r - a.q
ensure equal(0, dot(u, v))
}
forall Angle a
where Acute(a) {
ensure inRange(angleBetween(a.p - a.q, a.r - a.q), 0, MathPI()/2)
}
forall Angle a
where Obtuse(a) {
ensure inRange(angleBetween(a.p - a.q, a.r - a.q), MathPI()/2, MathPI())
}
forall Triangle t; Plane P
where t := Triangle(p, q, r)
with Point p; Point q; Point r {
t.PQ above P.icon
t.QR above P.icon
t.RP above P.icon
t.icon above P.icon
}
forall Triangle t
where t := Triangle(p, q, r)
with Point p; Point q; Point r {
t.color = Colors.black
t.PQ = Line {
start : p.icon.center
end : q.icon.center
strokeColor : t.color
strokeWidth : const.strokeWidth
style : "solid"
}
t.QR = Line {
start : q.icon.center
end : r.icon.center
strokeColor : t.color
strokeWidth : const.strokeWidth
style : "solid"
}
t.RP = Line {
start : r.icon.center
end : p.icon.center
strokeColor : t.color
strokeWidth : const.strokeWidth
style : "solid"
}
t.icon = Path {
d: pathFromPoints("closed", [p.vec, q.vec, r.vec])
fillColor: none()
}
ensure lessThan(const.minSegmentLength, length(t.PQ))
ensure lessThan(const.minSegmentLength, length(t.QR))
ensure lessThan(const.minSegmentLength, length(t.RP))
ensure disjoint(t.icon, p.text)
ensure disjoint(t.icon, q.text)
ensure disjoint(t.icon, r.text)
t.PQ below p.icon
t.PQ below q.icon
t.QR below q.icon
t.QR below r.icon
t.RP below r.icon
t.RP below p.icon
}
forall Point p
with Triangle T; Point t1, t2, t3
where T := Triangle(t1, t2, t3); Incenter(p, T) {
override p.vec = incenter(t1.vec, t2.vec, t3.vec)
clr = setOpacity(Colors.darkpurple, 0.6)
T.incenterIcon = Circle {
center : p.vec
r : inradius(t1.vec, t2.vec, t3.vec) - const.strokeWidth
strokeWidth : const.strokeWidth
strokeColor : clr
strokeStyle: "dashed"
fillColor : Colors.none
}
T.incenterIcon below t1.icon
T.incenterIcon below t2.icon
T.incenterIcon below t3.icon
}
forall Point p
where Circumcenter(p, T)
with Triangle T {
clr = Colors.darkpurple
override p.icon = Circle {
center : p.vec
r : const.pointRadius
strokeWidth : const.strokeWidth
strokeColor : clr
fillColor : clr
}
p.icon above T.PQ
p.icon above T.QR
p.icon above T.RP
T.icon = Circle {
center : p.vec
r : ?
strokeWidth : const.strokeWidth
strokeColor : clr
fillColor : Colors.none
strokeStyle: "dashed"
}
ensure equal(norm(T.PQ.start - p.vec), T.icon.r)
ensure equal(norm(T.QR.start - p.vec), T.icon.r)
ensure equal(norm(T.RP.start - p.vec), T.icon.r)
encourage repelPt(const.repelWeight, T.PQ.start, T.QR.start)
encourage repelPt(const.repelWeight, T.QR.start, T.RP.start)
}
forall Point p
where Centroid(p, T)
with Triangle T {
clr = setOpacity(Colors.darkpurple, 0.6)
override p.vec = vmul(1/3, T.PQ.start + T.QR.start + T.RP.start)
override p.icon = Circle {
center : p.vec
r : const.pointRadius
strokeWidth : const.strokeWidth
strokeColor : clr
fillColor : clr
}
override T.icon = Line {
start : T.PQ.start
end : midpoint(T.QR.start, T.QR.end)
strokeColor : clr
strokeWidth : const.strokeWidth
style : "solid"
}
override T.line2 = Line {
start : T.QR.start
end : midpoint(T.RP.start, T.RP.end)
strokeColor : clr
strokeWidth : const.strokeWidth
style : "solid"
}
override T.icon3 = Line {
start : T.RP.start
end : midpoint(T.PQ.start, T.PQ.end)
strokeColor : clr
strokeWidth : const.strokeWidth
style : "solid"
}
}
forall Point p
where Orthocenter(p, T)
with Triangle T {
clr = setOpacity(Colors.darkpurple, 0.6)
T.icon = Line {
start : (?, ?)
end : p.vec
strokeColor : clr
strokeWidth : const.strokeWidth
style : "solid"
}
T.icon2 = Line {
start : (?, ?)
end : p.vec
strokeColor : clr
strokeWidth : const.strokeWidth
style : "solid"
}
T.icon3 = Line {
start : (?, ?)
end : p.vec
strokeColor : clr
strokeWidth : const.strokeWidth
style : "solid"
}
-- TODO make it so that predicates can reference other predicates. 3/4 of these are copy-pasted from the Collinear predicate
ensure collinear(T.PQ.start, T.icon.start, T.PQ.end)
ensure collinear(T.QR.start, T.icon2.start, T.QR.end)
ensure collinear(T.RP.start, T.icon3.start, T.RP.end)
ensure perpendicular(T.PQ.start, T.icon.start, p.vec)
ensure perpendicular(T.QR.start, T.icon2.start, p.vec)
ensure perpendicular(T.RP.start, T.icon3.start, p.vec)
encourage repelPt(const.repelWeight, T.PQ.start, T.icon.start)
encourage repelPt(const.repelWeight, T.PQ.end, T.icon.start)
encourage repelPt(const.repelWeight, T.QR.start, T.icon2.start)
encourage repelPt(const.repelWeight, T.QR.end, T.icon2.start)
encourage repelPt(const.repelWeight, T.RP.start, T.icon3.start)
encourage repelPt(const.repelWeight, T.RP.end, T.icon3.start)
}
--Rectangle
-- -- Should the rectangle be constructed from the points, or vice versa?
forall Rectangle R
where R := Rectangle(p, q, r, s)
with Point p; Point q; Point r; Point s {
override R.color = Colors.none
override R.icon = Path {
d : pathFromPoints("closed", [p.icon.center, q.icon.center, r.icon.center, s.icon.center])
strokeWidth : const.strokeWidth
fillColor : R.color
strokeColor : Colors.black
}
ensure equal(vdist(p.icon.center, q.icon.center), vdist(r.icon.center, s.icon.center))
ensure equal(vdist(p.icon.center, s.icon.center), vdist(q.icon.center, r.icon.center))
ensure perpendicular(p.icon.center, q.icon.center, r.icon.center)
ensure perpendicular(q.icon.center, s.icon.center, r.icon.center)
-- R.icon above P.icon
}
forall Quadrilateral Q
where Q := Quadrilateral(p, q, r, s)
with Point p; Point q; Point r; Point s {
Q.p = p.icon.center
Q.q = q.icon.center
Q.r = r.icon.center
Q.s = s.icon.center
override Q.color = Colors.black
Q.side1 = Line {
start : Q.p
end : Q.q
strokeColor : Q.color
strokeWidth : const.strokeWidth
style : "solid"
}
Q.side2 = Line {
start : Q.r
end : Q.q
strokeColor : Q.color
strokeWidth : const.strokeWidth
style : "solid"
}
Q.side3 = Line {
start : Q.s
end : Q.r
strokeColor : Q.color
strokeWidth : const.strokeWidth
style : "solid"
}
Q.side4 = Line {
start : Q.p
end : Q.s
strokeColor : Q.color
strokeWidth : const.strokeWidth
style : "solid"
}
Q.labelContainer = Path {
d: pathFromPoints("closed", [Q.p, Q.q, Q.r, Q.s])
fillColor: none()
}
-- TODO: check if the points actually have labels
ensure disjoint(p.text, Q.labelContainer)
ensure disjoint(q.text, Q.labelContainer)
ensure disjoint(r.text, Q.labelContainer)
ensure disjoint(s.text, Q.labelContainer)
-- ensure all sides are visible
ensure lessThan(const.minSegmentLength, norm(Q.p - Q.q))
ensure lessThan(const.minSegmentLength, norm(Q.q - Q.r))
ensure lessThan(const.minSegmentLength, norm(Q.r - Q.s))
ensure lessThan(const.minSegmentLength, norm(Q.s - Q.p))
ensure lessThan(const.minSegmentLength, norm(Q.r - Q.p))
ensure lessThan(const.minSegmentLength, norm(Q.s - Q.q))
}
--FUNCTIONS
forall Segment s
with Triangle T; Point p, q, r, a, b
where s := MidSegment(T, a, b); T := Triangle(p, q, r) {
override a.vec = midpoint(q.vec, r.vec)
override b.vec = midpoint(r.vec, p.vec)
override s.icon = Line {
start : a.vec
end : b.vec
strokeColor : s.color
strokeWidth : const.strokeWidth
style : "solid"
}
}
forall Point p
where p := Midpoint(l)
with Linelike l {
override p.vec = midpoint(l.icon.start, l.icon.end)
}
forall Point p
where Midpoint(l, p)
with Linelike l {
override p.vec = midpoint(l.icon.start, l.icon.end)
}
forall Point p
where Midpoint(l, p); p has label
with Linelike l {
override p.vec = midpoint(l.icon.start, l.icon.end)
ensure disjoint(p.text, l.icon)
}
-- TODO sometimes bisector becomes a scaled version of either side length PQ or QR of angle PQR
forall Linelike s
where AngleBisector(a, s)
with Angle a; Point p {
weight = 10000
angleA = angleBetween(a.p - a.q, s.end - a.q) * weight
angleB = angleBetween(s.end - a.q, a.r - a.q) * weight
ensure equal(angleA, angleB)
-- HACK: make sure the bisector end point is between angle end points. Might be too specific
ensure inRange(s.end[0], a.p[0], a.r[0])
ensure inRange(s.end[1], a.p[1], a.r[1])
-- FIXME: NaN when using the following
-- v1 = normalize(a.p - a.q)
-- v2 = normalize(s.end - a.q)
-- v3 = normalize(a.r - a.q)
-- angleA = angleFrom(v1, v2) * weight
-- angleB = angleFrom(v2, v3) * weight
}
forall Circle c {
c.radius = const.circleRadius
c.vec = (?, ?)
c.icon = Circle {
center : c.vec
r : c.radius
strokeWidth : const.strokeWidth
strokeColor : Colors.black
fillColor : Colors.none
}
}
forall Circle c
where c := CircleR(p, q)
with Point p, q {
override c.radius = vdist(p.vec, q.vec)
override c.vec = p.icon.center
override c.icon = Circle {
center : c.vec
r : c.radius
strokeWidth : const.strokeWidth
strokeColor : Colors.black
fillColor : Colors.none
}
}
-- TODO this can be reimplemented when issue #621 is resolved
-- Circle c
-- where c := CircleD(p, q)
-- with Point p, q {
-- override c.radius = vdist(p.vec, q.vec) / 2
-- }
forall Segment s
where s := Chord(c, p, q)
with Circle c; Point p, q {
override s.vec = q.vec - p.vec
override s.icon = Line {
start : p.icon.center
end : q.icon.center
strokeColor : s.color
strokeWidth : const.strokeWidth
style : "solid"
}
p.icon above c.icon
q.icon above c.icon
ensure equal(norm(p.vec - c.vec), c.radius)
ensure equal(norm(q.vec - c.vec), c.radius)
}
forall Segment s
where s := Chord(c, p, q); p has label; q has label
with Circle c; Point p, q {
ensure disjoint(c.icon, p.text)
ensure disjoint(c.icon, q.text)
}
forall Segment s
where s := Radius(c, p)
with Circle c; Point p {
override s.vec = p.vec - c.vec
override s.icon = Line {
start : c.vec
end : p.icon.center
strokeColor : Colors.black
strokeWidth : const.strokeWidth
style : "solid"
}
p.icon above c.icon
ensure equal(norm(c.vec - p.vec), c.radius)
}
forall Segment s
where s := Radius(c, p); p has label
with Circle c; Point p {
ensure disjoint(p.text, c.icon)
}
forall Segment s
where s := Diameter(c, p, q)
with Circle c; Point p, q {
override s.vec = q.vec - p.vec
override s.icon = Line {
start : p.icon.center
end : q.icon.center
strokeWidth : const.strokeWidth
style : "solid"
strokeColor : Colors.black
}
p.icon above c.icon
q.icon above c.icon
ensure equal(norm(midpoint(p.vec, q.vec) - c.icon.center), 0)
ensure equal(c.icon.r * 2, norm(s.vec))
}
forall Point p
where OnCircle(c, p)
with Circle c {
ensure equal(norm(c.vec - p.vec), c.radius)
}
forall Point p
where OnCircle(c, p); p has label
with Circle c {
ensure disjoint(p.text, c.icon)
}
forall Point p
where CircleCenter(c, p)
with Circle c {
override p.vec = c.vec
}
-- END of "euclidean.style"
--------------------------------------------------------------------------------
--Plane
forall Plane p {
dim = 700.0
override p.text.center = ((dim / 2.0) - const.textPadding2, (dim / 2.0) - const.textPadding2)
-- inner:
override p.icon = Rectangle {
fillColor : #f3f4f9
strokeColor : #8e93c4
strokeWidth : 2.0
center : (0.0, 0.0)
width : dim
height : dim
}
p.text above p.icon
}
forall Triangle t
where t := Triangle(p, q, r)
with Point p; Point q; Point r {
t.strokeWidth = 0.0
override t.PQ = Line {
start : p.icon.center
end : q.icon.center
strokeWidth : t.strokeWidth
}
override t.QR = Line {
start : q.icon.center
end : r.icon.center
strokeWidth : t.strokeWidth
}
override t.RP = Line {
start : r.icon.center
end : p.icon.center
strokeWidth : t.strokeWidth
}
override t.icon = Path {
d : pathFromPoints("closed", [p.icon.center, r.icon.center, q.icon.center])
fillColor: Colors.purple2
strokeWidth: 0
}
ensure lessThan(const.minSegmentLength, length(t.PQ))
ensure lessThan(const.minSegmentLength, length(t.QR))
ensure lessThan(const.minSegmentLength, length(t.RP))
ensure disjoint(t.icon, p.text)
ensure disjoint(t.icon, q.text)
ensure disjoint(t.icon, r.text)
t.PQ below p.icon
t.PQ below q.icon
t.QR below q.icon
t.QR below r.icon
t.RP below r.icon
t.RP below p.icon
}
--Angle
forall Angle theta
where theta := InteriorAngle(p, q, r)
with Point p; Point q; Point r {
override theta.p = p.vec
override theta.q = q.vec
override theta.r = r.vec
override theta.radius = const.thetaRadius
encourage nonDegenerateAngle(p.icon, q.icon, r.icon)
startA = ptOnLine(theta.q, theta.p, theta.radius)
endA = ptOnLine(theta.q, theta.r, theta.radius)
sweepA = arcSweepFlag(theta.q, startA, endA)
theta.mark = Path {
d : arc("open", startA, endA, (theta.radius, theta.radius), 0, 0, sweepA)
strokeWidth : 2.0
strokeColor : Colors.darkpurple
-- fillColor : #ffffff40
}
theta.mark below theta.side1, theta.side2
}
forall Segment s
where s := PerpendicularBisector(s2, p)
with Segment s2; Point p {
override s.icon = Line {
end : p.icon.center
startArrowhead: "straight"
startArrowheadSize: const.arrowheadSize
strokeColor : Colors.darkpurple
strokeWidth : const.strokeWidth
}
startA = ptOnLine(s.icon.end, s.icon.start, const.thetaRadius)
endA = ptOnLine(s.icon.end, s2.icon.end, const.thetaRadius)
sweepA = arcSweepFlag(s.icon.end, startA, endA)
markSize = 10
override s.mark = Path {
d : pathFromPoints("open", [ptOnLine(s.icon.end, s.icon.start, markSize), innerPointOffset(s.icon.end, s.icon.start, s2.icon.end, markSize), ptOnLine(s.icon.end, s2.icon.end, markSize)])
strokeWidth : 2.0
strokeColor : Colors.black
}
ensure disjoint(s.icon, p.text)
ensure perpendicular(s.icon.start, s.icon.end, s2.icon.end)
ensure equal(norm(s.icon.end - s.icon.start), const.rayLength)
}
forall Point p
where p := Midpoint(l)
with Linelike l {
override p.vec = midpoint(l.icon.start, l.icon.end)
override p.icon.fillColor = Colors.white
override p.icon.strokeColor = Colors.black
override p.icon.strokeWidth = 1
layer p.icon above l.icon