Spherical coordinate systems: splitted into "polar" and "equatorial" with opposite (co)latitude

[SVN r72233]
This commit is contained in:
Barend Gehrels 2011-05-27 22:01:05 +00:00
parent 80458f256d
commit 5eb0739f08
39 changed files with 411 additions and 167 deletions

View File

@ -27,8 +27,8 @@ int main()
double area = bg::area(poly);
std::cout << "Area: " << area << std::endl;
// Calculate the area of a spherical polygon
bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical<bg::degree> > > sph_poly;
// Calculate the area of a spherical equatorial polygon
bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
area = bg::area(sph_poly);
std::cout << "Area: " << area << std::endl;

View File

@ -27,8 +27,8 @@ int main()
double area = bg::area(poly);
std::cout << "Area: " << area << std::endl;
// Calculate the area of a spherical polygon
bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical<bg::degree> > > sph_poly;
// Calculate the area of a spherical polygon (for latitude: 0 at equator)
bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
area = bg::area(sph_poly);
std::cout << "Area: " << area << std::endl;

View File

@ -17,7 +17,7 @@
int main()
{
using namespace boost::geometry;
typedef model::point<float, 2, cs::spherical<degree> > P;
typedef model::point<float, 2, cs::spherical_equatorial<degree> > P;
model::linestring<P> line;
line.push_back(P(2, 41));
line.push_back(P(2, 48));

View File

@ -18,7 +18,8 @@ int main()
{
namespace bg = boost::geometry;
bg::model::point<long double, 2, bg::cs::spherical<bg::degree> > p1(5.0, 52.0);
// Select a point near the pole (theta=5.0, phi=15.0)
bg::model::point<long double, 2, bg::cs::spherical<bg::degree> > p1(15.0, 5.0);
// Transform from degree to radian. Default strategy is automatically selected,
// it will convert from degree to radian
@ -45,9 +46,9 @@ int main()
/*`
Output:
[pre
p1: (5, 52)
p2: (0.0872665, 0.907571)
p3: (0.785012, 0.0686797, 0.615661)
p1: (15, 5)
p2: (0.261799, 0.0872665)
p3: (0.084186, 0.0225576, 0.996195)
]
*/
//]

View File

@ -17,8 +17,8 @@ using namespace boost::geometry;
int main()
{
typedef model::point<double, 2, cs::spherical<degree> > degree_point;
typedef model::point<double, 2, cs::spherical<radian> > radian_point;
typedef model::point<double, 2, cs::spherical_equatorial<degree> > degree_point;
typedef model::point<double, 2, cs::spherical_equatorial<radian> > radian_point;
degree_point d(4.893, 52.373);
radian_point r(0.041, 0.8527);

View File

@ -135,7 +135,7 @@ int main(void)
//[quick_start_spherical
typedef boost::geometry::model::point
<
double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> spherical_point;
spherical_point amsterdam(4.90, 52.37);

View File

@ -50,7 +50,7 @@ int main()
// - from Cartesian to Spherical coordinate systems and back
// - from Cartesian to Cartesian (mapping, affine transformations) and back (inverse)
// - Map Projections
// - from Degree to Radian and back in spherical or geographic coordinate systems
// - from Degree to Radian and back in spherical_equatorial or geographic coordinate systems
return 0;
}

View File

@ -267,7 +267,7 @@ int main()
// (geographic calculations are in an extension; for sample it makes no difference)
typedef boost::geometry::model::point
<
double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> point_type;
typedef boost::geometry::model::linestring<point_type> line_type;

View File

@ -249,11 +249,11 @@ inline void build_route(Graph const& graph,
int main()
{
// Define a point in the Geographic coordinate system (currently Spherical)
// Define a point in the Geographic coordinate system (currently spherical-equatorial)
// (geographic calculations are in an extension; for sample it makes no difference)
typedef boost::geometry::model::point
<
double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> point_type;
typedef boost::geometry::model::linestring<point_type> line_type;

View File

@ -79,7 +79,7 @@ struct geographic
/*!
\brief Spherical coordinate system, in degree or in radian
\brief Spherical (polar) coordinate system, in degree or in radian
\details Defines the spherical coordinate system where points are
defined in two angles
and an optional radius usually known as r, theta, phi
@ -102,6 +102,25 @@ struct spherical
typedef DegreeOrRadian units;
};
/*!
\brief Spherical equatorial coordinate system, in degree or in radian
\details This one resembles the geographic coordinate system, and has latitude
up from zero at the equator, to 90 at the pole
(opposite to the spherical(polar) coordinate system).
Used in astronomy and in GIS (but there is also the geographic)
\see http://en.wikipedia.org/wiki/Spherical_coordinates
\ingroup cs
*/
template<typename DegreeOrRadian>
struct spherical_equatorial
{
typedef DegreeOrRadian units;
};
/*!
\brief Polar coordinate system
\details Defines the polar coordinate system "in which each point
@ -144,9 +163,16 @@ struct cs_tag<cs::geographic<DegreeOrRadian> >
template<typename DegreeOrRadian>
struct cs_tag<cs::spherical<DegreeOrRadian> >
{
typedef spherical_tag type;
typedef spherical_polar_tag type;
};
template<typename DegreeOrRadian>
struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
{
typedef spherical_equatorial_tag type;
};
template<>
struct cs_tag<cs::cartesian>
{

View File

@ -24,11 +24,15 @@ namespace boost { namespace geometry
/// Tag indicating Cartesian coordinate system family (cartesian,epsg)
struct cartesian_tag {};
/// Tag indicating Spherical polar coordinate system family
struct spherical_polar_tag {};
/// Tag indicating Spherical equatorial coordinate system family
struct spherical_equatorial_tag {};
/// Tag indicating Geographic coordinate system family (geographic)
struct geographic_tag {};
/// Tag indicating Spherical coordinate system family (spherical,celestial,...)
struct spherical_tag {};
// Tags defining tag hierarchy

View File

@ -188,7 +188,13 @@ struct default_strategy<point_tag, areal_tag, cartesian_tag, cartesian_tag, Poin
};
template <typename Point, typename PointOfSegment>
struct default_strategy<point_tag, areal_tag, spherical_tag, spherical_tag, Point, PointOfSegment>
struct default_strategy<point_tag, areal_tag, spherical_polar_tag, spherical_polar_tag, Point, PointOfSegment>
{
typedef winding<Point, PointOfSegment> type;
};
template <typename Point, typename PointOfSegment>
struct default_strategy<point_tag, areal_tag, spherical_equatorial_tag, spherical_equatorial_tag, Point, PointOfSegment>
{
typedef winding<Point, PointOfSegment> type;
};

View File

@ -21,6 +21,7 @@
#include <boost/geometry/util/select_coordinate_type.hpp>
#include <boost/geometry/strategies/side.hpp>
namespace boost { namespace geometry

View File

@ -45,6 +45,8 @@ http://trs-new.jpl.nasa.gov/dspace/bitstream/2014/40409/1/07-03.pdf, is simple
and works well in most cases but not in 180 meridian crossing cases. This probably
could be solved.
\note This version is made for spherical equatorial coordinate systems
\qbk{
[heading Example]
@ -161,11 +163,20 @@ private :
namespace services
{
template <typename Point>
struct default_strategy<spherical_tag, Point>
{
typedef strategy::area::huiller<Point> type;
};
template <typename Point>
struct default_strategy<spherical_equatorial_tag, Point>
{
typedef strategy::area::huiller<Point> type;
};
// Note: spherical polar coordinate system requires "get_as_radian_equatorial"
/***template <typename Point>
struct default_strategy<spherical_polar_tag, Point>
{
typedef strategy::area::huiller<Point> type;
};***/
} // namespace services

View File

@ -117,7 +117,7 @@ template
template<typename> class CoordinateSystem,
typename Units
>
struct strategy_compare<spherical_tag, 1, Point, CoordinateSystem<Units>, 0>
struct strategy_compare<spherical_polar_tag, 1, Point, CoordinateSystem<Units>, 0>
{
typedef typename coordinate_type<Point>::type coordinate_type;
typedef strategy::compare::circular_comparator
@ -134,7 +134,7 @@ template
template<typename> class CoordinateSystem,
typename Units
>
struct strategy_compare<spherical_tag, -1, Point, CoordinateSystem<Units>, 0>
struct strategy_compare<spherical_polar_tag, -1, Point, CoordinateSystem<Units>, 0>
{
typedef typename coordinate_type<Point>::type coordinate_type;
typedef strategy::compare::circular_comparator

View File

@ -219,7 +219,12 @@ struct comparable_type<cross_track<Point, PointOfSegment, CalculationType, Strat
};
template <typename Point, typename PointOfSegment, typename CalculationType, typename Strategy>
template
<
typename Point, typename PointOfSegment,
typename CalculationType,
typename Strategy
>
struct get_comparable<cross_track<Point, PointOfSegment, CalculationType, Strategy> >
{
typedef typename comparable_type
@ -234,7 +239,12 @@ public :
};
template <typename Point, typename PointOfSegment, typename CalculationType, typename Strategy>
template
<
typename Point, typename PointOfSegment,
typename CalculationType,
typename Strategy
>
struct result_from_distance<cross_track<Point, PointOfSegment, CalculationType, Strategy> >
{
private :
@ -248,7 +258,12 @@ public :
};
template <typename Point, typename PointOfSegment, typename CalculationType, typename Strategy>
template
<
typename Point, typename PointOfSegment,
typename CalculationType,
typename Strategy
>
struct strategy_point_point<cross_track<Point, PointOfSegment, CalculationType, Strategy> >
{
typedef Strategy type;
@ -256,9 +271,17 @@ struct strategy_point_point<cross_track<Point, PointOfSegment, CalculationType,
/*
TODO: spherical polar coordinate system requires "get_as_radian_equatorial<>"
template <typename Point, typename PointOfSegment, typename Strategy>
struct default_strategy<segment_tag, Point, PointOfSegment, spherical_tag, spherical_tag, Strategy>
struct default_strategy
<
segment_tag, Point, PointOfSegment,
spherical_polar_tag, spherical_polar_tag,
Strategy
>
{
typedef cross_track
<
@ -271,12 +294,40 @@ struct default_strategy<segment_tag, Point, PointOfSegment, spherical_tag, spher
typename default_strategy
<
point_tag, Point, PointOfSegment,
spherical_tag, spherical_tag
spherical_polar_tag, spherical_polar_tag
>::type,
Strategy
>::type
> type;
};
*/
template <typename Point, typename PointOfSegment, typename Strategy>
struct default_strategy
<
segment_tag, Point, PointOfSegment,
spherical_equatorial_tag, spherical_equatorial_tag,
Strategy
>
{
typedef cross_track
<
Point,
PointOfSegment,
void,
typename boost::mpl::if_
<
boost::is_void<Strategy>,
typename default_strategy
<
point_tag, Point, PointOfSegment,
spherical_equatorial_tag, spherical_equatorial_tag
>::type,
Strategy
>::type
> type;
};
} // namespace services

View File

@ -306,13 +306,16 @@ public :
};
// Register it as the default for point-types in a spherical coordinate system
// Register it as the default for point-types
// in a spherical equatorial coordinate system
template <typename Point1, typename Point2>
struct default_strategy<point_tag, Point1, Point2, spherical_tag, spherical_tag>
struct default_strategy<point_tag, Point1, Point2, spherical_equatorial_tag, spherical_equatorial_tag>
{
typedef strategy::distance::haversine<Point1, Point2> type;
};
// Note: spherical polar coordinate system requires "get_as_radian_equatorial"
} // namespace services
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS

View File

@ -160,6 +160,9 @@ namespace detail
assert_dimension<P, 3>();
// http://en.wikipedia.org/wiki/List_of_canonical_coordinate_transformations#From_spherical_coordinates
// http://www.vias.org/comp_geometry/math_coord_convert_3d.htm
// https://moodle.polymtl.ca/file.php/1183/Autres_Documents/Derivation_for_Spherical_Co-ordinates.pdf
// Phi = first, theta is second, r is third, see documentation on cs::spherical
// (calculations are splitted to implement ttmath)
@ -230,7 +233,7 @@ namespace detail
\tparam P2 second point type
*/
template <typename P1, typename P2>
struct from_spherical_2_to_cartesian_3
struct from_spherical_polar_2_to_cartesian_3
{
inline bool apply(P1 const& p1, P2& p2) const
{
@ -247,7 +250,7 @@ struct from_spherical_2_to_cartesian_3
\tparam P2 second point type
*/
template <typename P1, typename P2>
struct from_spherical_3_to_cartesian_3
struct from_spherical_polar_3_to_cartesian_3
{
inline bool apply(P1 const& p1, P2& p2) const
{
@ -267,7 +270,7 @@ struct from_spherical_3_to_cartesian_3
\note If x,y,z point is not lying on unit sphere, transformation will return false
*/
template <typename P1, typename P2>
struct from_cartesian_3_to_spherical_2
struct from_cartesian_3_to_spherical_polar_2
{
inline bool apply(P1 const& p1, P2& p2) const
{
@ -284,7 +287,7 @@ struct from_cartesian_3_to_spherical_2
\tparam P2 second point type
*/
template <typename P1, typename P2>
struct from_cartesian_3_to_spherical_3
struct from_cartesian_3_to_spherical_polar_3
{
inline bool apply(P1 const& p1, P2& p2) const
{
@ -343,30 +346,30 @@ struct default_strategy<CoordSysTag, CoordSysTag, CoordSys<radian>, CoordSys<deg
/// Specialization to transform from unit sphere(phi,theta) to XYZ
template <typename CoordSys1, typename CoordSys2, typename P1, typename P2>
struct default_strategy<spherical_tag, cartesian_tag, CoordSys1, CoordSys2, 2, 3, P1, P2>
struct default_strategy<spherical_polar_tag, cartesian_tag, CoordSys1, CoordSys2, 2, 3, P1, P2>
{
typedef from_spherical_2_to_cartesian_3<P1, P2> type;
typedef from_spherical_polar_2_to_cartesian_3<P1, P2> type;
};
/// Specialization to transform from sphere(phi,theta,r) to XYZ
template <typename CoordSys1, typename CoordSys2, typename P1, typename P2>
struct default_strategy<spherical_tag, cartesian_tag, CoordSys1, CoordSys2, 3, 3, P1, P2>
struct default_strategy<spherical_polar_tag, cartesian_tag, CoordSys1, CoordSys2, 3, 3, P1, P2>
{
typedef from_spherical_3_to_cartesian_3<P1, P2> type;
typedef from_spherical_polar_3_to_cartesian_3<P1, P2> type;
};
/// Specialization to transform from XYZ to unit sphere(phi,theta)
template <typename CoordSys1, typename CoordSys2, typename P1, typename P2>
struct default_strategy<cartesian_tag, spherical_tag, CoordSys1, CoordSys2, 3, 2, P1, P2>
struct default_strategy<cartesian_tag, spherical_polar_tag, CoordSys1, CoordSys2, 3, 2, P1, P2>
{
typedef from_cartesian_3_to_spherical_2<P1, P2> type;
typedef from_cartesian_3_to_spherical_polar_2<P1, P2> type;
};
/// Specialization to transform from XYZ to sphere(phi,theta,r)
template <typename CoordSys1, typename CoordSys2, typename P1, typename P2>
struct default_strategy<cartesian_tag, spherical_tag, CoordSys1, CoordSys2, 3, 3, P1, P2>
struct default_strategy<cartesian_tag, spherical_polar_tag, CoordSys1, CoordSys2, 3, 3, P1, P2>
{
typedef from_cartesian_3_to_spherical_3<P1, P2> type;
typedef from_cartesian_3_to_spherical_polar_3<P1, P2> type;
};

View File

@ -60,7 +60,7 @@ void test_all()
}
template <typename Point>
void test_spherical()
void test_spherical(bool polar = false)
{
bg::model::polygon<Point> geometry;
@ -79,6 +79,29 @@ void test_spherical()
area = bg::area(geometry, strategy);
BOOST_CHECK_CLOSE(area, 2.0 * 2.0 * expected, 0.0001);
{
bg::model::ring<Point> aurha; // a'dam-utr-rott.-den haag-a'dam
bg::read_wkt("POLYGON((4.892 52.373,5.119 52.093,4.479 51.930,4.23 52.08,4.892 52.373))", aurha);
if (polar)
{
// Create colatitudes (measured from pole)
BOOST_FOREACH(Point& p, aurha)
{
bg::set<1>(p, 90.0 - bg::get<1>(p));
}
bg::correct(aurha);
}
bg::strategy::area::huiller
<
typename bg::point_type<Point>::type
> huiller(6372.795);
area = bg::area(aurha, huiller);
BOOST_CHECK_CLOSE(area, 1476.645675, 0.0001);
// SQL Server gives: 1481.55595960659
// for select geography::STGeomFromText('POLYGON((4.892 52.373,4.23 52.08,4.479 51.930,5.119 52.093,4.892 52.373))',4326).STArea()/1000000.0
}
}
template <typename P>
@ -116,7 +139,8 @@ int test_main(int, char* [])
test_all<bg::model::point<float, 2, bg::cs::cartesian> >();
test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
test_spherical<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >();
test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
test_spherical<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >(true);
test_ccw<bg::model::point<double, 2, bg::cs::cartesian> >();
test_open<bg::model::point<double, 2, bg::cs::cartesian> >();

View File

@ -96,11 +96,11 @@ int test_main(int, char* [])
test_all<bg::model::d2::point_xy<float> >();
test_all<bg::model::d2::point_xy<double> >();
test_spherical<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >();
test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
#if defined(HAVE_TTMATH)
test_all<bg::model::d2::point_xy<ttmath_big> >();
test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical<bg::degree> > >();
test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
#endif
return 0;

View File

@ -14,6 +14,7 @@
#include <geometry_test_common.hpp>
#include <boost/geometry/algorithms/area.hpp>
#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>

View File

@ -94,6 +94,29 @@ template <> struct string_from_type<long double>
#endif
struct geographic_policy
{
template <typename CoordinateType>
static inline CoordinateType apply(CoordinateType const& value)
{
return value;
}
};
struct mathematical_policy
{
template <typename CoordinateType>
static inline CoordinateType apply(CoordinateType const& value)
{
return 90 - value;
}
};
// For all tests:
// - do NOT use "using namespace boost::geometry" to make clear what is Boost.Geometry
// - use bg:: as short alias

View File

@ -28,9 +28,10 @@
#include <boost/geometry/geometries/segment.hpp>
// This test is GIS oriented.
template <typename Point>
template <typename Point, typename LatitudePolicy>
void test_distance(
typename bg::coordinate_type<Point>::type const& lon1,
typename bg::coordinate_type<Point>::type const& lat1,
@ -60,9 +61,9 @@ void test_distance(
Point p1, p2, p3;
bg::assign_values(p1, lon1, lat1);
bg::assign_values(p2, lon2, lat2);
bg::assign_values(p3, lon3, lat3);
bg::assign_values(p1, lon1, LatitudePolicy::apply(lat1));
bg::assign_values(p2, lon2, LatitudePolicy::apply(lat2));
bg::assign_values(p3, lon3, LatitudePolicy::apply(lat3));
strategy_type strategy;
@ -83,29 +84,30 @@ void test_distance(
}
template <typename Point>
template <typename Point, typename LatitudePolicy>
void test_all()
{
typename bg::coordinate_type<Point>::type const average_earth_radius = 6372795.0;
// distance (Paris <-> Amsterdam/Barcelona),
// with coordinates rounded as below ~87 km
// should be is equal
// to distance (Paris <-> Barcelona/Amsterdam)
// is equal to distance (Paris <-> Barcelona/Amsterdam)
typename bg::coordinate_type<Point>::type const p_to_ab = 86.798321 * 1000.0;
test_distance<Point>(2, 48, 4, 52, 2, 41, average_earth_radius, p_to_ab, 0.1);
test_distance<Point>(2, 48, 2, 41, 4, 52, average_earth_radius, p_to_ab, 0.1);
test_distance<Point, LatitudePolicy>(2, 48, 4, 52, 2, 41, average_earth_radius, p_to_ab, 0.1);
test_distance<Point, LatitudePolicy>(2, 48, 2, 41, 4, 52, average_earth_radius, p_to_ab, 0.1);
}
int test_main(int, char* [])
{
test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >();
test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> >, geographic_policy >();
// NYI: haversine for mathematical spherical coordinate systems
// test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> >, mathematical_policya >();
#if defined(HAVE_TTMATH)
typedef ttmath::Big<1,4> tt;
//test_all<bg::model::point<tt, 2, bg::cs::spherical<bg::degree> > >();
//test_all<bg::model::point<tt, 2, bg::cs::geographic<bg::degree> >, geographic_policy>();
#endif
return 0;

View File

@ -34,7 +34,7 @@
double const average_earth_radius = 6372795.0;
template <typename Point>
template <typename Point, typename LatitudePolicy>
struct test_distance
{
typedef bg::strategy::distance::haversine
@ -60,15 +60,15 @@ struct test_distance
haversine_type strategy(radius);
Point p1, p2;
bg::assign_values(p1, lon1, lat1);
bg::assign_values(p2, lon2, lat2);
bg::assign_values(p1, lon1, LatitudePolicy::apply(lat1));
bg::assign_values(p2, lon2, LatitudePolicy::apply(lat2));
return_type d = strategy.apply(p1, p2);
BOOST_CHECK_CLOSE(d, expected, tolerance);
}
};
template <typename Point>
template <typename Point, typename LatitudePolicy>
void test_all()
{
// earth to unit-sphere -> divide by earth circumference, then it is from 0-1,
@ -77,19 +77,19 @@ void test_all()
// ~ Amsterdam/Paris, 467 kilometers
double const a_p = 467.2704 * 1000.0;
test_distance<Point>::test(4, 52, 2, 48, average_earth_radius, a_p, 1.0);
test_distance<Point>::test(2, 48, 4, 52, average_earth_radius, a_p, 1.0);
test_distance<Point>::test(4, 52, 2, 48, 1.0, a_p * e2u, 0.001);
test_distance<Point, LatitudePolicy>::test(4, 52, 2, 48, average_earth_radius, a_p, 1.0);
test_distance<Point, LatitudePolicy>::test(2, 48, 4, 52, average_earth_radius, a_p, 1.0);
test_distance<Point, LatitudePolicy>::test(4, 52, 2, 48, 1.0, a_p * e2u, 0.001);
// ~ Amsterdam/Barcelona
double const a_b = 1232.9065 * 1000.0;
test_distance<Point>::test(4, 52, 2, 41, average_earth_radius, a_b, 1.0);
test_distance<Point>::test(2, 41, 4, 52, average_earth_radius, a_b, 1.0);
test_distance<Point>::test(4, 52, 2, 41, 1.0, a_b * e2u, 0.001);
test_distance<Point, LatitudePolicy>::test(4, 52, 2, 41, average_earth_radius, a_b, 1.0);
test_distance<Point, LatitudePolicy>::test(2, 41, 4, 52, average_earth_radius, a_b, 1.0);
test_distance<Point, LatitudePolicy>::test(4, 52, 2, 41, 1.0, a_b * e2u, 0.001);
}
template <typename P1, typename P2, typename CalculationType>
template <typename P1, typename P2, typename CalculationType, typename LatitudePolicy>
void test_services()
{
namespace bgsd = bg::strategy::distance;
@ -244,9 +244,12 @@ double time_normal(int n)
int test_main(int, char* [])
{
test_all<bg::model::point<int, 2, bg::cs::spherical<bg::degree> > >();
test_all<bg::model::point<float, 2, bg::cs::spherical<bg::degree> > >();
test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >();
test_all<bg::model::point<int, 2, bg::cs::spherical_equatorial<bg::degree> >, geographic_policy>();
test_all<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> >, geographic_policy>();
test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> >, geographic_policy>();
// NYI: haversine for mathematical spherical coordinate systems
// test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> >, mathematical_policy>();
//double t1 = time_sqrt(20000);
//double t2 = time_normal(20000);
@ -255,15 +258,16 @@ int test_main(int, char* [])
#if defined(HAVE_TTMATH)
typedef ttmath::Big<1,4> tt;
test_all<bg::model::point<tt, 2, bg::cs::spherical<bg::degree> > >();
test_all<bg::model::point<tt, 2, bg::cs::spherical<bg::degree> >, geographic_policy>();
#endif
test_services
<
bg::model::point<float, 2, bg::cs::spherical<bg::degree> >,
bg::model::point<double, 2, bg::cs::spherical<bg::degree> >,
double
bg::model::point<double, 2, bg::cs::spherical<bg::degree> >,
double,
geographic_policy
>();
return 0;

View File

@ -91,7 +91,7 @@ static void test_segment_intersection(int caseno,
#endif
typedef typename bg::coordinate_type<P>::type coordinate_type;
typedef segment<const P> segment_type;
typedef bg::model::referring_segment<const P> segment_type;
P p1, p2, p3, p4;
bg::assign_values(p1, x1, y1);

View File

@ -64,7 +64,7 @@ static void test_segment_intersection(std::string const& case_id,
//#endif
typedef typename bg::coordinate_type<P>::type coordinate_type;
typedef bg::segment<const P> segment_type;
typedef bg::model::referring_segment<const P> segment_type;
P p1, p2, p3, p4;
bg::assign_values(p1, x1, y1);

View File

@ -1,54 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <geometry_test_common.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/strategies/spherical/side_by_cross_track.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/segment.hpp>
template <typename Point>
void test_side(double lon1, double lat1,
double lon2, double lat2,
double lon3, double lat3,
int expected)
{
typedef bg::strategy::side::side_by_cross_track<double> strategy;
Point p1, p2, p3;
bg::assign_values(p1, lon1, lat1);
bg::assign_values(p2, lon2, lat2);
bg::assign_values(p3, lon3, lat3);
int s = strategy::apply(p1, p2, p3);
}
template <typename Point>
void test_all()
{
test_side<Point>(2.0, 48.0, 4.0, 52.0, 2.0, 41.0, 1);
test_side<Point>(2.0, 48.0, 2.0, 41.0, 4.0, 52.0, -1);
}
int test_main(int, char* [])
{
test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >();
double a = 0;
double b = sin(a);
return 0;
}

View File

@ -0,0 +1,137 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <geometry_test_common.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/strategies/spherical/side_by_cross_track.hpp>
#include <boost/geometry/strategies/spherical/side_via_plane.hpp>
#include <boost/geometry/strategies/spherical/ssf.hpp>
#include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/segment.hpp>
namespace boost { namespace geometry {
template <typename Vector, typename Point1, typename Point2>
static inline Vector create_vector(Point1 const& p1, Point2 const& p2)
{
Vector v;
convert(p1, v);
subtract_point(v, p2);
return v;
}
}}
inline char side_char(int side)
{
return side == 1 ? 'L'
: side == -1 ? 'R'
: '-'
;
}
template <typename Point>
void test_side1(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3,
int expected)
{
std::cout << case_id << ": ";
//int s = bg::strategy::side::side_via_plane<>::apply(p1, p2, p3);
int side1 = bg::strategy::side::spherical_side_formula<>::apply(p1, p2, p3);
int side2 = bg::strategy::side::side_via_plane<>::apply(p1, p2, p3);
int side3 = bg::strategy::side::side_by_cross_track<>::apply(p1, p2, p3);
typedef bg::strategy_side<bg::spherical_equatorial_tag>::type spherical_strategy;
//int side4 = spherical_strategy::apply(p1, p2, p3);
typedef bg::strategy_side<bg::cartesian_tag>::type cartesian_strategy;
int side5 = cartesian_strategy::apply(p1, p2, p3);
//BOOST_CHECK_EQUAL(side1, expected);
//BOOST_CHECK_EQUAL(side2, expected);
std::cout
<< "exp: " << side_char(expected)
<< " ssf: " << side_char(side1)
<< " pln: " << side_char(side2)
<< " ct: " << side_char(side3)
//<< " def: " << side_char(side4)
<< " cart: " << side_char(side5)
<< std::endl;
}
template <typename Point>
void test_side(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3,
int expected)
{
test_side1(case_id, p1, p2, p3, expected);
//test_side1(case_id, p2, p1, p3, -expected);
}
template <typename Point>
void test_all()
{
typedef std::pair<double, double> pair;
Point amsterdam(5.9, 52.4);
Point barcelona(2.0, 41.0);
Point paris(2.0, 48.0);
Point milan(7.0, 45.0);
goto wrong;
test_side<Point>("bp-m", barcelona, paris, milan, -1);
test_side<Point>("bm-p", barcelona, milan, paris, 1);
test_side<Point>("mp-b", milan, paris, barcelona, 1);
test_side<Point>("am-p", amsterdam, milan, paris, -1);
test_side<Point>("pm-a", paris, milan, amsterdam, 1);
wrong:
Point blog_p1(10.0, 30.0);
Point blog_p2(50.0, 50.0);
Point blog_p(30.0, 39.0);
test_side<Point>("blog1", blog_p1, blog_p2, blog_p, 1);
return;
// http://www.gcmap.com/mapui?P=50N+80E-60N+50W,65N+30E
//Point blog_np1(80.0, 50.0);
//Point blog_np2(-50.0, 60.0);
// http://www.gcmap.com/mapui?P=50N+140E-60N+10E,65N+30E
Point blog_np1(140.0, 50.0);
Point blog_np2(10.0, 60.0);
Point blog_np(30.0, 65.0);
//test_side<Point>(blog_np1, blog_np2, blog_np, 1);
test_side<Point>("40", blog_np1, blog_np2, Point(30.0, 40.0), 1);
test_side<Point>("45", blog_np1, blog_np2, Point(30.0, 45.0), 1);
test_side<Point>("50", blog_np1, blog_np2, Point(30.0, 50.0), 1);
test_side<Point>("55", blog_np1, blog_np2, Point(30.0, 55.0), 1);
test_side<Point>("60", blog_np1, blog_np2, Point(30.0, 60.0), 1);
test_side<Point>("65", blog_np1, blog_np2, Point(30.0, 65.0), 1);
test_side<Point>("70", blog_np1, blog_np2, Point(30.0, 70.0), 1);
test_side<Point>("75", blog_np1, blog_np2, Point(30.0, 75.0), 1);
}
int test_main(int, char* [])
{
//test_all<bg::model::point<int, 2, bg::cs::spherical<bg::degree> > >();
test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >();
return 0;
}

View File

@ -2,9 +2,9 @@
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="side_by_cross_track"
Name="spherical_side"
ProjectGUID="{ADBE38D8-1828-48A2-BBA1-81F50B53C67C}"
RootNamespace="side_by_cross_track"
RootNamespace="spherical_side"
Keyword="Win32Proj"
>
<Platforms>
@ -18,7 +18,7 @@
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\side_by_cross_track"
IntermediateDirectory="$(ConfigurationName)\spherical_side"
ConfigurationType="1"
InheritedPropertySheets="..\boost.vsprops"
CharacterSet="1"
@ -91,7 +91,7 @@
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\side_by_cross_track"
IntermediateDirectory="$(ConfigurationName)\spherical_side"
ConfigurationType="1"
InheritedPropertySheets="..\boost.vsprops"
CharacterSet="1"
@ -165,7 +165,7 @@
</References>
<Files>
<File
RelativePath=".\side_by_cross_track.cpp"
RelativePath=".\spherical_side.cpp"
>
</File>
</Files>

View File

@ -14,7 +14,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "projected_point", "projecte
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "segment_intersection_collinear", "segment_intersection_collinear.vcproj", "{2D0CB6D3-6ABC-4119-A235-66E6065A279E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "side_by_cross_track", "side_by_cross_track.vcproj", "{ADBE38D8-1828-48A2-BBA1-81F50B53C67C}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spherical_side", "spherical_side.vcproj", "{ADBE38D8-1828-48A2-BBA1-81F50B53C67C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "within", "within.vcproj", "{AB13D2AC-FD34-4DE4-BD8E-4D463050E5DD}"
EndProject

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\andoyer"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops"
InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
CharacterSet="1"
>
<Tool
@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../../../..;../../..;../../../../../../boost/geometry/extensions/contrib"
AdditionalIncludeDirectories="../../../../../..;../..;../../../../../../boost/geometry/extensions/contrib"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
ExceptionHandling="2"
RuntimeLibrary="1"
@ -93,7 +93,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\andoyer"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops"
InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>
@ -114,7 +114,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../../../..;../../..;../../../../../../boost/geometry/extensions/contrib"
AdditionalIncludeDirectories="../../../../../..;../..;../../../../../../boost/geometry/extensions/contrib"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
ExceptionHandling="2"
UsePrecompiledHeader="0"

View File

@ -32,7 +32,7 @@
#include <boost/geometry/extensions/gis/projections/parameters.hpp>
#include <boost/geometry/extensions/gis/projections/proj/sterea.hpp>
#include <test_common/test_point.hpp>
//#include <test_common/test_point.hpp>
template <typename PRJ, typename XY, typename LL>
@ -177,6 +177,7 @@ void test_latlong(double perc)
// with holes
test_area_polygon_ll<bg::model::d2::point_xy<T>, bg::model::ll::point<bg::degree, T> >(false, true, perc);
}
int test_main(int, char* [])

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\area_ll"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
>
<Tool
@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../../../..;../../.."
AdditionalIncludeDirectories="../../../../..;../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
ExceptionHandling="2"
RuntimeLibrary="1"
@ -93,7 +93,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\area_ll"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>
@ -114,7 +114,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../../../..;../../.."
AdditionalIncludeDirectories="../../../../..;../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
ExceptionHandling="2"
UsePrecompiledHeader="0"

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\cross_track"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops"
InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
CharacterSet="1"
>
<Tool
@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../../../..;../../.."
AdditionalIncludeDirectories="../../../../../..;../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
ExceptionHandling="2"
RuntimeLibrary="1"
@ -93,7 +93,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\cross_track"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops"
InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>
@ -114,7 +114,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../../../..;../../.."
AdditionalIncludeDirectories="../../../../../..;../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
ExceptionHandling="2"
UsePrecompiledHeader="0"

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\distance_mixed"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
>
<Tool
@ -94,7 +94,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\distance_mixed"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>

View File

@ -21,7 +21,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\parse"
ConfigurationType="1"
InheritedPropertySheets="../../../boost.vsprops"
InheritedPropertySheets="../../boost.vsprops"
CharacterSet="1"
>
<Tool
@ -91,7 +91,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\parse"
ConfigurationType="1"
InheritedPropertySheets="../../../boost.vsprops"
InheritedPropertySheets="../../boost.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\parse_dms"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
>
<Tool
@ -93,7 +93,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\parse_dms"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\point_ll"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
>
<Tool
@ -93,7 +93,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\point_ll"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops"
InheritedPropertySheets="..\..\boost.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>

View File

@ -20,7 +20,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\vincenty"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops"
InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
CharacterSet="1"
>
<Tool
@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../../../..;../../..;../../../../../../boost/geometry/extensions/contrib"
AdditionalIncludeDirectories="../../../../../..;../..;../../../../../../boost/geometry/extensions/contrib"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
ExceptionHandling="2"
RuntimeLibrary="1"
@ -93,7 +93,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\vincenty"
ConfigurationType="1"
InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops"
InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>
@ -114,7 +114,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../../../..;../../..;../../../../../../boost/geometry/extensions/contrib"
AdditionalIncludeDirectories="../../../../../..;../..;../../../../../../boost/geometry/extensions/contrib"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
ExceptionHandling="2"
UsePrecompiledHeader="0"