2 offset.cc -- implement Offset
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
21 s
= String("(") + to_str (coordinate_a_
[X_AXIS
]) + ", "
22 + to_str (coordinate_a_
[Y_AXIS
]) + ")";
31 return (fabs (r
) > 1e20
);
35 free bsd fix by John Galbraith
39 complex_multiply (Offset z1
, Offset z2
)
42 if(!isinf_b(z2
[Y_AXIS
]))
44 z
[X_AXIS
] = z1
[X_AXIS
] * z2
[X_AXIS
] - z1
[Y_AXIS
]*z2
[Y_AXIS
];
45 z
[Y_AXIS
] = z1
[X_AXIS
] * z2
[Y_AXIS
] + z1
[Y_AXIS
] * z2
[X_AXIS
];
52 complex_conjugate (Offset o
)
54 o
[Y_AXIS
] = - o
[Y_AXIS
];
59 complex_divide (Offset z1
, Offset z2
)
61 z2
= complex_conjugate (z2
);
62 Offset z
= complex_multiply (z1
, z2
);
70 complex_exp (Offset o
)
72 Real s
= sin (o
[Y_AXIS
]);
73 Real c
= cos (o
[Y_AXIS
]);
75 Real r
= exp (o
[X_AXIS
]);
77 return Offset(r
*c
, r
*s
);
83 return atan2 (coordinate_a_
[Y_AXIS
], coordinate_a_
[X_AXIS
]);
87 euclidian vector length / complex modulus
90 Offset::length () const
92 return sqrt (sqr (coordinate_a_
[X_AXIS
]) + sqr (coordinate_a_
[Y_AXIS
]));
95 Offset::mirror (Axis a
)
97 coordinate_a_
[a
] = - coordinate_a_
[a
];