diff --git a/Documentation/doc/Documentation/Introduction.txt b/Documentation/doc/Documentation/Introduction.txt index 36fb1cbf915..7a5e85a0e48 100644 --- a/Documentation/doc/Documentation/Introduction.txt +++ b/Documentation/doc/Documentation/Introduction.txt @@ -43,7 +43,7 @@ precision floating point numbers for the %Cartesian coordinates of the point. Besides the types we see \em predicates like the orientation test for three points, and \em constructions like the distance and midpoint -computation. A predicate has a discrete set of possible answers, +computation. A predicate has a discrete set of possible results, whereas a construction produces either a number, or another geometric entity. @@ -83,15 +83,40 @@ extract constructions. \cgalExample{Kernel_23/exact.cpp} +Here comes the output and you may still be surprised. + +\verbatim +not collinear +collinear +collinear +\endverbatim + +In the first block the points are still not collinear, +for the simple reason that the coordinates you see as text +get turned into floating point numbers. When they are then +turned into arbitrary precision rationals, they exactly +represent the floating point number, but not the text. + +This is different in the second block, which corresponds +to reading numbers from a file. The arbitrary precision +rationals are then directly constructed from a string +so that they represent exactly the text. + +In the third block you see that constructions as +midpoint constructions are exact, just as the name +of the kernel type suggests. + + In many cases you will have floating point numbers that are "exact", in the sense that they were computed by some application or obtained from a sensor. They are not the string "0.1" or computed on the fly as "1.0/10.0", but a full precision floating point number. If they are input to an algorithm that makes no constructions you can use a kernel that provides exact predicates, but inexact -constructions. An example for that is the convex hull algorithm. -The output is a subset of the input, and all the algorithm -does is to compare coordinates and perform orientation tests. +constructions. An example for that is the convex hull algorithm +which we will see in the next section. +The output is a subset of the input, and the algorithm +only compares coordinates and performs orientation tests. At a first glance the kernel doing exact predicates and constructions seems to be the perfect choice, but performance requirements diff --git a/Kernel_23/examples/Kernel_23/exact.cpp b/Kernel_23/examples/Kernel_23/exact.cpp index 0de6f546b3c..5011baff520 100644 --- a/Kernel_23/examples/Kernel_23/exact.cpp +++ b/Kernel_23/examples/Kernel_23/exact.cpp @@ -1,18 +1,27 @@ #include #include +#include typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; - - typedef Kernel::Point_2 Point_2; int main() { + Point_2 p(0, 0.3), q, r(2, 0.9); { - Point_2 p(0, 0.3), q(1, 0.6), r(2, 0.9); - Point_2 m = CGAL::midpoint(p,r); + q = Point_2(1, 0.6); std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not collinear\n"); - std::cout << (CGAL::collinear(p,m,r) ? "collinear\n" : "not collinear\n"); + } + + { + std::istringstream input("0 0.3 1 0.6 2 0.9"); + input >> p >> q >> r; + std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not collinear\n"); + } + + { + q = CGAL::midpoint(p,r); + std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not collinear\n"); } return 0;