byteman
1.3 (Build #225)
Bitstream relocation and manipulation tool
src
Common
Coords.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright 2022 Kristiyan Manev (University of Manchester)
3
*
4
* Licensed under the Apache License, Version 2.0(the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*****************************************************************************/
16
17
#ifndef COORDS_H
18
#define COORDS_H
19
20
#include<algorithm>
// min, max
21
22
struct
Coord2D
23
{
24
int
row
;
25
int
col
;
26
};
27
28
struct
Rect2D
29
{
30
Coord2D
position
;
31
Coord2D
size
;
32
};
33
namespace
rect
{
34
inline
Rect2D
getOverlap
(
Rect2D
r1,
Rect2D
r2){
35
Rect2D
retRect;
36
retRect.
position
.
col
= std::max(r1.
position
.
col
, r2.
position
.
col
);
37
retRect.
size
.
col
= std::min((r1.
position
.
col
+ r1.
size
.
col
), (r2.
position
.
col
+ r2.
size
.
col
)) - retRect.
position
.
col
;
38
if
(0 > retRect.
size
.
col
)
39
retRect.
size
.
col
= 0;
40
41
retRect.
position
.
row
= std::max(r1.
position
.
row
, r2.
position
.
row
);
42
retRect.
size
.
row
= std::min((r1.
position
.
row
+ r1.
size
.
row
), (r2.
position
.
row
+ r2.
size
.
row
)) - retRect.
position
.
row
;
43
if
(0 > retRect.
size
.
row
)
44
retRect.
size
.
row
= 0;
45
46
return
retRect;
47
}
48
inline
bool
empty
(
Rect2D
r){
49
return
(0 >= r.
size
.
row
|| 0 >= r.
size
.
col
);
50
}
51
}
52
53
#endif
//COORDS_H
rect
Definition:
Coords.h:33
rect::empty
bool empty(Rect2D r)
Definition:
Coords.h:48
rect::getOverlap
Rect2D getOverlap(Rect2D r1, Rect2D r2)
Definition:
Coords.h:34
Coord2D
Definition:
Coords.h:23
Coord2D::col
int col
Definition:
Coords.h:25
Coord2D::row
int row
Definition:
Coords.h:24
Rect2D
Definition:
Coords.h:29
Rect2D::size
Coord2D size
Definition:
Coords.h:31
Rect2D::position
Coord2D position
Definition:
Coords.h:30
Generated on Tue Nov 29 2022 12:57:36 for byteman by
1.9.1