forked from fanxu/ffld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.cpp
151 lines (122 loc) · 2.85 KB
/
Rectangle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//--------------------------------------------------------------------------------------------------
// Implementation of the paper "Exact Acceleration of Linear Object Detectors", 12th European
// Conference on Computer Vision, 2012.
//
// Copyright (c) 2012 Idiap Research Institute, <http://www.idiap.ch/>
// Written by Charles Dubout <[email protected]>
//
// This file is part of FFLD (the Fast Fourier Linear Detector)
//
// FFLD is free software: you can redistribute it and/or modify it under the terms of the GNU
// General Public License version 3 as published by the Free Software Foundation.
//
// FFLD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with FFLD. If not, see
// <http://www.gnu.org/licenses/>.
//--------------------------------------------------------------------------------------------------
#include "Rectangle.h"
#include <algorithm>
#include <iostream>
using namespace FFLD;
using namespace std;
Rectangle::Rectangle() : x_(0), y_(0), width_(0), height_(0)
{
}
Rectangle::Rectangle(int width, int height) : x_(0), y_(0), width_(width), height_(height)
{
}
Rectangle::Rectangle(int x, int y, int width, int height) : x_(x), y_(y), width_(width),
height_(height)
{
}
int Rectangle::x() const
{
return x_;
}
void Rectangle::setX(int x)
{
x_ = x;
}
int Rectangle::y() const
{
return y_;
}
void Rectangle::setY(int y)
{
y_ = y;
}
int Rectangle::width() const
{
return width_;
}
void Rectangle::setWidth(int width)
{
width_ = width;
}
int Rectangle::height() const
{
return height_;
}
void Rectangle::setHeight(int height)
{
height_ = height;
}
int Rectangle::left() const
{
return x();
}
void Rectangle::setLeft(int left)
{
setWidth(right() - left + 1);
setX(left);
}
int Rectangle::top() const
{
return y();
}
void Rectangle::setTop(int top)
{
setHeight(bottom() - top + 1);
setY(top);
}
int Rectangle::right() const
{
return x() + width() - 1;
}
void Rectangle::setRight(int right)
{
setWidth(right - left() + 1);
}
int Rectangle::bottom() const
{
return y() + height() - 1;
}
void Rectangle::setBottom(int bottom)
{
setHeight(bottom - top() + 1);
}
bool Rectangle::empty() const
{
return (width() <= 0) || (height() <= 0);
}
int Rectangle::area() const
{
return max(width(), 0) * max(height(), 0);
}
ostream & FFLD::operator<<(ostream & os, const Rectangle & rect)
{
return os << rect.x() << ' ' << rect.y() << ' ' << rect.width() << ' ' << rect.height();
}
istream & FFLD::operator>>(istream & is, Rectangle & rect)
{
int x, y, width, height;
is >> x >> y >> width >> height;
rect.setX(x);
rect.setY(y);
rect.setWidth(width);
rect.setHeight(height);
return is;
}