BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
4ef7955
Branches
Tags
master
libetherpix
config_gen
src
line.cpp
update copyright year
Stefan Schuermans
commited
4ef7955
at 2017-05-20 16:55:59
line.cpp
Blame
History
Raw
/* * EtherPix config file generator * * Copyright 2010-2017 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 "line.h" #include "point.h" Line::Line() { } Line::Line(const Point &start, const Point &end): mStart(start), mEnd(end) { } double Line::length() const { return (mEnd - mStart).abs(); } void Line::getBounds(Box &bounds) const { bounds.mBL = mStart; bounds.mTR = mEnd; bounds.fix(); } bool Line::isIntersecting(const Line *pLine) const { return getIntersection(pLine, NULL); } bool Line::getIntersection(const Line *pLine, Point *pIntersect) const { Point d1 = mEnd - mStart; Point d2 = pLine->mEnd - pLine->mStart; Point ds = mStart - pLine->mStart; double denom = d2.mY * d1.mX - d2.mX * d1.mY; double num1 = d2.mX * ds.mY - d2.mY * ds.mX; double num2 = d1.mX * ds.mY - d1.mY * ds.mX; if (denom >= -EPSILON && denom <= EPSILON) // parallel return false; double prm1 = num1 / denom; double prm2 = num2 / denom; if (prm1 < -EPSILON || prm1 > 1.0 + EPSILON || prm2 < -EPSILON || prm2 > 1.0 + EPSILON) return false; if (pIntersect) *pIntersect = mStart + d1 * prm1; return true; }