Skip to content

Commit

Permalink
Merge pull request #60 from gaganjyot/master
Browse files Browse the repository at this point in the history
Bounding Box
  • Loading branch information
rvt committed May 26, 2016
2 parents fdb2ea2 + 0f4c9c3 commit 52749f4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
25 changes: 22 additions & 3 deletions lckernel/cad/geometry/geobezier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,31 @@ Bezier::Bezier(const Bezier &bez) :
}

const Area Bezier::boundingBox() const {

/*
* TODO BOUNDING BOX
* GSOC project
* T = A-B/(A - 2B + C)
*/
auto tx_ = (_pointA.x() - _pointB.x())/(_pointA.x() - (_pointB.x()*2.0) + _pointC.x());
auto ty_ = (_pointA.y() - _pointB.y())/(_pointA.y() - (_pointB.y()*2.0) + _pointC.y());
std::vector<double> x_{_pointA.x(), _pointC.x() };
std::vector<double> y_{_pointA.y(), _pointC.y() };

if(tx_ > 0. && tx_ < 1.0) {
auto bez1 = DirectValueAt(tx_);
x_.push_back(bez1.x());
y_.push_back(bez1.y());
}

if(ty_ > 0. && ty_ < 1.0) {
auto bez2 = DirectValueAt(ty_);
x_.push_back(bez2.x());
y_.push_back(bez2.y());
}

std::sort(x_.begin(), x_.end());
std::sort(y_.begin(), y_.end());

return Area();
return Area(geo::Coordinate(x_.front(), y_.front()), geo::Coordinate (x_.back() ,y_.back()));
}

Coordinate Bezier::nearestPointOnPath(const Coordinate& coord) const {
Expand Down
1 change: 1 addition & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ entitytest.h
code.h
testmath.h
testmatrices.h
beziertest.h
)

include_directories("${CMAKE_SOURCE_DIR}/lckernel")
Expand Down
11 changes: 11 additions & 0 deletions unittest/beziertest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "cad/geometry/geobezier.h"

TEST(BEZIER, BOUNDINGBOX) {
auto p1 = lc::geo::Coordinate(180,240);
auto p2 = lc::geo::Coordinate(2,2);
auto p3 = lc::geo::Coordinate(220, 180);

auto bb = lc::geo::Bezier(p1,p2,p3);
auto area = bb.boundingBox();
std::cout << area.minP() << "\t\t" << area.maxP() << "\n";
}
2 changes: 1 addition & 1 deletion unittest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "testgeoarc.h"
#include "testintersect.h"
#include "testmatrices.h"

#include "beziertest.h"
using namespace std;
using namespace lc;
using namespace entity;
Expand Down

0 comments on commit 52749f4

Please sign in to comment.