Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Converting between Rational and Floating Point Kernel

Converting between Rational and Floating Point Kernel

Floating point objects can be converted to rational objects, and vice versa. We illustrate conversion for points.

If p is a point or rat_point then point p.to_point(); returns a point.

If p is a point the call is equivalent to the call of the copy constructor, and if p is a rat_point, the Cartesian coordinates of the point returned are the floating point approximations of the Cartesian coordinates of p.

Remark 1: The conversion from rational objects to floating point objects needs to be used whenever an object is to be displayed in a window. If W is a window and p is a point or a rat_point, then W << p.to_point(); draws p in W.


#include <LEDA/graphics/window.h>
#include <LEDA/geo/rat_point.h>

using namespace leda;

int main()
  rat_point rp(50,50);

  window W(100,100);;
  W << rp.to_point();
  //W << rp; does not work

  return 0;

Remark 2: We could write W << p; if the class rat_point provided a conversion operator to point. We opted for the less elegant code, since the use of conversion operators can lead to unexpected side effects.

See also:

Data Types for 2D Geometry



Advanced Data types for 2-D geometry

Data Types for 3-D Geometry

Geometry Algorithms


Please send any suggestions, comments or questions to
© Copyright 2001-2003, Algorithmic Solutions Software GmbH