Skip to content

Commit

Permalink
Merge pull request #168 from TwinFan/Next
Browse files Browse the repository at this point in the history
Merge v1.23
  • Loading branch information
TwinFan authored Feb 22, 2020
2 parents a521d4c + a6f6d7c commit 100774d
Show file tree
Hide file tree
Showing 55 changed files with 5,088 additions and 1,505 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ build-lin/
build-win/
build-mac/

# Generated documentation
docs/html/

# XCode user specific files
xcuserdata/
*.xcworkspace/
Expand Down
44 changes: 19 additions & 25 deletions Include/ACInfoWnd.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
//
// SettingsUI.h
// LiveTraffic

/*
* Copyright (c) 2018, Birger Hoppe
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/// @file ACInfoWnd.h
/// @brief Aircraft information window showing details for a selected aircraft
/// @author Birger Hoppe
/// @copyright (c) 2018-2020 Birger Hoppe
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:\n
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.\n
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

#ifndef ACInfoWnd_h
#define ACInfoWnd_h
Expand Down
52 changes: 26 additions & 26 deletions Include/Constants.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
//
// Constants.h
// LiveTraffic

/*
* Copyright (c) 2018, Birger Hoppe
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/// @file Constants.h
/// @brief Constant definitions for LiveTraffic
/// @details Version Information.\n
/// Unit Conversions.\n
/// Flight Model defaults.\n
/// Menu item texts.\n
/// Informational, warning, and error message texts.\n
/// @author Birger Hoppe
/// @copyright (c) 2020 Birger Hoppe
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:\n
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.\n
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

#ifndef Constants_h
#define Constants_h
Expand Down Expand Up @@ -110,6 +109,7 @@ constexpr int COLOR_GREEN = 0x00FF00;
constexpr int COLOR_BLUE = 0x00F0F0; // light blue

//MARK: Airports, Runways, Taxiways
constexpr double ART_EDGE_ANGLE_TOLERANCE=30.0; ///< [¡] tolerance of searched heading to edge's angle to be considered a fit
constexpr double ART_RWY_TD_POINT_F = 0.10; ///< [-] Touch-down point is this much into actual runway (so we don't touch down at its actual beginning)
constexpr double ART_RWY_MAX_HEAD_DIFF = 10.0; ///< [¡] maximum heading difference between flight and runway
constexpr double ART_RWY_MAX_VSI_F = 2.0; ///< [-] descend rate: maximum allowed factor applied to VSI_FINAL
Expand Down Expand Up @@ -248,7 +248,7 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
#define ERR_CURL_EASY_INIT "Could not initialize easy CURL"
#define ERR_CURL_PERFORM "%s: Could not get network data: %d - %s"
#define ERR_CURL_NOVERCHECK "Could not browse X-Plane.org for version info: %d - %s"
#define ERR_CURL_HTTP_RESP "%s: HTTP response is not OK but %ld"
#define ERR_CURL_HTTP_RESP "%s: HTTP response is not OK but %ld for %s"
#define ERR_CURL_REVOKE_MSG {"revocation","80092012","80092013"} // appear in error text if querying revocation list fails
#define ERR_CURL_DISABLE_REV_QU "%s: Querying revocation list failed - have set CURLSSLOPT_NO_REVOKE and am trying again"
#define ERR_HTTP_NOT_OK "HTTP response was not HTTP_OK"
Expand Down
120 changes: 99 additions & 21 deletions Include/CoordCalc.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
//
// CoordCalc.h
// LiveTraffic
/*
* Found on stackoverflow, code originally by iammilind, improved by 4566976
* original: https://stackoverflow.com/questions/32096968
* improved version: https://ideone.com/9yuONO
*
* I've adapted to my structures and coding style/naming
* added a function (CoordVectorBetween) and this header file.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/// @file CoordCalc.h
/// @brief Arithmetics with geographic coordinations and altitudes
/// @details Basic calculations like distance, angle between vectors, point plus vector.\n
/// Definitions for classes positionTy, vectorTy, and boundingBoxTy.
/// @author Birger Hoppe
/// @copyright (c) 2018-2020 Birger Hoppe
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:\n
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.\n
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

#ifndef CoordCalc_h
#define CoordCalc_h
Expand All @@ -28,6 +30,17 @@
// positions and angles are in degrees
// distances and altitude are in meters

//
// MARK: Mathematical helper functions
//
/// Square, ie. a^2
template <class T>
inline T sqr (T a) { return a*a; }

/// Pythagoras square, ie. a^2 + b^2
template <class T>
inline T pyth2 (T a, T b) { return sqr(a) + sqr(b); }

//
//MARK: Degree/Radian conversion
// (as per stackoverflow post, adapted)
Expand All @@ -49,6 +62,10 @@ inline double vsi2deg (const double speed, const double vsi)
struct positionTy;
struct vectorTy;

/// angle between two locations given in plain lat/lon
double CoordAngle (double lat1, double lon1, double lat2, double lon2);
/// distance between two locations given in plain lat/lon [meter]
double CoordDistance (double lat1, double lon1, double lat2, double lon2);
// angle between two coordinates
double CoordAngle (const positionTy& pos1, const positionTy& pos2 );
//distance between two coordinates
Expand All @@ -58,6 +75,57 @@ vectorTy CoordVectorBetween (const positionTy& from, const positionTy& to );
// destination point given a starting point and a vetor
positionTy CoordPlusVector (const positionTy& pos, const vectorTy& vec);

/// @brief Simple square of distance just by Pythagoras
inline double DistPythSqr (double x1, double y1,
double x2, double y2)
{ return pyth2(x2-x1, y2-y1); }

/// Return structure for DistPointToLineSqr()
struct distToLineTy {
double dist2 = NAN; ///< main result: square distance of point to the line
double len2 = NAN; ///< square of length of line between ln_x/y1 and ln_x/y2
double leg1_len2 = NAN; ///< square length of leg from point 1 to base (base is point on the line with shortest distance to point)
double leg2_len2 = NAN; ///< square length of leg from point 2 to base (base is point on the line with shortest distance to point)
/// Is the base outside the endpoints of the line?
bool IsBaseOutsideLine () const
{ return leg1_len2 > len2 || leg2_len2 > len2; }
/// How much is the base outside the (nearer) endpoint? (squared)
double DistSqrOfBaseBeyondLine () const
{ return std::max(leg1_len2,leg2_len2) - len2; }
};

/// @brief Square of distance between a location and a line defined by two points.
/// @note Function makes no assuptions about the coordinate system,
/// only that x and y are orthogonal. It uses good ole plain Pythagoras.
/// Ie., if x/y are in local coordinates, result is in meter.
/// if they are in geometric coordinates, result cannot be converted to an actual length,
/// but can still be used in relative comparions.
/// @note All results are square values. Functions avoids taking square roots for performance reasons.
/// @param pt_x Point's x coordinate
/// @param pt_y Point's y coordinate
/// @param ln_x1 Line: First endpoint's x coordinate
/// @param ln_y1 Line: First endpoint's y coordinate
/// @param ln_x2 Line: Second endpoint's x coordinate
/// @param ln_y2 Line: Second endpoint's y coordinate
/// @param[out] outResults Structure holding the results, see ::distToLineTy
void DistPointToLineSqr (double pt_x, double pt_y,
double ln_x1, double ln_y1,
double ln_x2, double ln_y2,
distToLineTy& outResults);

/// @brief Based on results from DistPointToLineSqr() computes locaton of base point on line
/// @param ln_x1 Line: First endpoint's x coordinate (same as passed in to DistPointToLineSqr())
/// @param ln_y1 Line: First endpoint's y coordinate (same as passed in to DistPointToLineSqr())
/// @param ln_x2 Line: Second endpoint's x coordinate (same as passed in to DistPointToLineSqr())
/// @param ln_y2 Line: Second endpoint's y coordinate (same as passed in to DistPointToLineSqr())
/// @param res Result returned by DistPointToLineSqr()
/// @param[out] x X coordinate of base point on the line
/// @param[out] y Y coordinate of base point on the line
void DistResultToBaseLoc (double ln_x1, double ln_y1,
double ln_x2, double ln_y2,
const distToLineTy& res,
double &x, double &y);

// returns terrain altitude at given position
// returns NaN in case of failure
double YProbe_at_m (const positionTy& posAt, XPLMProbeRef& probeRef);
Expand Down Expand Up @@ -223,6 +291,9 @@ double HeadingAvg (double h1, double h2, double f1=1, double f2=1);
/// -180 <= HeadingDiff <= 180
double HeadingDiff (double h1, double h2);

/// Normaize a heading to the value range [0..360)
double HeadingNormalize (double h);

// a bounding box has a north/west and a south/east corner
// we use positionTy for convenience...alt is usually not used here
struct boundingBoxTy {
Expand All @@ -239,7 +310,9 @@ struct boundingBoxTy {
boundingBoxTy (const positionTy& center, double width, double height = NAN );

/// Enlarge the box by the given x/y values in meters on each side (`y` defaults to `x`)
void enlarge (double x, double y = NAN);
void enlarge_m (double x, double y = NAN);
/// Increases the bounding box to include the given position
void enlarge_pos (double lat, double lon);
/// Increases the bounding box to include the given position
void enlarge (const positionTy& lPos);
/// Increases the bounding box to include the given position(s)
Expand All @@ -256,7 +329,12 @@ struct boundingBoxTy {

// is position within bounding box?
bool contains (const positionTy& pos ) const;
inline bool operator & (const positionTy& pos ) { return contains(pos); }
bool operator & (const positionTy& pos ) const { return contains(pos); }

/// Do both boxes overlap?
bool overlap (const boundingBoxTy& o) const;
/// Do both boxes overlap?
bool operator & (const boundingBoxTy& o) const { return overlap(o); }
};

#endif /* CoordCalc_h */
Loading

0 comments on commit 100774d

Please sign in to comment.