forked from CruiserOne/Astrolog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcharts1.cpp
4422 lines (4078 loc) · 150 KB
/
xcharts1.cpp
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
/*
** Astrolog (Version 7.70) File: xcharts1.cpp
**
** IMPORTANT NOTICE: Astrolog and all chart display routines and anything
** not enumerated below used in this program are Copyright (C) 1991-2024 by
** Walter D. Pullen ([email protected], http://www.astrolog.org/astrolog.htm).
** Permission is granted to freely use, modify, and distribute these
** routines provided these credits and notices remain unmodified with any
** altered or distributed versions of the program.
**
** The main ephemeris databases and calculation routines are from the
** library SWISS EPHEMERIS and are programmed and copyright 1997-2008 by
** Astrodienst AG. Use of that source code is subject to license for Swiss
** Ephemeris Free Edition at https://www.astro.com/swisseph/swephinfo_e.htm.
** This copyright notice must not be changed or removed by any user of this
** program.
**
** Additional ephemeris databases and formulas are from the calculation
** routines in the program PLACALC and are programmed and Copyright (C)
** 1989,1991,1993 by Astrodienst AG and Alois Treindl ([email protected]). The
** use of that source code is subject to regulations made by Astrodienst
** Zurich, and the code is not in the public domain. This copyright notice
** must not be changed or removed by any user of this program.
**
** The original planetary calculation routines used in this program have
** been copyrighted and the initial core of this program was mostly a
** conversion to C of the routines created by James Neely as listed in
** 'Manual of Computer Programming for Astrologers', by Michael Erlewine,
** available from Matrix Software.
**
** Atlas composed using data from https://www.geonames.org/ licensed under a
** Creative Commons Attribution 4.0 License. Time zone changes composed using
** public domain TZ database: https://data.iana.org/time-zones/tz-link.html
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby ([email protected]).
**
** More formally: This program is free software; you can redistribute it
** and/or modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of the
** License, or (at your option) any later version. This program is
** distributed in the hope that it will be useful and inspiring, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details, a copy of which is in the
** LICENSE.HTM file included with Astrolog, and at http://www.gnu.org
**
** Initial programming 8/28-30/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 4/22/2024.
*/
#include "astrolog.h"
#ifdef GRAPH
/*
******************************************************************************
** Single Chart Graphics Routines.
******************************************************************************
*/
// Draw a wheel chart, in which the 12 signs and houses are delineated, and
// the planets are inserted in their proper places. This is the default
// graphics chart to generate, as is done when the -v or -w (or no) switches
// are included with -X. Draw the aspects in the middle of chart, too.
void XChartWheel()
{
real xsign[cSign+1], xhouse[cSign+1], xplanet[objMax], symbol[objMax];
int cx, cy, i, j;
real unitx, unity;
// Set up variables and temporarily automatically decrease the horizontal
// chart size to leave room for the sidebar, if that mode is in effect.
if (gs.fText && !us.fVelocity)
gs.xWin -= xSideT;
cx = gs.xWin/2 - 1; cy = gs.yWin/2 - 1;
unitx = (real)cx; unity = (real)cy;
gi.rAsc = gs.objLeft ? planet[NAbs(gs.objLeft)-1] +
rDegQuad*(gs.objLeft < 0) : chouse[1];
if (us.fIndian)
gi.rAsc = gs.objLeft ? (gs.objLeft < 0 ? 120.0 : -60.0)-gi.rAsc : 0.0;
// Fill out arrays with the angular degree on the circle of where to
// place each object, cusp, and sign glyph based on the chart mode.
if (gi.nMode == gWheel) {
for (i = 1; i <= cSign; i++)
xhouse[i] = PZ(chouse[i]);
} else {
gi.rAsc -= chouse[1];
for (i = 1; i <= cSign; i++)
xhouse[i] = PZ(ZFromS(i));
}
for (i = 1; i <= cSign; i++)
xsign[i] = PZ(HousePlaceInX(ZFromS(i), 0.0));
for (i = 0; i <= is.nObj; i++)
xplanet[i] = PZ(HousePlaceInX(planet[i], planetalt[i]));
// Go draw the outer sign and house rings.
DrawWheel(xsign, xhouse, cx, cy, unitx, unity, 0.65, 0.75, 0.80);
// For each planet, draw a small dot indicating where it is, and then a
// line from that point to the planet's glyph.
DrawRing(1, 1, xplanet, symbol, cx, cy, 0.0, 0.0, 0.0,
0.50, 0.52, 0.56, 0.60, 1.0);
FProcessCommandLine(szWheelX[0]);
// Draw lines connecting planets which have aspects between them.
if (!gs.fEquator) { // Don't draw aspects in equator mode.
if (!FCreateGrid(fFalse))
return;
for (j = is.nObj; j >= 1; j--)
for (i = j-1; i >= 0; i--)
if (grid->n[i][j] && FProper(i) && FProper(j))
DrawAspectLine(i, j, cx, cy, xplanet[i], xplanet[j], unitx, unity,
0.48);
}
// Go draw sidebar with chart information and positions if need be.
DrawSidebar();
}
// Draw an astro-graph chart on a map of the world, i.e. the draw the
// Ascendant, Descendant, Midheaven, and Nadir lines corresponding to the
// time in the chart. This chart is done when the -L switch is combined
// with the -X switch.
void XChartAstroGraph()
{
real planet1[objMax], planet2[objMax],
end1[cObj*2+2], end2[cObj*2+2],
symbol1[cObj*2+2], symbol2[cObj*2+2],
lon = Lon, longm, x, y, z, ad, oa, am, od, dm, lat;
int unit = gi.nScale, fVector, lat1 = -60, lat2 = 75, y1, y2, xold1, xold2,
xmid, i, j, k, l;
// Erase top and bottom parts of map. We don't draw the astro-graph lines
// above certain latitudes, and this gives us room for glyph labels, too.
y1 = (90-lat1)*gi.nScale;
y2 = (90-lat2)*gi.nScale;
DrawColor(gi.kiOff);
DrawBlock(0, 1, gs.xWin-1, y2-1);
DrawBlock(0, y1+1, gs.xWin-1, gs.yWin-2);
DrawColor(gi.kiLite);
i = gs.yWin/2;
if (gs.fEquator)
DrawDash(0, i, gs.xWin-2, i, 4); // Draw equator.
DrawColor(gi.kiOn);
DrawLine(1, y2, gs.xWin-2, y2);
DrawLine(1, y1, gs.xWin-2, y1);
for (i = 0; i <= is.nObj*2+1; i++)
end1[i] = end2[i] = -rLarge;
// Draw small hatches every 5 degrees along edges of world map.
DrawColor(gi.kiLite);
for (i = lat1+5; i < lat2; i += 5) {
j = (90-i)*gi.nScale;
k = (2+(i%10 == 0)+2*(i%30 == 0))*gi.nScaleT;
DrawLine(1, j, k, j);
DrawLine(gs.xWin-2, j, gs.xWin-1-k, j);
}
for (i = -nDegHalf+5; i < nDegHalf; i += 5) {
j = (nDegHalf-i)*gi.nScale;
k = (2+(i%10 == 0)+2*(i%30 == 0)+(i%90 == 0))*gi.nScaleT;
DrawLine(j, y2+1, j, y2+k);
DrawLine(j, y1-1, j, y1-k);
}
if (us.fLatitudeCross) {
DrawColor(kPurpleB);
i = (int)((rDegQuad - Lat)*(real)gi.nScale);
DrawLine(0, i, gs.xWin-1, i);
}
// Calculate zenith locations of each planet.
for (i = 0; i <= is.nObj; i++) if (!ignore[i]) {
planet1[i] = Tropical(planet[i]);
planet2[i] = planetalt[i];
EclToEqu(&planet1[i], &planet2[i]);
}
// Draw the Midheaven lines and zenith location markings.
if (lon < 0.0)
lon += rDegMax;
for (i = 0; i <= is.nObj; i++) if (FProper(i)) {
x = cp0.lonMC - planet1[i];
if (x < 0.0)
x += rDegMax;
if (x > rDegHalf)
x -= rDegMax;
z = lon + x;
if (z > rDegHalf)
z -= rDegMax;
j = (int)(Mod(rDegHalf-z+gs.rRot)*(real)gi.nScale);
if (!ignorez[arMC]) {
DrawColor(kElemB[eEar]);
DrawLine(j, y1+unit*4, j, y2-unit*1);
}
end2[i*2] = (real)j;
y = planet2[i];
k = (int)((rDegQuad-y)*(real)gi.nScale);
if (FBetween((int)y, lat1, lat2) && !ignorez[arMC]) {
DrawColor(gi.kiLite);
DrawBlock(j-gi.nScaleT, k-gi.nScaleT, j+gi.nScaleT, k+gi.nScaleT);
DrawColor(gi.kiOff);
DrawBlock(j, k, j, k);
}
// Draw Nadir lines assuming we aren't in bonus chart mode.
if (!gs.fAlt && !ignorez[arIC]) {
j += 180*gi.nScale;
if (j >= gs.xWin)
j -= gs.xWin;
end1[i*2] = (real)j;
DrawColor(kElemB[eWat]);
DrawLine(j, y1+unit*2, j, y2-unit*2);
}
}
// Now, normally (unless are in bonus chart mode) will go on to draw the
// the Ascendant and Descendant lines here.
longm = Mod(cp0.lonMC + lon);
if (!gs.fAlt && (!ignorez[arAsc] || !ignorez[arDes]))
for (i = 1; i <= is.nObj; i++) if (FProper(i)) {
xold1 = xold2 = nNegative;
// Normally the Ascendant and Descendant line segments are drawn
// simultaneously. However, for the PostScript and metafile vector
// graphics, that would cause the file to get inordinately large due
// to the constant thrashing between the Asc and Desc colors. Hence
// for these chart formats only, do two passes for Asc and Desc.
fVector = (gs.ft == ftPS || gs.ft == ftWmf);
for (l = 0; l <= fVector; l++)
for (lat = (real)lat1; lat <= (real)lat2;
lat += 1.0/(real)(gi.nScale/gi.nScaleT)) {
// First compute and draw the current segment of Ascendant line.
j = (int)((rDegQuad-lat)*(real)gi.nScale);
ad = RTanD(planet2[i])*RTanD(lat);
if (ad*ad > 1.0)
ad = rLarge;
else {
ad = RAsin(ad);
oa = planet1[i] - DFromR(ad);
if (oa < 0.0)
oa += rDegMax;
am = oa - rDegQuad;
if (am < 0.0)
am += rDegMax;
z = longm-am;
if (z < 0.0)
z += rDegMax;
if (z > rDegHalf)
z -= rDegMax;
k = (int)(Mod(rDegHalf-z+gs.rRot)*(real)gi.nScale);
if (!fVector || !l) {
if (!ignorez[arAsc]) {
DrawColor(kElemB[eFir]);
DrawWrap(xold1, j+gi.nScaleT, k, j, 1, gs.xWin-2);
}
// Line segment pointing to Ascendant.
if (lat == (real)lat1) {
if (!ignorez[arAsc])
DrawLine(k, y1, k, y1+unit*4);
end2[i*2+1] = (real)k;
}
} else if (lat == (real)lat1)
end2[i*2+1] = (real)k;
xold1 = k;
}
// The curving Ascendant and Descendant lines actually touch at low or
// high latitudes. Sometimes when loop starts out, a particular planet's
// lines haven't appeared yet, i.e. are scanning at a latitude at which
// the planet's lines don't exist. If this is the case, then when they
// finally do start, draw a thin horizontal line connecting the
// Ascendant and Descendant lines so they don't just start in space.
// Note that these connected lines aren't labeled with glyphs.
if (ad == rLarge) {
if (xold1 >= 0) {
if ((!fVector || !l) && !ignorez[arAsc] && !ignorez[arDes]) {
xmid = (xold1+xold2)/2;
if (NAbs(xold2-xold1) > (gs.xWin >> 1)) {
xmid += (gs.xWin >> 1);
if (xmid >= gs.xWin)
xmid -= gs.xWin;
}
DrawColor(kElemB[eFir]);
DrawWrap(xold1, j+1, xmid, j+1, 1, gs.xWin-2);
DrawColor(kElemB[eAir]);
DrawWrap(xmid, j+1, xold2, j+1, 1, gs.xWin-2);
}
lat = rDegQuad;
}
} else {
// Then compute and draw corresponding segment of Descendant line.
od = planet1[i] + DFromR(ad);
dm = od + rDegQuad;
z = longm-dm;
if (z < 0.0)
z += rDegMax;
if (z > rDegHalf)
z -= rDegMax;
k = (int)(Mod(rDegHalf-z+gs.rRot)*(real)gi.nScale);
if (xold2 < 0 && lat > (real)lat1 && (!fVector || l) &&
!ignorez[arDes]) {
xmid = (xold1+k)/2;
if (NAbs(k-xold1) > (gs.xWin >> 1)) {
xmid += (gs.xWin >> 1);
if (xmid >= gs.xWin)
xmid -= gs.xWin;
}
DrawColor(kElemB[eFir]);
DrawWrap(xold1, j, xmid, j, 1, gs.xWin-2);
DrawColor(kElemB[eAir]);
DrawWrap(xmid, j, k, j, 1, gs.xWin-2);
}
if ((!fVector || l) && !ignorez[arDes]) {
DrawColor(kElemB[eAir]);
DrawWrap(xold2, j+gi.nScaleT, k, j, 1, gs.xWin-2);
// Line segment pointing to Descendant.
if (lat == (real)lat1)
DrawLine(k, y1, k, y1+unit*2);
}
xold2 = k;
}
}
// Draw segments pointing to top of Ascendant and Descendant lines.
if (ad != rLarge) {
if (!ignorez[arAsc]) {
DrawColor(kElemB[eFir]);
DrawLine(xold1, y2, xold1, y2-unit*1);
}
if (!ignorez[arDes]) {
DrawColor(kElemB[eAir]);
DrawLine(k, y2, k, y2-unit*2);
}
end1[i*2+1] = (real)k;
}
}
// Plot chart location.
DrawColor(kMagentaB);
i = (int)(Mod(rDegHalf - Lon + gs.rRot)*(real)gi.nScale);
j = (int)((rDegQuad - Lat)*(real)gi.nScale);
if (us.fLatitudeCross)
DrawSpot(i, j);
else
DrawPoint(i, j);
// Determine where to draw the planet glyphs. There are four sets of each
// planet (each planet's glyph appearing in the chart up to four times) one
// for each type of line. The Midheaven and Ascendant lines are always
// labeled at the bottom of the chart, while the Nadir and Descendant lines
// at the top. Therefore need to place two sets of glyphs, twice.
for (i = 0; i <= is.nObj*2+1; i++) {
symbol1[i] = end1[i];
symbol2[i] = end2[i];
}
FillSymbolLine(symbol1);
FillSymbolLine(symbol2);
// Now actually draw the planet glyphs.
for (i = 0; i <= is.nObj*2+1; i++) {
j = i >> 1;
if (FProper(j)) {
if ((gi.xTurtle = (int)symbol1[i]) > 0 && gs.fLabel &&
!ignorez[FOdd(i) ? arDes : arIC]) {
DrawColor(ret[j] < 0.0 ? gi.kiGray : gi.kiOn);
DrawDash((int)end1[i], y2-unit*2, (int)symbol1[i], y2-unit*4,
(ret[i] < 0.0 ? 1 : 0) - gs.fColor);
DrawObject(j, gi.xTurtle, y2-unit*10);
}
if ((gi.xTurtle = (int)symbol2[i]) > 0 && gs.fLabel &&
!ignorez[FOdd(i) ? arAsc : arMC]) {
DrawColor(ret[j] < 0.0 ? gi.kiGray : gi.kiOn);
DrawDash((int)end2[i], y1+unit*4, (int)symbol2[i], y1+unit*8,
(ret[i] < 0.0 ? 1 : 0) - gs.fColor);
DrawObject(j, gi.xTurtle, y1+unit*14);
k = FOdd(i) ? oAsc : oMC;
l = kObjB[k]; kObjB[k] = kObjB[j];
DrawObject(k, (int)symbol2[i], y1+unit*24-gi.nScaleT);
kObjB[k] = l;
}
}
}
}
// Compose a string to display within a graphic aspect grid cell.
KI FormatGridCell(char *sz, int x, int y, int type, flag fWide)
{
char szT[cchSzDef];
int n, d, m, s;
real v;
KI ki = -1;
if (x < 0) {
v = rgpcp[-x-1]->obj[y];
n = SFromZ(v); v = v - ZFromS(n);
} else {
n = grid->n[x][y]; v = grid->v[x][y];
}
*szT = chNull;
s = NAbs((int)(v*3600.0)); m = s/60; d = m/60; m %= 60; s %= 60;
// For aspect cells, print orb in degrees and minutes.
if (type == 1) {
if (n > 0) {
if (us.fDistance && !us.fParallel) {
sprintf(sz, "%c%f", rgchAppSep[us.nAppSep*2 + (v >= 0.0)],
RAbs(v));
sprintf(&sz[fWide ? 8 : 5], "%s", "%");
} else if (us.nDegForm != df360) {
if (fWide)
sprintf(szT, "%02d", s);
sprintf(sz, "%c%d%c%02d'%s", rgchAppSep[us.nAppSep*2 + (v >= 0.0)],
d, chDegL, m, szT);
sz[fWide ? (d >= 100 ? 8 : 9) : (d >= 100 ? 5 : 6)] = chNull;
} else {
sprintf(sz, "%c%f", rgchAppSep[us.nAppSep*2 + (v >= 0.0)], RAbs(v));
sz[fWide ? 8 : 5] = chNull;
}
} else
*sz = chNull;
}
// For midpoint cells, print degrees and minutes.
else if (type == 2 || (type == 0 && us.nDegForm == dfHM)) {
if (us.nDegForm == dfHM) {
sprintf(sz, "%s", SzZodiac((real)((n-1)*30) + v));
sz[3] = sz[4]; sz[4] = sz[5]; sz[5] = 'm';
if (fWide)
sprintf(sz+6, "%s", sz+8);
sz[fWide ? 8 : 6] = chNull;
} else if (us.nDegForm != df360) {
if (fWide)
sprintf(szT, "%02d", s);
sprintf(sz, "%2d%c%02d'%s", d, chDegL, m, szT);
} else
sprintf(sz, fWide ? "%8.5f" : "%5.2f", RAbs(v));
}
// For main diagonal cells, print sign and degree of the planet.
else {
ki = kSignB(n);
if (us.nDegForm != df360) {
if (fWide)
sprintf(szT, "%c%02d", chDegL, m);
sprintf(sz, "%.3s %02d%s", szSignName[n], d, szT);
} else
sprintf(sz, fWide ? "%8.4f" : "%5.1f", RAbs((real)((n-1)*30) + v));
}
return ki;
}
// Draw an aspect and midpoint grid in the window, with planets labeled down
// the diagonal. This chart is done when the -g switch is combined with the
// -X switch. The chart always has a certain number of cells, hence based on
// how the restrictions are set up, there may be blank columns and rows, or
// else only the first number of unrestricted objects will be included.
void XChartGrid(int x0, int y0)
{
char sz[cchSzDef];
int nScale, unit, siz, x, y, i, j, k, i0, j0, ig, jg;
KI c;
nScale = gi.nScale/gi.nScaleT;
unit = CELLSIZE*gi.nScale; siz = gi.nGridCell*unit;
i = us.fSmartCusp; us.fSmartCusp = fFalse;
j = us.objRequire; us.objRequire = -1;
if (!FCreateGrid(gs.fAlt))
return;
us.fSmartCusp = i; us.objRequire = j;
// Loop through each cell in each row and column of grid.
for (y = 1, j0 = -1; y <= gi.nGridCell; y++) {
do {
j0++;
j = rgobjList[j0];
} while (!FProper(j) && j0 <= is.nObj);
DrawColor(gi.kiGray);
DrawDash(x0, y0 + y*unit, x0 + siz, y0 + y*unit, !gs.fColor);
DrawDash(x0 + y*unit, y0, x0 + y*unit, y0 + siz, !gs.fColor);
if (j0 <= is.nObj) for (x = 1, i0 = -1; x <= gi.nGridCell; x++) {
do {
i0++;
i = rgobjList[i0];
} while (!FProper(i) && i0 <= is.nObj);
ig = i; jg = j;
if ((i > j) != (i0 > j0))
SwapN(ig, jg);
if (i0 <= is.nObj) {
gi.xTurtle = x*unit-unit/2;
gi.yTurtle = y*unit-unit/2 - (nScale > 2 ? 5*gi.nScaleT : 0);
k = grid->n[ig][jg];
// If this is an aspect cell, draw glyph of aspect in effect.
if (gs.fAlt ? x > y : x < y) {
if (k) {
DrawColor(c = kAspB[k]);
DrawAspect(k + (NCheckEclipseAny(ig, k, jg, NULL) >
etNone)*cAspect2, x0 + gi.xTurtle, y0 + gi.yTurtle);
}
// If this is a midpoint cell, draw glyph of sign of midpoint.
} else if (gs.fAlt ? x < y : x > y) {
DrawColor(c = kSignB(grid->n[ig][jg]));
DrawSign(grid->n[ig][jg], x0 + gi.xTurtle, y0 + gi.yTurtle);
// For cells on main diagonal, draw glyph of planet.
} else {
if (gs.fLabelAsp) {
DrawColor(kDkBlueB);
DrawBlock(x0 + (x-1)*unit+1, y0 + (y-1)*unit+1,
x0 + x*unit-1, y0 + y*unit-1);
}
DrawColor(gi.kiLite);
DrawEdge(x0 + (x-1)*unit, y0 + (y-1)*unit, x0 + x*unit, y0 + y*unit);
DrawObject(i, x0 + gi.xTurtle, y0 + gi.yTurtle);
}
// When the scale size is 300+, can print text in each cell.
if (nScale > 2 && gs.fLabel) {
// For the aspect portion, print the orb in degrees and minutes.
if (x != y)
c = FormatGridCell(sz, ig, jg, 1 + (gs.fAlt ? x < y : x > y),
nScale > 3 && us.fSeconds);
// For the main diagonal, print degree and sign of each planet.
else
c = FormatGridCell(sz, ig, jg, 0, nScale > 3 && us.fSeconds);
if (c >= 0)
DrawColor(c);
DrawSz(sz, x0 + x*unit-unit/2, y0 + y*unit-3*gi.nScaleT, dtBottom);
}
}
}
}
}
// Translate zodiac position (or other type of coordinates) into chart pixel
// coordinates representing local horizon position, for the rectangular
// -Z -X switch chart.
void PlotHorizon(real lon, real lat, int x1, int y1, int xs, int ys,
int *xp, int *yp)
{
lat = rDegQuad - lat;
*xp = x1 + (int)((real)xs*lon/rDegMax + rRound);
*yp = y1 + (int)((real)ys*lat/rDegHalf + rRound);
}
void LocToHorizon(real lon, real lat, int x1, int y1, int xs, int ys,
int *xp, int *yp)
{
if (!gs.fEcliptic) {
lon = Mod(rDegQuad - lon);
if (us.fRefract)
lat = SwissRefract(lat);
PlotHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
} else {
lon = rDegMax - lon;
CoorXform(&lon, &lat, Lat - rDegQuad);
lon = Mod(cp0.lonMC - lon + rDegQuad);
EquToHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
}
}
void EquToHorizon(real lon, real lat, int x1, int y1, int xs, int ys,
int *xp, int *yp)
{
if (!gs.fEcliptic) {
lon = Mod(cp0.lonMC - lon + rDegQuad);
EquToLocal(&lon, &lat, rDegQuad - Lat);
lon = rDegMax - lon;
LocToHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
} else {
EquToEcl(&lon, &lat);
lon = Mod(Untropical(lon));
EclToHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
}
}
void EclToHorizon(real lon, real lat, int x1, int y1, int xs, int ys,
int *xp, int *yp)
{
if (!gs.fEcliptic) {
lon = Tropical(lon);
EclToEqu(&lon, &lat);
EquToHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
} else
PlotHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
}
void PriToHorizon(real lon, real lat, int x1, int y1, int xs, int ys,
int *xp, int *yp)
{
lon = rDegMax - lon;
CoorXform(&lon, &lat, rDegQuad);
LocToHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
}
void EarToHorizon(real lon, real lat, int x1, int y1, int xs, int ys,
int *xp, int *yp)
{
lon = Mod(lon + rDegHalf);
CoorXform(&lon, &lat, rDegQuad - Lat);
LocToHorizon(Mod(lon - rDegHalf), lat, x1, y1, xs, ys, xp, yp);
}
void EquToHorizon2(real lon, real lat, int x1, int y1, int xs, int ys,
int *xp, int *yp, flag fFlip)
{
if (!fFlip)
EquToHorizon(lon, lat, x1, y1, xs, ys, xp, yp);
else {
EquToEcl(&lon, &lat);
EclToHorizon(rDegMax - lon, lat, x1, y1, xs, ys, xp, yp);
}
}
#define NDashAspect(i, j, asp, orb) (gs.nDashMax >= 0 ? \
NAbs((int)(orb*3600.0)) / (60*60*2) : NAbs((int)(orb*3600.0)) * \
NAbs(gs.nDashMax) / (int)(GetOrb(i, j, asp)*3600.0))
// Draw the local horizon, and draw in the planets where they are at the time
// in question, as done when the -Z is combined with the -X switch.
void XChartHorizon()
{
int cx, cy, unit, x1, y1, x2, y2, xs, ys, xp, yp, i, j, k;
real rT;
ObjDraw rgod[objMax];
char sz[cchSzDef];
flag fHouse3D = !us.fHouse3D, fFlip = gs.fEcliptic && us.rHarmonic < 0.0;
ES es;
#ifdef CONSTEL
int m1, n1, m2, n2, xpT, ypT;
#endif
#ifdef SWISS
ES *pes1, *pes2;
int xp2, yp2;
#endif
unit = Max(12, 6*gi.nScale);
unit = Max(unit, yFontT);
x1 = y1 = unit; x2 = gs.xWin-1-unit; y2 = gs.yWin-1-unit;
xs = x2-x1; ys = y2-y1; cx = (x1+x2)/2; cy = (y1+y2)/2;
// Calculate the local horizon coordinates of each planet. First convert
// zodiac position and declination to zenith longitude and latitude.
ClearB((pbyte)rgod, sizeof(rgod));
for (i = 0; i <= is.nObj; i++) if (FProper(i)) {
EclToHorizon(planet[i], planetalt[i], x1, y1, xs, ys,
&rgod[i].x, &rgod[i].y);
rgod[i].obj = i;
rgod[i].kv = ~0;
rgod[i].f = fTrue;
}
// Draw planet disks (which become visible if large enough).
if (!gs.fAlt)
for (i = 0; i <= is.nObj; i++) if (FProper(i) && i != us.objCenter) {
rT = RObjDiam(i);
if (rT <= 0.0)
continue;
rT = RAtnD((rT / 2.0) / (PtLen(space[i]) * rAUToKm));
j = (int)(rT * (real)xs / rDegMax);
k = (int)(rT * (real)ys / rDegHalf);
if (j > 1 || k > 1) {
DrawColor(kDkGreenB);
DrawCircle2(rgod[i].x, rgod[i].y, j, k);
}
}
// Draw Earth's equator.
if (gs.fEquator) {
DrawColor(kPurpleB);
for (i = 0; i <= nDegMax; i++) {
EquToHorizon((real)i, 0.0, x1, y1, xs, ys, &xp, &yp);
DrawPoint(xp, yp);
}
}
#ifdef CONSTEL
// Draw constellations.
if (gs.fConstel) {
EnumConstelLines(NULL, NULL, NULL, NULL, NULL);
while (EnumConstelLines(&m1, &n1, &m2, &n2, &i)) {
EquToHorizon2((real)(nDegMax-m1), (real)(90-n1), x1, y1, xs, ys,
&xp, &yp, fFlip);
if (i <= 0) {
DrawColor(kPurpleB);
EquToHorizon2((real)(nDegMax-m2), (real)(90-n2), x1, y1, xs, ys,
&xpT, &ypT, fFlip);
DrawWrap(xp, yp, xpT, ypT, x1, x2);
} else {
DrawColor(gi.kiGray);
DrawSz(szCnstlAbbrev[i], xp, yp, dtCent | dtScale2);
}
}
}
#endif
// Draw zodiac sign boundary wedges.
if (us.fIndian) {
if (!gs.fColorSign)
DrawColor(kDkBlueB);
for (i = 0; i < nDegMax; i++) {
if (gs.fColorSign && i%30 == 0) {
k = i/30 + 1;
DrawColor(kSignB(!fFlip ? k : cSign+1 - k));
}
EclToHorizon((real)i, 0.0, x1, y1, xs, ys, &xp, &yp);
DrawPoint(xp, yp);
}
for (i = 0; i < nDegMax; i += 30) {
if (gs.fColorSign) {
k = i/30 + 1;
DrawColor(kSignB(!fFlip ? k : Mod12(cSign+2 - k)));
}
for (j = -90; j <= 90; j++) {
EclToHorizon((real)i, (real)j, x1, y1, xs, ys, &xp, &yp);
DrawPoint(xp, yp);
}
}
k = gi.nScale;
gi.nScale = gi.nScaleTextT;
for (j = -80; j <= 80; j += 160)
for (i = 1; i <= cSign; i++) {
EclToHorizon((real)(i-1)*30.0+15.0, (real)j, x1, y1, xs, ys,
&xp, &yp);
if (gs.fColorSign)
DrawColor(kSignB(!fFlip ? i : cSign+1 - i));
DrawSign(!fFlip ? i : cSign+1 - i, xp, yp);
}
gi.nScale = k;
}
// Draw house boundary wedges.
if (gs.fHouseExtra) {
if (!gs.fColorHouse)
DrawColor(kDkGreenB);
if (fHouse3D) {
for (j = 1; j <= cSign; j++) {
if (!gs.fEcliptic) {
if ((j == sCap && FSameR(chouse[j], is.MC)) ||
(j == sCan && FSameR(chouse[j], Mod(is.MC + rDegHalf))))
continue;
if (us.nHouse3D == hmPrime &&
((j == sAri && FSameR(chouse[j], is.Asc)) ||
(j == sLib && FSameR(chouse[j], Mod(is.Asc + rDegHalf)))))
continue;
if (us.nHouse3D == hmHorizon &&
((j == (Lat >= 0.0 ? sAri : sLib) &&
FSameR(chouse[j], Mod(is.Vtx + rDegHalf))) ||
(j == (Lat >= 0.0 ? sLib : sAri) && FSameR(chouse[j], is.Vtx))))
continue;
}
if (gs.fColorHouse)
DrawColor(kSignB(j));
rT = chouse3[j];
if (us.nHouse3D == hmHorizon)
rT = (rT + rDegQuad) * (Lat < 0.0 ? -1.0 : 1.0) - rDegQuad;
for (i = -89; i < 90; i++) {
if (us.nHouse3D == hmPrime)
PriToHorizon(rT, i, x1, y1, xs, ys, &xp, &yp);
else if (us.nHouse3D == hmHorizon)
LocToHorizon(rT, i, x1, y1, xs, ys, &xp, &yp);
else
EarToHorizon(rT, i, x1, y1, xs, ys, &xp, &yp);
DrawPoint(xp, yp);
}
}
for (i = 1; i <= cSign; i++) {
rT = Midpoint(chouse3[i], chouse3[Mod12(i+1)]);
if (us.nHouse3D == hmPrime)
PriToHorizon(rT, 0.0, x1, y1, xs, ys, &xp, &yp);
else if (us.nHouse3D == hmHorizon) {
rT = (rT + rDegQuad) * (Lat < 0.0 ? -1.0 : 1.0) - rDegQuad;
LocToHorizon(rT, 0.0, x1, y1, xs, ys, &xp, &yp);
} else
EarToHorizon(rT, 0.0, x1, y1, xs, ys, &xp, &yp);
if (gs.fColorHouse)
DrawColor(kSignB(i));
DrawHouse(i, xp, yp);
}
} else {
for (i = 1; i <= cSign; i++) {
if (gs.fColorHouse)
DrawColor(kSignB(SFromZ(chouse[i])));
for (j = -90; j <= 90; j++) {
EclToHorizon(chouse[i], (real)j, x1, y1, xs, ys,
&xp, &yp);
DrawPoint(xp, yp);
}
}
for (j = -75; j <= 75; j += 150)
for (i = 1; i <= cSign; i++) {
EclToHorizon(Midpoint(chouse[i], chouse[Mod12(i+1)]), (real)j,
x1, y1, xs, ys, &xp, &yp);
if (gs.fColorHouse)
DrawColor(kSignB(i));
DrawHouse(i, xp, yp);
}
}
}
// Draw vertical lines dividing our rectangle into four areas. In our
// local space chart, the middle line represents due south, the left line
// due east, the right line due west, and the edges due north. A fourth
// horizontal line divides that which is above and below the horizon.
if (gs.fHouseExtra && fHouse3D && !gs.fEcliptic) {
DrawColor(gs.fColorHouse ? kSignB(sCap) : kDkGreenB);
DrawDash(cx, y1, cx, cy, 1);
DrawColor(gs.fColorHouse ? kSignB(sCan) : kDkGreenB);
DrawDash(cx, cy, cx, y2, 1);
}
if (!(us.fIndian && gs.fEcliptic)) {
DrawColor(gi.kiGray);
if (!(gs.fHouseExtra && fHouse3D && !gs.fEcliptic))
DrawDash(cx, y1, cx, y2, 1);
DrawDash((cx+x1)/2, y1, (cx+x1)/2, y2, 1);
DrawDash((cx+x2)/2, y1, (cx+x2)/2, y2, 1);
}
DrawColor(gi.kiOn);
DrawEdge(x1, y1, x2, y2);
if (!(us.fIndian && gs.fEcliptic)) {
if (gs.fHouseExtra && fHouse3D) {
if (gs.fColorHouse)
DrawColor(kSignB(sAri));
DrawDash(x1, cy, cx, cy, 1);
if (gs.fColorHouse)
DrawColor(kSignB(sLib));
DrawDash(cx, cy, x2, cy, 1);
} else
DrawDash(x1, cy, x2, cy, 1);
}
// Make a slightly smaller rectangle within the window to draw the planets
// in. Make segments on all four edges marking 5 degree increments.
DrawColor(gi.kiLite);
for (i = 5; i < 180; i += 5) {
j = y1+(int)((real)i*(real)ys/rDegHalf);
k = (2+(i%10 == 0)+2*(i%30 == 0))*gi.nScaleT;
DrawLine(x1+1, j, x1+1+k, j);
DrawLine(x2-1, j, x2-1-k, j);
}
for (i = 0; i <= nDegMax; i += 5) {
j = x1+(int)((real)i*(real)xs/rDegMax);
if (i > 0 && i < nDegMax) {
k = (2+(i%10 == 0)+2*(i%30 == 0))*gi.nScaleT;
DrawLine(j, y1+1, j, y1+1+k);
DrawLine(j, y2-1, j, y2-1-k);
}
if (i%90 == 0) {
k = !fFlip ? i : nDegMax-i;
if (!gs.fEcliptic)
sprintf(sz, "%c", *rgszDir[k/90 & 3]);
else if (us.nDegForm == dfZod)
sprintf(sz, "%3.3s", szSignName[Mod12((k / 90)*3 + 1)]);
else if (us.nDegForm == dfHM)
sprintf(sz, "%dh", k/15);
else
sprintf(sz, "%d", k);
DrawSz(sz, j, y1-2*gi.nScaleT, dtBottom | dtScale2);
}
}
#ifdef SWISS
// Draw extra stars.
if (gs.fAllStar) {
DrawColor(gi.kiGray);
SwissComputeStar(0.0, NULL);
while (SwissComputeStar(is.T, &es)) {
EclToHorizon(es.lon, es.lat, x1, y1, xs, ys, &xp, &yp);
DrawStar(xp, yp, &es);
}
// Draw constellation lines between stars.
DrawColor(gi.kiLite);
EnumStarsLines(fTrue, NULL, NULL);
while (EnumStarsLines(fFalse, &pes1, &pes2)) {
EclToHorizon(pes1->lon, pes1->lat, x1, y1, xs, ys, &xp, &yp);
EclToHorizon(pes2->lon, pes2->lat, x1, y1, xs, ys, &xp2, &yp2);
DrawWrap(xp, yp, xp2, yp2, x1, x2);
}
}
// Draw extra asteroids.
if (gs.nAstLo > 0) {
DrawColor(gi.kiGray);
SwissComputeAsteroid(0.0, NULL, fTrue);
while (SwissComputeAsteroid(is.T, &es, fTrue)) {
EclToHorizon(es.lon, es.lat, x1, y1, xs, ys, &xp, &yp);
DrawStar(xp, yp, &es);
}
}
#endif
// Draw exoplanets.
if (gs.fAllExo) {
EnumExoplanets(NULL);
while (EnumExoplanets(&es)) {
EquToEcl(&es.lon, &es.lat);
EclToHorizon(es.lon, es.lat, x1, y1, xs, ys, &xp, &yp);
DrawStar(xp, yp, &es);
}
}
// Draw lines connecting planets which have aspects between them.
if (gs.fLabelCity) {
if (!FCreateGrid(fFalse))
return;
k = gi.nScale;
gi.nScale = gi.nScaleTextT;
for (j = is.nObj; j >= 1; j--)
for (i = j-1; i >= 0; i--)
if (grid->n[i][j] && FProper(i) && FProper(j)) {
DrawColor(kAspB[grid->n[i][j]]);
DrawDash(rgod[i].x, rgod[i].y, rgod[j].x, rgod[j].y,
NDashAspect(i, j, grid->n[i][j], grid->v[i][j]));
if (gs.fLabelAsp)
DrawAspect(grid->n[i][j],
(rgod[i].x + rgod[j].x) >> 1, (rgod[i].y + rgod[j].y) >> 1);
}
gi.nScale = k;
}
// Draw planet glyphs, and spots for actual planet locations.
DrawObjects(rgod, is.nObj+1, unit);
}
// Translate zodiac position (or other type of coordinates) into chart pixel
// coordinates representing local horizon position, for the circular -Z0 -X
// switch chart.
void PlotHorizonSky(real lon, real lat, CONST CIRC *pcr, int *xp, int *yp)
{
real s, x, y, rx, ry;
rx = (real)pcr->xr; ry = (real)pcr->yr;
s = (rDegQuad-lat)/rDegQuad;
if (s > 1.0) {
x = rx * (rSqr2 - 1.0);
y = ry * (rSqr2 - 1.0);
if (lon < 45.0 || lon >= rDegMax-45.0 ||
FBetween(lon, rDegHalf-45.0, rDegHalf+45.0))
s = 1.0 + (s - 1.0) * (((rx + x)/RAbs(RCosD(lon))-rx) / rx);
else if (lon < 135.0 || lon >= rDegMax-135.0)
s = 1.0 + (s - 1.0) * (((ry + y)/RAbs(RCosD(lon-90.0))-ry) / ry);
}
*xp = pcr->xc + (!gs.fEcliptic && FOdd(us.nHorizon) ? -1 : 1) *
(int)(rx*s*RCosD(rDegHalf+lon)+rRound);
*yp = pcr->yc + (!gs.fEcliptic && (us.nHorizon >= 4) ? -1 : 1) *
(int)(ry*s*RSinD(rDegHalf+lon)+rRound);
}
void LocToHorizonSky(real lon, real lat, CONST CIRC *pcr, int *xp, int *yp)
{
if (!gs.fEcliptic) {
if (us.fRefract)
lat = SwissRefract(lat);
PlotHorizonSky(lon, lat, pcr, xp, yp);