Visual Servoing Platform  version 3.4.0
testRect.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Test vpRect.
33  *
34  *****************************************************************************/
35 
36 #include <iostream>
37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpRect.h>
39 
40 int main()
41 {
42  vpRect c(10.1, 15.05, 19.63, 7.84);
43  vpRect a(c.getLeft() - 12.456, c.getTop() - 7.75, c.getWidth() + 12.456, c.getHeight() + 7.75);
44  vpRect b(c.getLeft(), c.getTop(), c.getWidth() + 8.81, c.getHeight() + 14.57);
45 
46  vpRect intersect = a & b;
47 
48  std::cout << "Test intersection." << std::endl;
49  std::cout << "a=" << a << std::endl;
50  std::cout << "b=" << b << std::endl;
51  std::cout << "c=" << c << std::endl;
52  std::cout << "intersect=" << intersect << std::endl;
53 
54  if (intersect != c) {
55  std::cerr << "Problem with the intersection function!" << std::endl;
56  return EXIT_FAILURE;
57  }
58 
59  a &= b;
60  std::cout << "a=" << a << std::endl;
61 
62  if (a != c) {
63  std::cerr << "Problem with the intersection function!" << std::endl;
64  return EXIT_FAILURE;
65  }
66 
67  a = vpRect(11.45, 15.67, 3.5, 7.81);
68  b = vpRect(24.78, 31.46, 7.48, 11.28);
69  intersect = a & b;
70 
71  std::cout << "\nTest no intersection." << std::endl;
72  std::cout << "a=" << a << std::endl;
73  std::cout << "b=" << b << std::endl;
74  std::cout << "intersect=" << intersect << std::endl;
75 
76  if (intersect != vpRect()) {
77  std::cerr << "Problem with the intersection function!" << std::endl;
78  return EXIT_FAILURE;
79  }
80 
81  a &= b;
82  std::cout << "a=" << a << std::endl;
83 
84  if (a != vpRect()) {
85  std::cerr << "Problem with the intersection function!" << std::endl;
86  return EXIT_FAILURE;
87  }
88 
89  std::cout << "vpRect is ok." << std::endl;
90  return EXIT_SUCCESS;
91 }
Defines a rectangle in the plane.
Definition: vpRect.h:79