diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2014-04-01 12:02:22 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2014-04-01 12:02:22 +0000 |
| commit | 0f78c1425e814758c0a0d7f0c2578eae88fe3ab6 (patch) | |
| tree | fa65ea104ff6fa39aae2e1a74a63fdf1da74ed35 /src | |
| parent | Some node.cpp/h work moved to path_manipulator. (diff) | |
| download | inkscape-0f78c1425e814758c0a0d7f0c2578eae88fe3ab6.tar.gz inkscape-0f78c1425e814758c0a0d7f0c2578eae88fe3ab6.zip | |
A refactor for fixing some issues. Pending how to handle static functions
VinÃcius for handle tips in his static functions i know two ways:
A: A bool property in node class of node.h to handle if curve is bspline
B: Call another non static function from the static tips one -not tested-
(bzr r11950.1.323)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/tool/node.cpp | 61 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 22 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.h | 4 |
3 files changed, 45 insertions, 42 deletions
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 1eaf0afa7..7ba69b039 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -170,8 +170,8 @@ void Handle::move(Geom::Point const &new_pos) //move the handler and its oposite the same proportion if(_pm().isBSpline()){ - setPosition(_pm().BSplineHandleReposition(this)); - this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),true)); + setPosition(_pm().BSplineHandleReposition(this,this)); + this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } return; } @@ -187,8 +187,8 @@ void Handle::move(Geom::Point const &new_pos) //move the handler and its oposite the same proportion if(_pm().isBSpline()){ - setPosition(_pm().BSplineHandleReposition(this)); - this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),true)); + setPosition(_pm().BSplineHandleReposition(this,this)); + this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } return; @@ -213,8 +213,8 @@ void Handle::move(Geom::Point const &new_pos) // moves the handler and its oposite the same proportion if(_pm().isBSpline()){ - setPosition(_pm().BSplineHandleReposition(this)); - this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),true)); + setPosition(_pm().BSplineHandleReposition(this,this)); + this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } } @@ -365,7 +365,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) if(_pm().isBSpline()){ setPosition(new_pos); int steps = _pm().BSplineGetSteps(); - new_pos=_pm().BSplineHandleReposition(this,ceilf(_pm().BSplineHandlePosition(this)*steps)/steps); + new_pos=_pm().BSplineHandleReposition(this,ceilf(_pm().BSplineHandlePosition(this,this)*steps)/steps); } } @@ -625,13 +625,15 @@ void Node::move(Geom::Point const &new_pos) Node *n = this; Node * nextNode = n->nodeToward(n->front()); Node * prevNode = n->nodeToward(n->back()); - if(_pm().isBSpline()){ - nodeWeight = _pm().BSplineHandlePosition(n->front()); - if(nextNode){ - nextNodeWeight = _pm().BSplineHandlePosition(nextNode->front()); + nodeWeight = _pm().BSplineHandlePosition(n->front()); + if(prevNode){ + if(prevNode->isEndNode()){ + prevNodeWeight = _pm().BSplineHandlePosition(prevNode->front(),prevNode->front()); } - if(prevNode){ - prevNodeWeight = _pm().BSplineHandlePosition(prevNode->front()); + } + if(nextNode){ + if(nextNode->isEndNode()){ + nextNodeWeight = _pm().BSplineHandlePosition(nextNode->back(),nextNode->back()); } } @@ -649,17 +651,17 @@ void Node::move(Geom::Point const &new_pos) _front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight)); _back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight)); if(prevNode){ - if(prevNode->front()->isDegenerate()){ + if(prevNode->isEndNode()){ prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevNodeWeight)); }else{ - prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),true)); + prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevNode->back())); } } if(nextNode){ - if(nextNode->back()->isDegenerate()){ + if(nextNode->isEndNode()){ nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),nextNodeWeight)); }else{ - nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),true)); + nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),nextNode->back())); } } } @@ -674,17 +676,18 @@ void Node::transform(Geom::Affine const &m) double nodeWeight = 0.0000; double nextNodeWeight = 0.0000; double prevNodeWeight = 0.0000; - Node *n = this; Node * nextNode = n->nodeToward(n->front()); Node * prevNode = n->nodeToward(n->back()); - if(_pm().isBSpline()){ - nodeWeight = _pm().BSplineHandlePosition(n->front()); - if(nextNode){ - nextNodeWeight = _pm().BSplineHandlePosition(nextNode->front()); + nodeWeight = _pm().BSplineHandlePosition(n->front()); + if(prevNode){ + if(prevNode->isEndNode()){ + prevNodeWeight = _pm().BSplineHandlePosition(prevNode->front(),prevNode->front()); } - if(prevNode){ - prevNodeWeight = _pm().BSplineHandlePosition(prevNode->front()); + } + if(nextNode){ + if(nextNode->isEndNode()){ + nextNodeWeight = _pm().BSplineHandlePosition(nextNode->back(),nextNode->back()); } } @@ -701,17 +704,17 @@ void Node::transform(Geom::Affine const &m) _front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight)); _back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight)); if(prevNode){ - if(prevNode->front()->isDegenerate()){ + if(prevNode->isEndNode()){ prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevNodeWeight)); }else{ - prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),true)); + prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevNode->back())); } } if(nextNode){ - if(nextNode->back()->isDegenerate()){ + if(nextNode->isEndNode()){ nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),nextNodeWeight)); }else{ - nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),true)); + nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),nextNode->front())); } } } @@ -906,7 +909,7 @@ void Node::setType(NodeType type, bool update_handles) or we give them the default power in curve mode */ if(_pm().isBSpline()){ double weight = 0.0000; - if(_pm().BSplineHandlePosition(this->front()) != 0.0000){ + if(_pm().BSplineHandlePosition(this->front()) != 0.0000 ){ weight = 0.3334; } _front.setPosition(_pm().BSplineHandleReposition(this->front(),weight)); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 905df61f4..487c31b10 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -667,10 +667,10 @@ unsigned PathManipulator::_deleteStretch(NodeList::iterator start, NodeList::ite // if we are removing, we readjust the handlers if(isBSpline()){ if(start.prev()){ - start.prev()->front()->setPosition(BSplineHandleReposition(start.prev()->front(),true)); + start.prev()->front()->setPosition(BSplineHandleReposition(start.prev()->front(),start.prev()->back())); } if(end){ - end->back()->setPosition(BSplineHandleReposition(end->back(),true)); + end->back()->setPosition(BSplineHandleReposition(end->back(),end->front())); } } @@ -1207,31 +1207,31 @@ bool PathManipulator::isBSpline(bool recalculate){ } // returns the corresponding strength to the position of the handlers -double PathManipulator::BSplineHandlePosition(Handle *h, bool other){ +double PathManipulator::BSplineHandlePosition(Handle *h, Handle *h2){ using Geom::X; using Geom::Y; + if(h2){ + h = h2; + } double pos = 0.0000; Node *n = h->parent(); Node * nextNode = NULL; - if(other){ - h = h->other(); - } nextNode = n->nodeToward(h); - if(nextNode && !Geom::are_near(n->position(), h->position())){ + if(nextNode){ SPCurve *lineInsideNodes = new SPCurve(); lineInsideNodes->moveto(n->position()); lineInsideNodes->lineto(nextNode->position()); pos = Geom::nearest_point(h->position(),*lineInsideNodes->first_segment()); } - if ((pos == 0.0000 || pos == 1.0000) && other == false){ - return BSplineHandlePosition(h, true); + if (pos == 0.0000 && !h2){ + return BSplineHandlePosition(h, h->other()); } return pos; } // give the location for the handler in the corresponding position -Geom::Point PathManipulator::BSplineHandleReposition(Handle *h, bool other){ - double pos = this->BSplineHandlePosition(h, other); +Geom::Point PathManipulator::BSplineHandleReposition(Handle *h, Handle *h2){ + double pos = this->BSplineHandlePosition(h, h2); return BSplineHandleReposition(h,pos); } diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index cba029b68..a85664ddf 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -108,8 +108,8 @@ private: void _createControlPointsFromGeometry(); bool isBSpline(bool recalculate = false); - double BSplineHandlePosition(Handle *h, bool other = false); - Geom::Point BSplineHandleReposition(Handle *h, bool other = false); + double BSplineHandlePosition(Handle *h, Handle *h2 = NULL); + Geom::Point BSplineHandleReposition(Handle *h, Handle *h2 = NULL); Geom::Point BSplineHandleReposition(Handle *h, double pos); void _createGeometryFromControlPoints(bool alert_LPE = false); unsigned _deleteStretch(NodeList::iterator first, NodeList::iterator last, bool keep_shape); |
