release/4.3a0
Frank Dellaert 2010-01-12 02:09:03 +00:00
parent 1aed18717b
commit 5163684077
3 changed files with 35 additions and 12 deletions

View File

@ -25,8 +25,8 @@ namespace gtsam {
}
/* ************************************************************************* */
double Point2::dist(const Point2& p2) const {
return sqrt(pow(x() - p2.x(), 2.0) + pow(y() - p2.y(), 2.0));
double Point2::norm() const {
return sqrt(x_*x_ + y_*y_);
}
/* ************************************************************************* */

View File

@ -48,8 +48,13 @@ namespace gtsam {
inline Point2 operator - (const Point2& q) const {return Point2(x_-q.x_,y_-q.y_);}
inline Point2 operator / (double q) const {return Point2(x_/q,y_/q);}
/** norm of point */
double norm() const;
/** distance between two points */
double dist(const Point2& p2) const;
inline double dist(const Point2& p2) const {
return (p2 - *this).norm();
}
private:
/** Serialization function */

View File

@ -11,22 +11,40 @@ using namespace std;
using namespace gtsam;
/* ************************************************************************* */
TEST( Point2, expmap) {
Vector d(2);d(0)=1;d(1)=-1;
Point2 a(4,5), b=expmap(a,d),c(5,4);
CHECK(assert_equal(b,c));
TEST( Point2, expmap)
{
Vector d(2);
d(0) = 1;
d(1) = -1;
Point2 a(4, 5), b = expmap(a, d), c(5, 4);
CHECK(assert_equal(b,c));
}
/* ************************************************************************* */
TEST( Point2, add) {
CHECK(assert_equal( Point2(4,5)+Point2(1,1), Point2(5,6) ));
TEST( Point2, add)
{
CHECK(assert_equal( Point2(4,5)+Point2(1,1), Point2(5,6) ));
}
/* ************************************************************************* */
TEST( Point2, subtract) {
CHECK(assert_equal( Point2(4,5)-Point2(1,1), Point2(3,4) ));
TEST( Point2, subtract)
{
CHECK(assert_equal( Point2(4,5)-Point2(1,1), Point2(3,4) ));
}
/* ************************************************************************* */
int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
TEST( Point2, norm)
{
Point2 p0(cos(5), sin(5));
DOUBLES_EQUAL(1,p0.norm(),1e-6);
Point2 p1(4, 5), p2(1, 1);
DOUBLES_EQUAL( 5,p1.dist(p2),1e-6);
DOUBLES_EQUAL( 5,(p2-p1).norm(),1e-6);
}
/* ************************************************************************* */
int main() {
TestResult tr;
return TestRegistry::runAllTests(tr);
}
/* ************************************************************************* */