2 // ********************************************************************
 
    3 // * This Software is part of the AIDA Unified Solids Library package *
 
    4 // * See: https://aidasoft.web.cern.ch/USolids                        *
 
    5 // ********************************************************************
 
    9 // --------------------------------------------------------------------
 
   13 // Implementation of inline methods of UVector2
 
   15 // 19.10.12 Marek Gayer
 
   16 //          Created from original implementation in CLHEP
 
   17 // --------------------------------------------------------------------
 
   23 inline double Hep2Vector::x() const {
 
   27 inline double Hep2Vector::y() const {
 
   31 inline Hep2Vector::Hep2Vector(double x1, double y1)
 
   34 inline Hep2Vector::Hep2Vector( const Hep3Vector & s)
 
   35 : dx(s.x()), dy(s.y()) {}
 
   37 inline void Hep2Vector::setX(double x1) {
 
   41 inline void Hep2Vector::setY(double y1) {
 
   45 inline void Hep2Vector::set(double x1, double y1) {
 
   50 double & Hep2Vector::operator[] (int i)       { return operator()(i); }
 
   51 double   Hep2Vector::operator[] (int i) const { return operator()(i); }
 
   53 inline Hep2Vector::Hep2Vector(const Hep2Vector & p)
 
   54 : dx(p.x()), dy(p.y()) {}
 
   56 inline Hep2Vector::~Hep2Vector() {}
 
   58 inline Hep2Vector & Hep2Vector::operator = (const Hep2Vector & p) {
 
   64 inline bool Hep2Vector::operator == (const Hep2Vector& v) const {
 
   65   return (v.x()==x() && v.y()==y()) ? true : false;
 
   68 inline bool Hep2Vector::operator != (const Hep2Vector& v) const {
 
   69   return (v.x()!=x() || v.y()!=y()) ? true : false;
 
   72 inline Hep2Vector& Hep2Vector::operator += (const Hep2Vector & p) {
 
   78 inline Hep2Vector& Hep2Vector::operator -= (const Hep2Vector & p) {
 
   84 inline Hep2Vector Hep2Vector::operator - () const {
 
   85   return Hep2Vector(-dx, -dy);
 
   88 inline Hep2Vector& Hep2Vector::operator *= (double a) {
 
   94 inline double Hep2Vector::dot(const Hep2Vector & p) const {
 
   95   return dx*p.x() + dy*p.y();
 
   98 inline double Hep2Vector::mag2() const {
 
  102 inline double Hep2Vector::mag() const {
 
  103   return std::sqrt(mag2());
 
  106 inline double Hep2Vector::r() const {
 
  107   return std::sqrt(mag2());
 
  110 inline Hep2Vector Hep2Vector::unit() const {
 
  113   return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : Hep2Vector(1,0);
 
  116 inline Hep2Vector Hep2Vector::orthogonal() const {
 
  117   double x1 = std::fabs(dx), y1 = std::fabs(dy);
 
  119     return Hep2Vector(dy,-dx);
 
  121     return Hep2Vector(-dy,dx);
 
  125 inline double Hep2Vector::phi() const {
 
  126   return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
 
  129 inline double Hep2Vector::angle(const Hep2Vector & q) const {
 
  130   double ptot2 = mag2()*q.mag2();
 
  131   return ptot2 <= 0.0 ? 0.0 : std::acos(dot(q)/std::sqrt(ptot2));
 
  134 inline void Hep2Vector::setMag(double r1){
 
  136   setX( r1 * std::cos(ph) );
 
  137   setY( r1 * std::sin(ph) );
 
  140 inline void Hep2Vector::setR(double r1){
 
  144 inline void Hep2Vector::setPhi(double phi1){
 
  146   setX( ma * std::cos(phi1) );
 
  147   setY( ma * std::sin(phi1) );
 
  150 inline void Hep2Vector::setPolar(double r1, double phi1){
 
  151   setX( r1 * std::cos(phi1) );
 
  152   setY( r1 * std::sin(phi1) );
 
  155 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b) {
 
  156   return Hep2Vector(a.x() + b.x(), a.y() + b.y());
 
  159 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b) {
 
  160   return Hep2Vector(a.x() - b.x(), a.y() - b.y());
 
  163 inline Hep2Vector operator * (const Hep2Vector & p, double a) {
 
  164   return Hep2Vector(a*p.x(), a*p.y());
 
  167 inline Hep2Vector operator * (double a, const Hep2Vector & p) {
 
  168   return Hep2Vector(a*p.x(), a*p.y());
 
  171 inline double operator * (const Hep2Vector & a, const Hep2Vector & b) {
 
  175 inline double Hep2Vector::getTolerance () {