DGtal
1.2.0
src
Board
Rect.cpp
1
/* -*- mode: c++ -*- */
9
/*
10
* \@copyright This File is part of the Board library which is
11
* licensed under the terms of the GNU Lesser General Public Licence.
12
* See the LICENCE file for further details.
13
*/
14
15
#include "Board/Rect.h"
16
17
namespace
LibBoard
{
18
19
Rect
20
operator||
(
const
Rect
& rectA,
const
Rect
& rectB )
21
{
22
Rect
rect;
23
rect.
top
= ( rectA.
top
> rectB.
top
) ? rectA.
top
: rectB.
top
;
24
rect.
left
= (rectA.
left
< rectB.
left
) ? rectA.
left
: rectB.
left
;
25
if
( rectA.
left
+ rectA.
width
> rectB.
left
+ rectB.
width
)
26
rect.
width
= rectA.
left
+ rectA.
width
- rect.
left
;
27
else
28
rect.
width
= rectB.
left
+ rectB.
width
- rect.
left
;
29
if
( rectA.
top
- rectA.
height
< rectB.
top
- rectB.
height
)
30
rect.
height
= rect.
top
- ( rectA.
top
- rectA.
height
);
31
else
32
rect.
height
= rect.
top
- ( rectB.
top
- rectB.
height
);
33
return
rect;
34
}
35
36
Rect
37
operator&&
(
const
Rect
& rectA,
const
Rect
& rectB )
38
{
39
Rect
rect;
40
rect.
top
= ( rectA.
top
< rectB.
top
) ? rectA.
top
: rectB.
top
;
41
rect.
left
= (rectA.
left
> rectB.
left
) ? rectA.
left
: rectB.
left
;
42
if
( rectA.
left
+ rectA.
width
< rectB.
left
+ rectB.
width
)
43
rect.
width
= rectA.
left
+ rectA.
width
- rect.
left
;
44
else
45
rect.
width
= rectB.
left
+ rectB.
width
- rect.
left
;
46
if
( rectA.
top
- rectA.
height
> rectB.
top
- rectB.
height
)
47
rect.
height
= rect.
top
- ( rectA.
top
- rectA.
height
);
48
else
49
rect.
height
= rect.
top
- ( rectB.
top
- rectB.
height
);
50
if
( rect.
height
< 0 ) rect.
height
= 0;
51
if
( rect.
width
< 0 ) rect.
width
= 0;
52
return
rect;
53
}
54
55
}
// namespace LibBoard
56
57
std::ostream &
58
operator<<( std::ostream & out,
const
LibBoard::Rect
& rect )
59
{
60
out <<
"Rect("
61
<< rect.
left
<<
","
<< rect.
top
62
<<
"+"
<< rect.
width
<<
"x"
<< rect.
height
<<
")"
;
63
return
out;
64
}
LibBoard
Definition:
Board.cpp:87
LibBoard::operator&&
Rect operator&&(const Rect &rectA, const Rect &rectB)
Definition:
Rect.cpp:37
LibBoard::operator||
Rect operator||(const Rect &rectA, const Rect &rectB)
Definition:
Rect.cpp:20
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition:
Rect.h:26
LibBoard::Rect::height
double height
Definition:
Rect.h:31
LibBoard::Rect::width
double width
Definition:
Rect.h:30
LibBoard::Rect::left
double left
Definition:
Rect.h:28
LibBoard::Rect::top
double top
Definition:
Rect.h:29
Generated on Tue Jun 1 2021 17:05:37 for DGtal by
1.9.1