/* Example programs from the book Scientific and Engineering Programming in C++: An Introduction with Advanced Techniques and Examples, Addison-Wesley, 1994. (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES CORPORATION 1994. ALL RIGHTS RESERVED. See README file for further details. */ #ifndef MetricSpaceCategoryH #define MetricSpaceCategoryH template class MetricSpaceCategory { public: // User Must Define: M dot(const V&) const; M norm() const; M cosAngle(const V& e) const; M angle(const V& e) const; friend M dot(const V& lhs, const V& rhs) { return lhs.dot(rhs); } }; #include template inline M MetricSpaceCategory::norm() const { const V& vr = (const V&)(*this); return sqrt( vr.dot(vr) ); } template inline M MetricSpaceCategory::cosAngle(const V& e) const{ const V& vr = (const V&)(*this); return vr.dot( e / (norm() * e.norm()) ); } template inline M MetricSpaceCategory::angle(const V& e) const { return acos(cosAngle(e)); } #endif