adding Geometry classes: Point, Size, and Rect
This commit is contained in:
parent
e17c54e3f8
commit
24f9448c2e
2 changed files with 201 additions and 0 deletions
99
src/Geometry.cc
Normal file
99
src/Geometry.cc
Normal file
|
@ -0,0 +1,99 @@
|
|||
// Geometry.cc for Openbox
|
||||
// Copyright (c) 2002 - 2002 ben Jansens (ben@orodu.net)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include "Geometry.h"
|
||||
|
||||
Point::Point() : m_x(0), m_y(0) {
|
||||
}
|
||||
|
||||
Point::Point(const Point &point) : m_x(point.m_x), m_y(point.m_y) {
|
||||
}
|
||||
|
||||
Point::Point(const int x, const int y) : m_x(x), m_y(y) {
|
||||
}
|
||||
|
||||
inline void Point::setX(const int x) {
|
||||
m_x = x;
|
||||
}
|
||||
|
||||
inline void Point::setY(const int y) {
|
||||
m_y = y;
|
||||
}
|
||||
|
||||
Size::Size() : m_w(0), m_h(0) {
|
||||
}
|
||||
|
||||
Size::Size(const Size &size) : m_w(size.m_w), m_h(size.m_h) {
|
||||
}
|
||||
|
||||
Size::Size(const int w, const int h) : m_w(w), m_h(h) {
|
||||
}
|
||||
|
||||
inline void Size::setW(const int w) {
|
||||
m_w = w;
|
||||
}
|
||||
|
||||
inline void Size::setH(const int h) {
|
||||
m_h = h;
|
||||
}
|
||||
|
||||
Rect::Rect() : m_origin(0, 0), m_size(0, 0) {
|
||||
}
|
||||
|
||||
Rect::Rect(const Point &origin, const Size &size) : m_origin(origin),
|
||||
m_size(size) {
|
||||
}
|
||||
|
||||
Rect::Rect(const int x, const int y, const int w, const int h) : m_origin(x, y),
|
||||
m_size(w, h) {
|
||||
}
|
||||
|
||||
void Rect::setSize(const Size &size) {
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
void Rect::setOrigin(const Point &origin) {
|
||||
m_origin = origin;
|
||||
}
|
||||
|
||||
void Rect::setX(const int x) {
|
||||
m_origin.setX(x);
|
||||
}
|
||||
|
||||
void Rect::setY(const int y) {
|
||||
m_origin.setY(y);
|
||||
}
|
||||
|
||||
void Rect::setW(int w) {
|
||||
m_size.setW(w);
|
||||
}
|
||||
|
||||
void Rect::setH(int h) {
|
||||
m_size.setH(h);
|
||||
}
|
||||
|
||||
bool Rect::Intersect(const Rect &r) const {
|
||||
return
|
||||
(x() < (r.x()+r.w()) ) &&
|
||||
( (x()+w()) > r.x()) &&
|
||||
(y() < (r.y()+r.h()) ) &&
|
||||
( (y()+h()) > r.y());
|
||||
}
|
102
src/Geometry.h
Normal file
102
src/Geometry.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
// Geometry.h for Openbox
|
||||
// Copyright (c) 2002 - 2002 ben Jansens (ben@orodu.net)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#ifndef __geometru_h
|
||||
#define __geometry_h
|
||||
|
||||
class Point{
|
||||
int m_x, m_y;
|
||||
public:
|
||||
Point();
|
||||
Point(const Point &point);
|
||||
Point(const int x, const int y);
|
||||
|
||||
void setX(const int x);
|
||||
inline int x() const {
|
||||
return m_x;
|
||||
}
|
||||
|
||||
void setY(const int y);
|
||||
inline int y() const {
|
||||
return m_y;
|
||||
}
|
||||
};
|
||||
|
||||
class Size{
|
||||
int m_w, m_h;
|
||||
public:
|
||||
Size();
|
||||
Size(const Size &size);
|
||||
Size(const int w, const int h);
|
||||
|
||||
void setW(const int w);
|
||||
inline int w() const {
|
||||
return m_w;
|
||||
}
|
||||
|
||||
void setH(const int h);
|
||||
inline int h() const {
|
||||
return m_h;
|
||||
}
|
||||
};
|
||||
|
||||
class Rect{
|
||||
Point m_origin;
|
||||
Size m_size;
|
||||
public:
|
||||
Rect();
|
||||
Rect(const Point &origin, const Size &size);
|
||||
Rect(const int x, const int y, const int w, const int h);
|
||||
|
||||
void setSize(const Size &size);
|
||||
inline const Size &size() const {
|
||||
return const_cast<const Size &>(m_size);
|
||||
}
|
||||
|
||||
void setOrigin(const Point &origin);
|
||||
inline const Point &origin() const {
|
||||
return const_cast<const Point &>(m_origin);
|
||||
}
|
||||
|
||||
void setX(const int x);
|
||||
inline int x() const {
|
||||
return m_origin.x();
|
||||
}
|
||||
|
||||
void setY(const int y);
|
||||
inline int y() const {
|
||||
return m_origin.y();
|
||||
}
|
||||
|
||||
void setW(const int w);
|
||||
inline int w() const {
|
||||
return m_size.w();
|
||||
}
|
||||
|
||||
void setH(const int h);
|
||||
inline int h() const {
|
||||
return m_size.h();
|
||||
}
|
||||
|
||||
bool Intersect(const Rect &r) const;
|
||||
};
|
||||
|
||||
#endif // __geomtry_h
|
Loading…
Reference in a new issue