rgleason / weather_routing_pi

Weather Routing plugin for OpenCPN
GNU General Public License v3.0
11 stars 14 forks source link

Bug 03 Entering position between 0 and 1 degree W gives false position. #99

Open trudK45 opened 1 year ago

trudK45 commented 1 year ago

If you try to enter a position of say 30 minutes W by entering -0 degrees 30 minutes you will end up with a position of 30 minutes east. It's obvious that -0 is interpreted as 0 and the minus sign is not transferred to the minutes part.

trudK45 commented 1 year ago

Looking at the code I think this also applies for 0 -1 degrees south. You simply need to detect the entered minus sign on the degrees to decide if the minutes are to be negated or not if the value of the degrees is zero.

The routine OnNewPosition in file WeatherRouting.cpp:945

void WeatherRouting::OnNewPosition( wxCommandEvent& event ) { NewPositionDialog dlg(this); if(dlg.ShowModal() == wxID_OK) { double lat=0, lon=0, lat_minutes=0, lon_minutes=0;

    wxString latitude_degrees = dlg.m_tLatitudeDegrees->GetValue();
    wxString latitude_minutes = dlg.m_tLatitudeMinutes->GetValue();
    latitude_degrees.ToDouble(&lat);
    latitude_minutes.ToDouble(&lat_minutes);
    lat_minutes = fabs(lat_minutes);
    if(lat < 0) <------------------------------------------This will not work if -0 is entered
        lat_minutes = -lat_minutes;
    lat += lat_minutes / 60;

    wxString longitude_degrees = dlg.m_tLongitudeDegrees->GetValue();
    wxString longitude_minutes = dlg.m_tLongitudeMinutes->GetValue();
    longitude_degrees.ToDouble(&lon);
    longitude_minutes.ToDouble(&lon_minutes);
    lon_minutes = fabs(lon_minutes);
    if(lon < 0) <------------------------------------------This will not work if -0 is entered
        lon_minutes = -lon_minutes;
    lon += lon_minutes / 60;

    AddPosition(lat, lon, dlg.m_tName->GetValue());
}

}