BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
a3a92ab
Branches
Tags
master
libetherpix
config_gen
src
box.cpp
rename "FlexiPix" to "EtherPix"
Stefan Schuermans
commited
a3a92ab
at 2017-05-20 16:55:59
box.cpp
Blame
History
Raw
/* * EtherPix config file generator * * Copyright 2010 Stefan Schuermans <stefan schuermans info> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * * This program 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 Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <stdlib.h> #include "box.h" #include "constants.h" #include "point.h" Box::Box() { } Box::Box(const Point &bl, const Point &tr): mBL(bl), mTR(tr) { fix(); } void Box::fix() { if (mBL.mX > mTR.mX) { double tmp = mBL.mX; mBL.mX = mTR.mX; mTR.mX = tmp; } if (mBL.mY > mTR.mY) { double tmp = mBL.mY; mBL.mY = mTR.mY; mTR.mY = tmp; } } void Box::getCenter(Point ¢er) { center = (mBL + mTR) / 2.0; } void Box::include(const Point &p) { if (p.mX < mBL.mX) mBL.mX = p.mX; if (p.mY < mBL.mY) mBL.mY = p.mY; if (p.mX > mTR.mX) mTR.mX = p.mX; if (p.mY > mTR.mY) mTR.mY = p.mY; } void Box::include(const Box &b) { if (b.mBL.mX < mBL.mX) mBL.mX = b.mBL.mX; if (b.mBL.mY < mBL.mY) mBL.mY = b.mBL.mY; if (b.mTR.mX > mTR.mX) mTR.mX = b.mTR.mX; if (b.mTR.mY > mTR.mY) mTR.mY = b.mTR.mY; } bool Box::isIntersecting(const Box *pBox) const { return getIntersection(pBox, NULL); } bool Box::getIntersection(const Box *pBox, Box *pIntersect) const { Point bl = mBL, tr = mTR; if (pBox->mBL.mX > bl.mX) bl.mX = pBox->mBL.mX; if (pBox->mBL.mY > bl.mY) bl.mY = pBox->mBL.mY; if (pBox->mTR.mX < tr.mX) tr.mX = pBox->mTR.mX; if (pBox->mTR.mY < tr.mY) tr.mY = pBox->mTR.mY; if (tr.mX - bl.mX < -EPSILON || tr.mY - bl.mY < -EPSILON) return false; if (pIntersect) { pIntersect->mBL = bl; pIntersect->mTR = tr; pIntersect->fix(); } return true; }