MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / DrawCrescent

Function DrawCrescent

xgeneral.cpp:1050–1119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1048// part may be rotated by the specified number of degrees.
1049
1050void DrawCrescent(int x1, int y1, int x2, int y2, real rProp, real rRotate,
1051 KI ki0, KI ki1)
1052{
1053 real xc, yc, rSq, dxy, rx, ry, dx, dy, dx2, dy2, rS, rC;
1054 int x, y, xPrev;
1055 KI ki, kiPrev;
1056
1057 // Can only draw up to a half Moon crescent. Any greater means to draw a
1058 // crescent coming in from the inverse angle with the two colors reversed.
1059 if (rProp <= 0.5)
1060 rProp = 1.0 - rProp*2.0;
1061 else {
1062 rProp = (rProp - 0.5)*2.0;
1063 rRotate += rDegHalf;
1064 SwapN(ki0, ki1);
1065 }
1066
1067 // Initialize variables.
1068 xc = (real)(x1 + x2) / 2.0; yc = (real)(y1 + y2) / 2.0;
1069 rx = (real)(x2 - x1) / 2.0; ry = (real)(y2 - y1) / 2.0;
1070 rSq = Sq(rx) + rx/2.0;
1071 dxy = rx / ry;
1072 RotateR2Init(rS, rC, rRotate);
1073 x1 = Max(x1, 0); x2 = Min(x2, gs.xWin-1);
1074 y1 = Max(y1, 0); y2 = Min(y2, gs.yWin-1);
1075
1076 // Draw one row of the ellipse at a time.
1077 for (y = y1; y <= y2; y++) {
1078 xPrev = ki = kiPrev = ~0;
1079 for (x = x1; x <= x2; x++) {
1080 dx = (real)x - xc;
1081 dy = (real)y - yc;
1082 if (rx != ry)
1083 dy *= dxy;
1084 if (Sq(dx) + Sq(dy) > rSq) {
1085 if (xPrev != ~0)
1086 break;
1087 continue;
1088 }
1089 if (rRotate != 0.0) {
1090 // Fast rotation if doing a rotated ellipse.
1091 RotateR2(dx, dy, dx2, dy2, rS, rC);
1092 } else {
1093 dx2 = dx; dy2 = dy;
1094 }
1095 ki = ki1;
1096 if (dx2 > 0.0) {
1097 dx2 /= rProp;
1098 if (Sq(dx2) + Sq(dy2) > rSq)
1099 ki = ki0;
1100 }
1101 // Don't draw anything in this row until the color changes.
1102 if (xPrev == ~0)
1103 xPrev = x;
1104 if (kiPrev == ~0)
1105 kiPrev = ki;
1106 if (ki != kiPrev) {
1107 DrawColor(kiPrev);

Callers 1

XChartTelescopeFunction · 0.85

Calls 1

DrawColorFunction · 0.85

Tested by

no test coverage detected