DGtal  1.5.beta
testHalfPlane.cpp
Go to the documentation of this file.
1 
34 #include <cstdio>
35 #include <cmath>
36 #include <fstream>
37 #include <vector>
38 #include <iostream>
39 #include <iterator>
40 #include "DGtal/base/Common.h"
41 #include "DGtal/base/Exceptions.h"
42 #include "DGtal/kernel/SpaceND.h"
43 #include "DGtal/kernel/domains/DomainPredicate.h"
44 #include "DGtal/kernel/domains/HyperRectDomain.h"
45 #include "DGtal/io/boards/Board2D.h"
46 #include "DGtal/shapes/fromPoints/StraightLineFrom2Points.h"
47 #include "DGtal/shapes/fromPoints/Point2ShapePredicate.h"
48 
49 #include "DGtalCatch.h"
50 
51 
52 using namespace DGtal;
53 using namespace DGtal::functors;
54 using namespace LibBoard;
55 
56 TEST_CASE( "HalfplaneUnit tests" )
57 {
58  typedef int Coordinate;
60  typedef StraightLineFrom2Points<Point> StraightLine;
61 
62  Point p(0,0);
63  Point q(5,2);
64  Point r1(2,0);
65  Point r2(0,2);
66  Point r3(10,4);
67  StraightLine line(p,q);
68 
69  //halfplane upward oriented and closed
71  typedef Point2ShapePredicate<StraightLine,true,true> UpClosedHalfPlane;
73 
74  //halfplane upward oriented and open
75  typedef Point2ShapePredicate<StraightLine,true,false> UpOpenHalfPlane;
76  //halfplane downward oriented and closed
77  typedef Point2ShapePredicate<StraightLine,false,true> DownClosedHalfPlane;
78 
79  //Location
80  trace.beginBlock("Creation of a halfplane and test some points");
81  std::string res;
82  trace.info() << "created line:" << std::endl;
83  trace.info() << line << std::endl;
84 
86  //line is an instance of StraightLine
87  UpClosedHalfPlane hp(line);
88  trace.info() << hp << std::endl;
89  trace.info() << "Does " << r1 << " belongs to hp (no)?" << std::endl;
90  REQUIRE( !hp(r1) );
92  REQUIRE(hp(r2));
93  REQUIRE(hp(r3));
94 
95 
96  UpOpenHalfPlane hp2(line);
97  REQUIRE(! hp2(r1));
98  REQUIRE(hp2(r2));
99  REQUIRE( ! hp2(r3) );
100 
101  DownClosedHalfPlane hp3(line);
102  REQUIRE(hp3(r1));
103  REQUIRE(!hp3(r2));
104  REQUIRE(hp3(r3));
105 }
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Aim: Represents a straight line uniquely defined by two 2D points and that is able to return for any ...
void beginBlock(const std::string &keyword="")
std::ostream & info()
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Struct representing a 2D point.
Definition: Point.h:27
MyPointD Point
Definition: testClone2.cpp:383
TEST_CASE("HalfplaneUnit tests")
REQUIRE(domain.isInside(aPoint))