Skip to content

Commit

Permalink
Merge branch 'tickets/DM-11473'
Browse files Browse the repository at this point in the history
  • Loading branch information
r-owen committed Oct 4, 2017
2 parents 6486c12 + 4934e7e commit 6058802
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
11 changes: 7 additions & 4 deletions include/lsst/afw/geom/SpherePoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ class SpherePoint final {
SpherePoint(Angle const& longitude, Angle const& latitude);

/**
* Construct a SpherePoint from a two-element array of radians
* Construct a SpherePoint from double longitude and latitude.
*
* @param lonLatRad Longitude, latitude, both in radians.
* @param longitude The longitude of the point.
* @param latitude The latitude of the point. Must be in the
* interval [-π/2, π/2] radians.
* @param units The units of longitude and latitude
*
* @throws pex::exceptions::InvalidParameterError
* Thrown if latitude is out of range.
* Thrown if `latitude` isout of range.
*
* @exceptsafe Provides strong exception guarantee.
*/
explicit SpherePoint(double const lonLatRad[2]);
SpherePoint(double longitude, double latitude, AngleUnit units);

/**
* Construct a SpherePoint from a vector representing a direction.
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/geom/spherePoint/spherePoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ PYBIND11_PLUGIN(spherePoint) {

/* Constructors */
cls.def(py::init<Angle const &, Angle const &>(), "longitude"_a, "latitude"_a);
cls.def(py::init<double, double, AngleUnit>(), "longitude"_a, "latitude"_a, "units"_a);
cls.def(py::init<Point3D const &>(), "vector"_a);
// do not wrap SpherePoint(double const lonLatRad[2]) because it is not as safe as the other constructors
cls.def(py::init<SpherePoint const &>(), "other"_a);

/* Operators */
Expand Down
3 changes: 2 additions & 1 deletion src/geom/SpherePoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Angle haversine(Angle const& deltaLon, Angle const& deltaLat, double cosLat1, do
}
} // end namespace

SpherePoint::SpherePoint(double const lonLatRad[2]) : _longitude(lonLatRad[0]), _latitude(lonLatRad[1]) {}
SpherePoint::SpherePoint(double longitude, double latitude, AngleUnit units)
: _longitude(longitude * units), _latitude(latitude * units) {}

SpherePoint::SpherePoint(Angle const& longitude, Angle const& latitude)
: _longitude(longitude.wrap().asRadians()), _latitude(latitude.asRadians()) {
Expand Down
11 changes: 0 additions & 11 deletions tests/test_spherePoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@ BOOST_AUTO_TEST_CASE(getItemError) {
BOOST_CHECK_THROW(point[-1], pex::exceptions::OutOfRangeError);
}

/*
* Test the SpherePoint(double const lonLatRad[2]) constructor
*/
BOOST_AUTO_TEST_CASE(SpherePointArrayConstructor, *boost::unit_test::tolerance(1e-14)) {
double lonLatRad[2] = {1.23, -0.34};
SpherePoint point(lonLatRad);

BOOST_TEST(point[0].asRadians() == lonLatRad[0]);
BOOST_TEST(point[1].asRadians() == lonLatRad[1]);
}

// TODO: add a test for propagation of ostream errors
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_spherePoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ def testCopyConstructor(self):
spcopy = SpherePoint(sp)
self.assertEqual(sp, spcopy)

def testDoubleDoubleUnitsConstructor(self):
sp1 = SpherePoint(42.0, 45.0, degrees)
self.assertEqual(sp1, SpherePoint(42.0 * degrees, 45.0 * degrees))
sp2 = SpherePoint(1.1, -0.6, radians)
self.assertEqual(sp2, SpherePoint(1.1 * radians, -0.6 * radians))
with self.assertRaises(TypeError):
SpherePoint(-42.0, 45.0) # units must be specified

def testInitNArgFail(self):
"""Tests if only 1- or 2-argument initializers are allowed.
"""
Expand Down

0 comments on commit 6058802

Please sign in to comment.