// ========================================================================== // $Id: test_point.cpp,v 1.2 2017/09/23 00:53:23 jlang Exp $ // CSI2372 example Code for lecture 4 // ========================================================================== // (C)opyright: // // Jochen Lang // SITE, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.site.uottawa.ca // // Creator: jlang (Jochen Lang) // Email: jlang@site.uottawa.ca // ========================================================================== // $Log: test_point.cpp,v $ // Revision 1.2 2017/09/23 00:53:23 jlang // Introduced references and const again for this version // // Revision 1.1 2011/09/27 17:22:20 jlang // Added bounding shape example // // Revision 1.1 2010/09/29 14:28:59 jlang // Separate files for line_segment and point2d. Added test_point and make label test // // // ========================================================================== #include #include "point2d.h" using std::cout; using std::endl; int main( ) { // Define a Point2d Point2D pt1{0.0,1.0}; // Make a copy Point2D pt2{pt1}; // Use initializer Point2D pt3 = 1.0; // Default point Point2D pt4{}; // A point on the heap -- avoid auto ptHeap = new Point2D{ 1.0, 1.0 }; // Test the functions if (pt1.dot( pt3 ) < 1e-9) { cout << "Dot product ok." << endl << "(Vector to Point pt1 and to pt3 are orthogonal.)" << endl; } else { cout << "Dot product failed." << endl; } Point2D res = pt1.add(pt3).subtract( *ptHeap ); if ( res.dot(res) < 1e-9 ) { cout << "Addition and subtraction ok." << endl; } else { cout << "Addition and/or subtraction failed." << endl; } delete ptHeap; return 0; }