From 8645dab54ebef1c2b55c31da92323342f9554796 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 6 Dec 2024 15:07:57 -0800 Subject: [PATCH] Add code comments Use wxPoint to avoid rounding versus truncation --- gui/include/gui/ocpndc.h | 16 ++++++++++++++++ gui/src/glChartCanvas.cpp | 26 ++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/gui/include/gui/ocpndc.h b/gui/include/gui/ocpndc.h index 0afa93c925..1e30703696 100644 --- a/gui/include/gui/ocpndc.h +++ b/gui/include/gui/ocpndc.h @@ -87,6 +87,22 @@ class ocpnDC { void GetSize(wxCoord *width, wxCoord *height) const; + /** + * Draw a line between two points using either wxDC or OpenGL. + * + * When using OpenGL, this function supports different line qualities and + * widths. For high quality lines (b_hiqual=true), it enables anti-aliasing + * and line smoothing. The function also handles dashed lines via line + * stippling in OpenGL mode. + * + * @param x1 The x-coordinate of the starting point, in physical pixels. + * @param y1 The y-coordinate of the starting point, in physical pixels. + * @param x2 The x-coordinate of the ending point, in physical pixels. + * @param y2 The y-coordinate of the ending point, in physical pixels. + * @param b_hiqual If true, enables high quality rendering with anti-aliasing + * and line smoothing in OpenGL mode. Has no effect in wxDC + * mode. + */ void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, bool b_hiqual = true); void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0, diff --git a/gui/src/glChartCanvas.cpp b/gui/src/glChartCanvas.cpp index ec9af203e4..cc4d925250 100644 --- a/gui/src/glChartCanvas.cpp +++ b/gui/src/glChartCanvas.cpp @@ -2020,13 +2020,13 @@ void glChartCanvas::GridDraw() { if (!straight_latitudes) lon_step /= ceil(lon_step / curved_step); for (lat = startlat; lat < nlat; lat += gridlatMajor) { - wxPoint2DDouble r, s; - s.m_x = NAN; - + wxPoint r, s; + s.x = INVALID_COORD; + s.y = INVALID_COORD; for (lon = wlon; lon < elon + lon_step / 2; lon += lon_step) { - m_pParentCanvas->GetDoubleCanvasPointPix(lat, lon, &r); - if (!std::isnan(s.m_x) && !std::isnan(r.m_x)) { - gldc.DrawLine(s.m_x, s.m_y, r.m_x, r.m_y, false); + m_pParentCanvas->GetCanvasPointPix(lat, lon, &r); + if (s.x != INVALID_COORD && s.y != INVALID_COORD) { + gldc.DrawLine(s.x, s.y, r.x, r.y, false); } s = r; } @@ -2040,8 +2040,6 @@ void glChartCanvas::GridDraw() { m_pParentCanvas->GetCanvasPointPix(lat, (elon + wlon) / 2, &r); gldc.DrawLine(0, r.y, 10, r.y, true); gldc.DrawLine(w - 10, r.y, w, r.y, false); - - lat = lat + gridlatMinor; } } @@ -2050,13 +2048,13 @@ void glChartCanvas::GridDraw() { if (!straight_longitudes) lat_step /= ceil(lat_step / curved_step); for (lon = startlon; lon < elon; lon += gridlonMajor) { - wxPoint2DDouble r, s; - s.m_x = NAN; + wxPoint r, s; + s.x = INVALID_COORD; + s.y = INVALID_COORD; for (lat = slat; lat < nlat + lat_step / 2; lat += lat_step) { - m_pParentCanvas->GetDoubleCanvasPointPix(lat, lon, &r); - - if (!std::isnan(s.m_x) && !std::isnan(r.m_x)) { - gldc.DrawLine(s.m_x, s.m_y, r.m_x, r.m_y, false); + m_pParentCanvas->GetCanvasPointPix(lat, lon, &r); + if (s.x != INVALID_COORD && s.y != INVALID_COORD) { + gldc.DrawLine(s.x, s.y, r.x, r.y, false); } s = r; }