Skip to content

Commit

Permalink
overload ==operator in coordinate systems
Browse files Browse the repository at this point in the history
  • Loading branch information
rjnrohit committed Apr 21, 2020
1 parent 2a312f2 commit 6a91de4
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/boost/astronomy/coordinate/cartesian_representation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <boost/units/get_dimension.hpp>
#include <boost/units/systems/si/dimensionless.hpp>

#include <boost/test/tools/floating_point_comparison.hpp>

#include <boost/astronomy/detail/is_base_template_of.hpp>
#include <boost/astronomy/coordinate/base_representation.hpp>

Expand Down Expand Up @@ -205,6 +207,29 @@ struct cartesian_representation: base_representation<3, bg::cs::cartesian, Coord
>(result);
}

//!"==" operator to compare with other representations
template
<typename Representation>
bool operator ==(Representation const& other) const
{
auto tempRep1 = make_cartesian_representation(other);

return
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<XQuantity>(tempRep1.get_x()).value(),
this->get_x().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<YQuantity>(tempRep1.get_y()).value(),
this->get_y().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<ZQuantity>(tempRep1.get_z()).value(),
this->get_z().value());
}
}; //cartesian_representation


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <boost/units/systems/si/dimensionless.hpp>
#include <boost/units/systems/si/plane_angle.hpp>

#include <boost/test/tools/floating_point_comparison.hpp>

#include <boost/astronomy/detail/is_base_template_of.hpp>
#include <boost/astronomy/coordinate/base_differential.hpp>
#include <boost/astronomy/coordinate/cartesian_differential.hpp>
Expand Down Expand Up @@ -256,6 +258,28 @@ struct spherical_coslat_differential : public base_differential

return product;
}

//!"==" operator to compare with other differentials
template
<typename Differential>
bool operator ==(Differential const& other) const
{
auto tempRep1 = make_spherical_coslat_differential(other);

return
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LatQuantity>(tempRep1.get_dlat()).value(),this->get_dlat().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LonQuantity>(tempRep1.get_dlon_coslat()).value(),
this->get_dlon_coslat().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<DistQuantity>(tempRep1.get_ddist()).value(),this->get_ddist().value());
}
}; //spherical_coslat_differential

//!constructs object from provided components of differential
Expand Down
26 changes: 26 additions & 0 deletions include/boost/astronomy/coordinate/spherical_differential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <boost/units/systems/si/dimensionless.hpp>
#include <boost/units/systems/si/plane_angle.hpp>

#include <boost/test/tools/floating_point_comparison.hpp>

#include <boost/astronomy/detail/is_base_template_of.hpp>
#include <boost/astronomy/coordinate/base_differential.hpp>
#include <boost/astronomy/coordinate/cartesian_differential.hpp>
Expand Down Expand Up @@ -249,6 +251,30 @@ struct spherical_differential : public base_differential

return product;
}

//!"==" operator to compare with other differentials
template
<typename Differential>
bool operator ==(Differential const& other) const
{
auto tempRep1 = make_spherical_differential(other);

return
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LatQuantity>(tempRep1.get_dlat()).value(),
this->get_dlat().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LonQuantity>(tempRep1.get_dlon()).value(),
this->get_dlon().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<DistQuantity>(tempRep1.get_ddist()).value(),
this->get_ddist().value());
}
}; //spherical_differential

//!constructs object from provided components of differential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <boost/units/systems/si/dimensionless.hpp>
#include <boost/units/systems/si/plane_angle.hpp>

#include <boost/test/tools/floating_point_comparison.hpp>

#include <boost/astronomy/detail/is_base_template_of.hpp>
#include <boost/astronomy/coordinate/base_differential.hpp>
#include <boost/astronomy/coordinate/cartesian_differential.hpp>
Expand Down Expand Up @@ -249,6 +251,30 @@ struct spherical_equatorial_differential : public base_differential

return product;
}

//!"==" operator to compare with other differentials
template
<typename Differential>
bool operator ==(Differential const& other) const
{
auto tempRep1 = make_spherical_equatorial_differential(other);

return
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LatQuantity>(tempRep1.get_dlat()).value(),
this->get_dlat().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LonQuantity>(tempRep1.get_dlon()).value(),
this->get_dlon().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<DistQuantity>(tempRep1.get_ddist()).value(),
this->get_ddist().value());
}
}; //spherical_equatorial_differential

//!constructs object from provided components of differential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <boost/units/get_dimension.hpp>
#include <boost/units/systems/si/dimensionless.hpp>

#include <boost/test/tools/floating_point_comparison.hpp>

#include <boost/astronomy/detail/is_base_template_of.hpp>
#include <boost/astronomy/coordinate/base_representation.hpp>
#include <boost/astronomy/coordinate/cartesian_representation.hpp>
Expand Down Expand Up @@ -227,6 +229,29 @@ struct spherical_equatorial_representation : public base_representation
return result;
}

//!"==" operator to compare with other representations
template
<typename Representation>
bool operator ==(Representation const& other) const
{
auto tempRep1 = make_spherical_equatorial_representation(other);

return
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LatQuantity>(tempRep1.get_lat()).value(),
this->get_lat().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LonQuantity>(tempRep1.get_lon()).value(),
this->get_lon().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<DistQuantity>(tempRep1.get_dist()).value(),
this->get_dist().value());
}
}; //spherical_equatorial_representation


Expand Down
26 changes: 26 additions & 0 deletions include/boost/astronomy/coordinate/spherical_representation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/units/systems/si/dimensionless.hpp>

#include <boost/test/tools/floating_point_comparison.hpp>

#include <boost/astronomy/detail/is_base_template_of.hpp>
#include <boost/astronomy/coordinate/base_representation.hpp>
#include <boost/astronomy/coordinate/cartesian_representation.hpp>
Expand Down Expand Up @@ -204,6 +206,7 @@ struct spherical_representation : public base_representation
bg::set<2>(this->point, distance.value());
}

//!"+" operator to add any other representations
template<typename Addend>
spherical_representation
<
Expand Down Expand Up @@ -233,6 +236,29 @@ struct spherical_representation : public base_representation
return result;
}

//!"==" operator to compare with other representations
template
<typename Representation>
bool operator ==(Representation const& other) const
{
auto tempRep1 = make_spherical_representation(other);

return
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LatQuantity>(tempRep1.get_lat()).value(),
this->get_lat().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<LonQuantity>(tempRep1.get_lon()).value(),
this->get_lon().value())
&&
boost::math::fpc::close_at_tolerance<CoordinateType>
(boost::math::fpc::percent_tolerance(1e-10),boost::math::fpc::FPC_STRONG)
(static_cast<DistQuantity>(tempRep1.get_dist()).value(),
this->get_dist().value());
}
}; //spherical_representation


Expand Down

0 comments on commit 6a91de4

Please sign in to comment.