| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include "rs_constructionline.h" |
| |
|
| | #include "lc_quadratic.h" |
| | #include "rs_debug.h" |
| | #include "rs_math.h" |
| | #include "rs_painter.h" |
| |
|
| |
|
| | RS_ConstructionLineData::RS_ConstructionLineData(const RS_Vector& point1, |
| | const RS_Vector& point2): |
| | point1(point1) |
| | ,point2(point2) |
| | { |
| | } |
| |
|
| | std::ostream& operator << (std::ostream& os, |
| | const RS_ConstructionLineData& ld) |
| | { |
| | os << "(" << ld.point1 << |
| | "/" << ld.point2 << |
| | ")"; |
| | return os; |
| | } |
| |
|
| | |
| | |
| | |
| | RS_ConstructionLine::RS_ConstructionLine(RS_EntityContainer* parent, |
| | const RS_ConstructionLineData& d) |
| | :RS_AtomicEntity(parent), data(d) { |
| |
|
| | calculateBorders(); |
| | } |
| |
|
| | RS_ConstructionLine::RS_ConstructionLine(const RS_Vector& point1, const RS_Vector& point2) |
| | :RS_AtomicEntity(nullptr), data(point1, point2){ |
| | } |
| |
|
| | RS_Entity* RS_ConstructionLine::clone() const { |
| | RS_ConstructionLine* c = new RS_ConstructionLine(*this); |
| | return c; |
| | } |
| |
|
| | void RS_ConstructionLine::calculateBorders() { |
| | minV = RS_Vector::minimum(data.point1, data.point2); |
| | maxV = RS_Vector::maximum(data.point1, data.point2); |
| | } |
| |
|
| | RS_Vector RS_ConstructionLine::getNearestEndpoint(const RS_Vector& coord, |
| | double* dist) const{ |
| |
|
| | const double dist1 = (data.point1-coord).squared(); |
| | const double dist2 = (data.point2-coord).squared(); |
| |
|
| | if (dist2<dist1) { |
| | if (dist) { |
| | *dist = sqrt(dist2); |
| | } |
| | return data.point2; |
| | } else { |
| | if (dist) { |
| | *dist = sqrt(dist1); |
| | } |
| | return data.point1; |
| | } |
| | } |
| |
|
| | RS_Vector RS_ConstructionLine::getNearestPointOnEntity(const RS_Vector& coord, |
| | bool , double* , RS_Entity** entity) const{ |
| |
|
| | if (entity) { |
| | *entity = const_cast<RS_ConstructionLine*>(this); |
| | } |
| |
|
| | RS_Vector ae = data.point2-data.point1; |
| | RS_Vector ea = data.point1-data.point2; |
| | RS_Vector ap = coord-data.point1; |
| | |
| |
|
| | if (ae.magnitude()<1.0e-6 || ea.magnitude()<1.0e-6) { |
| | return RS_Vector(false); |
| | } |
| |
|
| | |
| | RS_Vector ba = ae * RS_Vector::dotP(ae, ap) |
| | / (ae.magnitude()*ae.magnitude()); |
| | |
| | |
| |
|
| | return data.point1+ba; |
| | } |
| |
|
| | RS_Vector RS_ConstructionLine::getNearestCenter(const RS_Vector& , |
| | double* dist) const{ |
| |
|
| | if (dist) { |
| | *dist = RS_MAXDOUBLE; |
| | } |
| |
|
| | return RS_Vector(false); |
| | } |
| |
|
| | |
| | RS_ConstructionLineData const& RS_ConstructionLine::getData() const { |
| | return data; |
| | } |
| |
|
| | |
| | RS_Vector const& RS_ConstructionLine::getPoint1() const { |
| | return data.point1; |
| | } |
| | |
| | RS_Vector const& RS_ConstructionLine::getPoint2() const { |
| | return data.point2; |
| | } |
| |
|
| | |
| | RS_Vector RS_ConstructionLine::getStartpoint() const |
| | { |
| | return data.point1; |
| | } |
| |
|
| | |
| | RS_Vector RS_ConstructionLine::getEndpoint() const |
| | { |
| | return data.point2; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | double RS_ConstructionLine::getDirection1(void) const |
| | { |
| | return RS_Math::correctAngle( data.point1.angleTo( data.point2)); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | double RS_ConstructionLine::getDirection2(void) const |
| | { |
| | return RS_Math::correctAngle( data.point2.angleTo( data.point1)); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | LC_Quadratic RS_ConstructionLine::getQuadratic() const |
| | { |
| | std::vector<double> ce(3,0.); |
| | auto dvp=data.point2 - data.point1; |
| | RS_Vector normal(-dvp.y,dvp.x); |
| | ce[0]=normal.x; |
| | ce[1]=normal.y; |
| | ce[2]= -normal.dotP(data.point2); |
| | return LC_Quadratic(ce); |
| | } |
| |
|
| | RS_Vector RS_ConstructionLine::getMiddlePoint() const{ |
| | return RS_Vector(false); |
| | } |
| | RS_Vector RS_ConstructionLine::getNearestMiddle(const RS_Vector& , |
| | double* dist, const int )const { |
| | if (dist) { |
| | *dist = RS_MAXDOUBLE; |
| | } |
| | return RS_Vector(false); |
| | } |
| |
|
| | RS_Vector RS_ConstructionLine::getNearestDist(double , |
| | const RS_Vector& , |
| | double* dist) const{ |
| | if (dist) { |
| | *dist = RS_MAXDOUBLE; |
| | } |
| | return RS_Vector(false); |
| | } |
| |
|
| |
|
| | double RS_ConstructionLine::getDistanceToPoint(const RS_Vector& coord, |
| | RS_Entity** entity, |
| | RS2::ResolveLevel , double ) const { |
| |
|
| | RS_DEBUG->print("RS_ConstructionLine::getDistanceToPoint"); |
| |
|
| | if (entity) { |
| | *entity = const_cast<RS_ConstructionLine*>(this); |
| | } |
| | |
| | RS_Vector se = data.point2-data.point1; |
| | double d(se.magnitude()); |
| | if(d<RS_TOLERANCE) { |
| | |
| | return RS_MAXDOUBLE; |
| | } |
| | se.set( se.x/d,-se.y/d); |
| | RS_Vector vpc= coord - data.point1; |
| | vpc.rotate(se); |
| | return ( fabs(vpc.y) ); |
| | } |
| |
|
| | void RS_ConstructionLine::move(const RS_Vector& offset) { |
| | data.point1.move(offset); |
| | data.point2.move(offset); |
| | |
| | } |
| |
|
| | void RS_ConstructionLine::rotate(const RS_Vector& center, double angle) { |
| | RS_Vector angleVector(angle); |
| | data.point1.rotate(center, angleVector); |
| | data.point2.rotate(center, angleVector); |
| | |
| | } |
| |
|
| | void RS_ConstructionLine::rotate(const RS_Vector& center, const RS_Vector& angleVector) { |
| | data.point1.rotate(center, angleVector); |
| | data.point2.rotate(center, angleVector); |
| | |
| | } |
| |
|
| | void RS_ConstructionLine::scale(const RS_Vector& center, const RS_Vector& factor) { |
| | data.point1.scale(center, factor); |
| | data.point2.scale(center, factor); |
| | |
| | } |
| |
|
| | void RS_ConstructionLine::mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2) { |
| | data.point1.mirror(axisPoint1, axisPoint2); |
| | data.point2.mirror(axisPoint1, axisPoint2); |
| | } |
| |
|
| | RS_Entity& RS_ConstructionLine::shear(double k){ |
| | data.point1.shear(k); |
| | data.point2.shear(k); |
| | return *this; |
| | } |
| |
|
| | void RS_ConstructionLine::draw(RS_Painter *painter) { |
| | painter->drawInfiniteWCS(data.point1, data.point2); |
| | } |
| |
|
| | |
| | |
| | |
| | std::ostream& operator << (std::ostream& os, const RS_ConstructionLine& l) { |
| | os << " ConstructionLine: " << l.getData() << "\n"; |
| | return os; |
| | } |
| |
|