00001 #include "BoxConstraint.h" 00002 #include "Point.h" 00003 00004 namespace Elve { 00005 using namespace std; 00006 00007 BoxConstraint::BoxConstraint(const QRectF &bounds) : mBounds(bounds) 00008 { 00009 00010 } 00011 00012 void BoxConstraint::setBounds(const QRectF& bounds) { 00013 mBounds = bounds; 00014 } 00015 00016 00017 void BoxConstraint::constrain(Point& point) { 00018 QVector2D pos = point.pos(); 00019 pos.setX(max(mBounds.left(),min(mBounds.right(),(qreal)pos.x()))); 00020 pos.setY(max(mBounds.top(),min(mBounds.bottom(),(qreal)pos.y()))); 00021 point.setPos(pos); 00022 } 00023 00024 }