From e8aefd2c2e0aa35571cac1f204ca80ea90ca2fd1 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 25 Oct 2020 12:53:59 +0100 Subject: [PATCH] #3 finish solar terminator: work with maps at longitudes other than 0 --- src/gtk-sat-map.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/gtk-sat-map.c b/src/gtk-sat-map.c index 8c7a0ac..f9dca53 100644 --- a/src/gtk-sat-map.c +++ b/src/gtk-sat-map.c @@ -2691,9 +2691,9 @@ static void redraw_terminator(GtkSatMap * satmap) for (longitude = -180; longitude <= 180; ++longitude) { - - lx = cos(de2ra * (longitude + sgn(sz) * 90)); - ly = sin(de2ra * (longitude + sgn(sz) * 90)); + int centered_longitude = longitude + (satmap->left_side_lon - 180.0); + lx = cos(de2ra * (centered_longitude + sgn(sz) * 90)); + ly = sin(de2ra * (centered_longitude + sgn(sz) * 90)); /* lz = 0.0; */ rx = ly * sz /* -lz*sy */ ; @@ -2703,19 +2703,23 @@ static void redraw_terminator(GtkSatMap * satmap) gdouble length = sqrt(rx * rx + ry * ry + rz * rz); lonlat_to_xy(satmap, - longitude, asin(rz / length) * (1.0 / de2ra), &x, &y); + centered_longitude, asin(rz / length) * (1.0 / de2ra), &x, &y); + + if( 180 == longitude ) + { + // make sure the last point is on the right side + x = satmap->x0 + satmap->width; + } line->coords[2 * (longitude + 181)] = x; line->coords[2 * (longitude + 181) + 1] = y; } - lonlat_to_xy(satmap, -180.0, sz < 0.0 ? 90.0 : -90.0, &x, &y); - line->coords[0] = x; - line->coords[1] = y; + line->coords[0] = satmap->x0; + line->coords[1] = sz < 0.0 ? satmap->y0 : ( satmap->y0 + satmap->height ); - lonlat_to_xy(satmap, 180.0, sz < 0.0 ? 90.0 : -90.0, &x, &y); - line->coords[724] = x; - line->coords[725] = y; + line->coords[724] = satmap->x0 + satmap->width; + line->coords[725] = sz < 0.0 ? satmap->y0 : ( satmap->y0 + satmap->height ); g_object_set(satmap->terminator, "points", line, NULL); goo_canvas_points_unref(line);