Sha256: ac423e728ae78d91fdb40feb01c3d216c96949b98601ba47d71b294d7ca6a04e

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

#ifndef __IMPLICIT_CAST_H__
#define __IMPLICIT_CAST_H__

namespace implicit_cast {

  const int degree2Radians = (3.14 / 180.0);
  const int radian2Degrees = (180.0 / 3.14);

  class Radian;

  class Degree
  {
    public:
      explicit Degree(float d) : val_(d) {}
      Degree(const Radian& r);

      float valueDegrees() const { return val_; }
      float valueRadians() const { return val_ * degree2Radians; }

    private:
      float val_;
  };

  class Radian
  {
    public:
      explicit Radian(float r) : val_(r) {} 
      Radian(const Degree& d) : val_(d.valueRadians()) {}

      float valueRadians() const { return val_; }
      float valueDegrees() const { return val_ * radian2Degrees; }

    private:
      float val_;
  };

  // Due to circular dependencies, need to define some
  // methods down here
  Degree::Degree(const Radian& r)
  {
    val_ = r.valueDegrees();
  }

  /**
   * And now some methods that work w/ the above two classes
   */
  bool isAcute(Degree degree) {
    return degree.valueDegrees() < 90;
  }

  bool isObtuse(Radian radian) {
    return radian.valueDegrees() > 90 && radian.valueDegrees() <= 180;
  }

  bool isRight(Degree* degree) {
    return degree->valueDegrees() == 90;
  }
}

#endif

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rbplusplus-1.4.0 test/headers/implicit_cast.h
rbplusplus-1.3.0 test/headers/implicit_cast.h
rbplusplus-1.2.1 test/headers/implicit_cast.h
rbplusplus-1.2.0 test/headers/implicit_cast.h
rbplusplus-1.1.0 test/headers/implicit_cast.h
rbplusplus-1.0.3 test/headers/implicit_cast.h
rbplusplus-1.0.1 test/headers/implicit_cast.h