Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for spherical_coslat_differential #123

Closed
wants to merge 11 commits into from
349 changes: 323 additions & 26 deletions include/boost/astronomy/coordinate/arithmetic.hpp

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions include/boost/astronomy/coordinate/base_differential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ struct base_differential
{
return this->diff;
}
//! returns the differential of calling object
bg::model::point
<
CoordinateType,
DimensionCount,
CoordinateSystem
>
get_point() const
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function to return current differential of this object. By doing this we are able to calculate cross of differential objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at #123 (comment)

Copy link
Member

@sarthak2007 sarthak2007 Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the need of this function? get_differential is already there in base_differential.hpp.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By doing this we can extend all arithmetic function to work for differentials as well. Otherwise, we may get a conflict of .get_point() in all arithmetic functions.

Copy link
Member

@sarthak2007 sarthak2007 Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this will help in magnitude function. But functions like sum, mean, difference, dot use make_cartesian_representation() and hence can't be extended to work for differentials by defining get_point for differential.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll also help to calculate cross for two differential classes or one representation class and one differential class. In the code where we used
bg::transform(cartesian1.get_point(), tempPoint1); bg::transform(cartesian2.get_point(), tempPoint2);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarthak2007 I'm closing this PR. I have created a separate PR #127 for the extension of arithmetic functions to support differential systems.

{
return this->diff;
}

template
<
Expand Down
76 changes: 76 additions & 0 deletions include/boost/astronomy/coordinate/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <boost/astronomy/coordinate/cartesian_representation.hpp>
#include <boost/astronomy/coordinate/spherical_representation.hpp>
#include <boost/astronomy/coordinate/spherical_equatorial_representation.hpp>
#include <boost/astronomy/coordinate/differential.hpp>

namespace boost { namespace astronomy { namespace coordinate {

Expand Down Expand Up @@ -70,6 +71,81 @@ std::ostream& operator<< (std::ostream &out, spherical_representation

return out;
}
//!"<<" operator overload to print details of a Cartesian differential point
template
<
typename CoordinateType,
class XQuantity,
class YQuantity,
class ZQuantity
>
std::ostream& operator<< (std::ostream &out, cartesian_differential
<CoordinateType, XQuantity, YQuantity, ZQuantity> const& point)
{
out << "Cartesian differential ( "
<< point.get_dx() << " , "
<< point.get_dy() << " , "
<< point.get_dz() << " )";

return out;
}

//!"<<" operator overload to print details of a Spherical Equatorial differential Point
template
<
typename CoordinateType,
class LatQuantity,
class LonQuantity,
class DistQuantity
>
std::ostream& operator<< (std::ostream &out, spherical_equatorial_differential
<CoordinateType, LatQuantity, LonQuantity, DistQuantity> const& point)
{
out << "Spherical Equatorial differential ( "
<< point.get_dlat() << " , "
<< point.get_dlon() << " , "
<< point.get_ddist() << " )";

return out;
}

//!"<<" operator overload to print details of a Spherical differential point
template
<
typename CoordinateType,
class LatQuantity,
class LonQuantity,
class DistQuantity
>
std::ostream& operator<< (std::ostream &out, spherical_differential
<CoordinateType, LatQuantity, LonQuantity, DistQuantity> const& point)
{
out << "Spherical differential ( "
<< point.get_dlat() << " , "
<< point.get_dlon() << " , "
<< point.get_ddist() << " )";

return out;
}

//!"<<" operator overload to print details of a spherical_coslat_differential
template
<
typename CoordinateType,
class LatQuantity,
class LonQuantity,
class DistQuantity
>
std::ostream& operator<< (std::ostream &out, spherical_coslat_differential
<CoordinateType, LatQuantity, LonQuantity, DistQuantity> const& point)
{
out << "Spherical Coslat Differential ( "
<< point.get_dlat() << " , "
<< point.get_dlon_coslat() << " , "
<< point.get_ddist() << " )";

return out;
}

}}} //namespace boost::astronomy::coordinate
#endif // !BOOST_ASTRONOMY_COORDINATE_IO_HPP
3 changes: 2 additions & 1 deletion test/coordinate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ foreach(_name
spherical_representation
spherical_differential
spherical_equatorial_representation
spherical_equatorial_differential)
spherical_equatorial_differential
spherical_coslat_differential)
set(_target test_coordinate_${_name})

add_executable(${_target} "")
Expand Down
1 change: 1 addition & 0 deletions test/coordinate/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ run spherical_representation.cpp ;
run spherical_differential.cpp ;
run spherical_equatorial_representation.cpp ;
run spherical_equatorial_differential.cpp ;
run spherical_coslat_differential.cpp ;
44 changes: 40 additions & 4 deletions test/coordinate/cartesian_representation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <boost/astronomy/coordinate/arithmetic.hpp>
#include <boost/astronomy/coordinate/representation.hpp>


using namespace std;
using namespace boost::astronomy::coordinate;
using namespace boost::units::si;
Expand Down Expand Up @@ -208,16 +209,15 @@ BOOST_AUTO_TEST_CASE(cartesian_representation_cross_product)

auto result = cross(point1, point2);

BOOST_CHECK_CLOSE(result.get_x().value(), -180.0, 0.001);
BOOST_CHECK_CLOSE(result.get_x().value(), -180, 0.001);
BOOST_CHECK_CLOSE(result.get_y().value(), 11.988, 0.001);
BOOST_CHECK_CLOSE(result.get_z().value(), -1485.0, 0.001);
BOOST_CHECK_CLOSE(result.get_z().value(), -1485, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(result.get_x()), quantity
<bu::multiply_typeof_helper<decltype(si::kilo*meters), si::length>::type>>::value));
BOOST_TEST((std::is_same<decltype(result.get_y()), quantity
<bu::multiply_typeof_helper<decltype(si::mega*meters),
decltype(si::milli*meters)>::type>>::value));
<bu::multiply_typeof_helper<decltype(si::kilo*meters), si::length>::type>>::value));
BOOST_TEST((std::is_same<decltype(result.get_z()), quantity
<bu::multiply_typeof_helper<decltype(si::centi*meters), si::length>::type>>::value));
}
Expand Down Expand Up @@ -254,6 +254,23 @@ BOOST_AUTO_TEST_CASE(cartesian_representation_unit_vector)
BOOST_TEST((std::is_same<decltype(result.get_z()), quantity<si::length>>::value));
}

BOOST_AUTO_TEST_CASE(cartesian_representation_two_point_unit_vector)
{
auto point1 = make_cartesian_representation(25.0*meter, 36.0*meter, 90.0*meter);
auto point2 = make_cartesian_representation(24.0*meter,35.0*meter,89.0*meter);

auto result = boost::astronomy::coordinate::unit_vector(point1,point2);

BOOST_CHECK_CLOSE(result.get_x().value(), 0.5773502691896258, 0.001);
BOOST_CHECK_CLOSE(result.get_y().value(), 0.5773502691896258, 0.001);
BOOST_CHECK_CLOSE(result.get_z().value(), 0.5773502691896258, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(result.get_x()), quantity<si::length>>::value));
BOOST_TEST((std::is_same<decltype(result.get_y()), quantity<si::length>>::value));
BOOST_TEST((std::is_same<decltype(result.get_z()), quantity<si::length>>::value));
}

BOOST_AUTO_TEST_CASE(cartesian_representation_magnitude)
{
auto point1 = make_cartesian_representation
Expand Down Expand Up @@ -287,6 +304,25 @@ BOOST_AUTO_TEST_CASE(cartesian_representation_sum)
BOOST_TEST((std::is_same<decltype(result.get_z()), quantity<si::length>>::value));
}

BOOST_AUTO_TEST_CASE(cartesian_representation_difference)
{
auto point1 = make_cartesian_representation
(10.0 * meter, 20.0 * si::kilo * meters, 30.0 * meter);
auto point2 = make_cartesian_representation
(50.0 * si::centi * meter, 60.0 * meter, 30.0 * meter);

auto result = boost::astronomy::coordinate::difference(point1, point2);

BOOST_CHECK_CLOSE(result.get_x().value(), 9.5, 0.001);
BOOST_CHECK_CLOSE(result.get_y().value(), 19.94, 0.001);
BOOST_CHECK_CLOSE(result.get_z().value(), 0, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(result.get_x()), quantity<si::length>>::value));
BOOST_TEST((std::is_same<decltype(result.get_y()), quantity<decltype(si::kilo*meter)>>::value));
BOOST_TEST((std::is_same<decltype(result.get_z()), quantity<si::length>>::value));
}

BOOST_AUTO_TEST_CASE(cartesian_representation_mean)
{
auto point1 = make_cartesian_representation
Expand Down
Loading