]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/offset.hh
* flower/include/std-string.hh: String/std::string compatibility:
[lilypond.git] / flower / include / offset.hh
index a782eb0507d5a85843d4923248c50690c6af25f4..5ca7e0e68c637130c2c9fe7e42b8d90503b97d77 100644 (file)
@@ -1,15 +1,18 @@
 /*
   offset.hh -- part of GNU LilyPond
 
-  (c) 1996--2005 Han-Wen Nienhuys
+  (c) 1996--2006 Han-Wen Nienhuys
 */
 
 #ifndef OFFSET_HH
 #define OFFSET_HH
 
-#include "axes.hh"
+#include "axis.hh"
+#include "std-string.hh"
 #include "string.hh"
+#include "real.hh"
 
+class Offset;
 Offset complex_multiply (Offset, Offset);
 Offset complex_divide (Offset, Offset);
 Offset complex_exp (Offset);
@@ -24,24 +27,24 @@ class Offset
 public:
   Real coordinate_a_[NO_AXES];
 
-  Real &operator[] (Axis i)
+  Real &operator [] (Axis i)
   {
     return coordinate_a_[i];
   }
 
-  Real operator[] (Axis i) const
+  Real operator [] (Axis i) const
   {
     return coordinate_a_[i];
   }
 
-  Offset &operator+= (Offset o)
+  Offset &operator += (Offset o)
   {
     (*this)[X_AXIS] += o[X_AXIS];
     (*this)[Y_AXIS] += o[Y_AXIS];
     return *this;
   }
 
-  Offset operator- () const
+  Offset operator - () const
   {
     Offset o = *this;
 
@@ -50,7 +53,7 @@ public:
     return o;
   }
 
-  Offset &operator-= (Offset o)
+  Offset &operator -= (Offset o)
   {
     (*this)[X_AXIS] -= o[X_AXIS];
     (*this)[Y_AXIS] -= o[Y_AXIS];
@@ -66,7 +69,13 @@ public:
     return *this;
   }
 
-  Offset &operator*= (Real a)
+  Offset &operator /= (Real a)
+  {
+    (*this) *= 1/a;
+    return *this;
+  }
+
+  Offset &operator *= (Real a)
   {
     (*this)[X_AXIS] *= a;
     (*this)[Y_AXIS] *= a;
@@ -76,16 +85,16 @@ public:
 
   Offset (Real ix, Real iy)
   {
-    coordinate_a_[X_AXIS] =ix;
-    coordinate_a_[Y_AXIS] =iy;
+    coordinate_a_[X_AXIS] = ix;
+    coordinate_a_[Y_AXIS] = iy;
   }
 
   Offset ()
   {
-    coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS]= 0.0;
+    coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS] = 0.0;
   }
 
-  String to_string () const;
+  Std_string to_string () const;
 
   Offset &mirror (Axis a)
   {
@@ -95,13 +104,12 @@ public:
 
   Real arg () const;
   Real length () const;
-
-  Offset operator*= (Offset z2)
+  bool is_sane () const;
+  Offset operator *= (Offset z2)
   {
     *this = complex_multiply (*this, z2);
     return *this;
   }
-
 };
 
 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
@@ -109,14 +117,21 @@ IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
 
 inline Offset
-operator* (Real o1, Offset o2)
+operator * (Real o1, Offset o2)
 {
   o2 *= o1;
   return o2;
 }
 
 inline Offset
-operator* (Offset o1, Real o2)
+operator / (Offset o1, Real a)
+{
+  o1 /= a;
+  return o1;
+}
+
+inline Offset
+operator * (Offset o1, Real o2)
 {
   o1 *= o2;
   return o1;