summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-09-23 21:43:31 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-09-23 21:43:31 +0000
commit86cf2d0a97e0412629102ae51df0a4797f9179db (patch)
treed4ba8704b993eefd6b7410fd2d51d104a166096f /src
parentfix bug -bad power- inserting nodes near cusp nodes in bspline (diff)
downloadinkscape-86cf2d0a97e0412629102ae51df0a4797f9179db.tar.gz
inkscape-86cf2d0a97e0412629102ae51df0a4797f9179db.zip
remove magic numbers from bspline
(bzr r13341.1.219)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/lpe-bspline.cpp42
-rw-r--r--src/ui/tool/node.cpp35
-rw-r--r--src/ui/tool/path-manipulator.cpp16
3 files changed, 53 insertions, 40 deletions
diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp
index 1141e87ef..eb0604273 100644
--- a/src/live_effects/lpe-bspline.cpp
+++ b/src/live_effects/lpe-bspline.cpp
@@ -53,19 +53,23 @@ namespace Inkscape {
namespace LivePathEffect {
const double handleCubicGap = 0.01;
+const double noPower = 0.0;
+const double defaultStartPower = 0.3334;
+const double defaultEndPower = 0.6667;
+
LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
steps(_("Steps whith CTRL:"), _("Change number of steps whith CTRL pressed"), "steps", &wr, this, 2),
ignoreCusp(_("Ignore cusp nodes"), _("Change ignoring cusp nodes"), "ignoreCusp", &wr, this, true),
onlySelected(_("Change only selected nodes"), _("Change only selected nodes"), "onlySelected", &wr, this, false),
- weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, 0.3334)
+ weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, defaultStartPower)
{
registerParameter(&weight);
registerParameter(&steps);
registerParameter(&ignoreCusp);
registerParameter(&onlySelected);
- weight.param_set_range(0.0000, 1);
+ weight.param_set_range(noPower, 1);
weight.param_set_increments(0.1, 0.1);
weight.param_set_digits(4);
@@ -138,12 +142,12 @@ void LPEBSpline::doEffect(SPCurve *curve)
if (cubic) {
SBasisIn = in->first_segment()->toSBasis();
if(are_near((*cubic)[1],(*cubic)[0]) && !are_near((*cubic)[2],(*cubic)[3])) {
- pointAt1 = SBasisIn.valueAt(0.3334);
+ pointAt1 = SBasisIn.valueAt(defaultStartPower);
} else {
pointAt1 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[1], *in->first_segment()));
}
if(are_near((*cubic)[2],(*cubic)[3]) && !are_near((*cubic)[1],(*cubic)[0])) {
- pointAt2 = SBasisIn.valueAt(0.6667);
+ pointAt2 = SBasisIn.valueAt(defaultEndPower);
} else {
pointAt2 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[2], *in->first_segment()));
}
@@ -161,7 +165,7 @@ void LPEBSpline::doEffect(SPCurve *curve)
if (cubic) {
SBasisOut = out->first_segment()->toSBasis();
if(are_near((*cubic)[1],(*cubic)[0]) && !are_near((*cubic)[2],(*cubic)[3])) {
- nextPointAt1 = SBasisIn.valueAt(0.3334);
+ nextPointAt1 = SBasisIn.valueAt(defaultStartPower);
} else {
nextPointAt1 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[1], *out->first_segment()));
}
@@ -294,22 +298,22 @@ Gtk::Widget *LPEBSpline::newWidget()
void LPEBSpline::toDefaultWeight(Gtk::Widget *widgWeight)
{
- weight.param_set_value(0.3334);
- changeWeight(0.3334);
+ weight.param_set_value(defaultStartPower);
+ changeWeight(defaultStartPower);
Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widgWeight);
std::vector< Gtk::Widget* > childList = scalarParameter->get_children();
Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]);
- entryWidg->set_text("0.3334");
+ entryWidg->set_text("defaultStartPower");
}
void LPEBSpline::toMakeCusp(Gtk::Widget *widgWeight)
{
- weight.param_set_value(0.0000);
- changeWeight(0.0000);
+ weight.param_set_value(noPower);
+ changeWeight(noPower);
Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widgWeight);
std::vector< Gtk::Widget* > childList = scalarParameter->get_children();
Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]);
- entryWidg->set_text("0.0000");
+ entryWidg->set_text("noPower");
}
void LPEBSpline::toWeight()
@@ -446,7 +450,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
if (cubic) {
if (!ignoreCusp || !Geom::are_near((*cubic)[1], pointAt0)) {
pointAt1 = SBasisIn.valueAt(weightValue);
- if (weightValue != 0.0000) {
+ if (weightValue != noPower) {
pointAt1 =
Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap);
}
@@ -455,7 +459,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
}
if (!ignoreCusp || !Geom::are_near((*cubic)[2], pointAt3)) {
pointAt2 = SBasisIn.valueAt(1 - weightValue);
- if (weightValue != 0.0000) {
+ if (weightValue != noPower) {
pointAt2 =
Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap);
}
@@ -463,14 +467,14 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
pointAt2 = in->first_segment()->finalPoint();
}
} else {
- if (!ignoreCusp && weightValue != 0.0000) {
+ if (!ignoreCusp && weightValue != noPower) {
pointAt1 = SBasisIn.valueAt(weightValue);
- if (weightValue != 0.0000) {
+ if (weightValue != noPower) {
pointAt1 =
Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap);
}
pointAt2 = SBasisIn.valueAt(1 - weightValue);
- if (weightValue != 0.0000) {
+ if (weightValue != noPower) {
pointAt2 =
Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap);
}
@@ -484,7 +488,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
if (!ignoreCusp || !Geom::are_near((*cubic)[1], pointAt0)) {
if (nodeIsSelected(pointAt0)) {
pointAt1 = SBasisIn.valueAt(weightValue);
- if (weightValue != 0.0000) {
+ if (weightValue != noPower) {
pointAt1 =
Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap);
}
@@ -497,7 +501,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
if (!ignoreCusp || !Geom::are_near((*cubic)[2], pointAt3)) {
if (nodeIsSelected(pointAt3)) {
pointAt2 = SBasisIn.valueAt(1 - weightValue);
- if (weightValue != 0.0000) {
+ if (weightValue != noPower) {
pointAt2 =
Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap);
}
@@ -508,7 +512,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
pointAt2 = in->first_segment()->finalPoint();
}
} else {
- if (!ignoreCusp && weightValue != 0.0000) {
+ if (!ignoreCusp && weightValue != noPower) {
if (nodeIsSelected(pointAt0)) {
pointAt1 = SBasisIn.valueAt(weightValue);
pointAt1 =
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp
index 8ef5a61dc..c52bd4c07 100644
--- a/src/ui/tool/node.cpp
+++ b/src/ui/tool/node.cpp
@@ -59,6 +59,11 @@ Inkscape::ControlType nodeTypeToCtrlType(Inkscape::UI::NodeType type)
namespace Inkscape {
namespace UI {
+const double handleCubicGap = 0.01;
+const double noPower = 0.0;
+const double defaultStartPower = 0.3334;
+const double defaultEndPower = 0.6667;
+
ControlPoint::ColorSet Node::node_colors = {
{0xbfbfbf00, 0x000000ff}, // normal fill, stroke
{0xff000000, 0x000000ff}, // mouseover fill, stroke
@@ -294,7 +299,7 @@ bool Handle::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEven
default: break;
}
break;
- // new double click event to set the handlers of a node to the default proportion, 0.3334%
+ // new double click event to set the handlers of a node to the default proportion, defaultStartPower%
case GDK_2BUTTON_PRESS:
handle_2button_press();
break;
@@ -305,11 +310,11 @@ bool Handle::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEven
return ControlPoint::_eventHandler(event_context, event);
}
-//this function moves the handler and its oposite to the default proportion of 0.3334
+//this function moves the handler and its oposite to the default proportion of defaultStartPower
void Handle::handle_2button_press(){
if(_pm().isBSpline()){
- setPosition(_pm().BSplineHandleReposition(this,0.3334));
- this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),0.3334));
+ setPosition(_pm().BSplineHandleReposition(this,defaultStartPower));
+ this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),defaultStartPower));
_pm().update();
}
}
@@ -618,9 +623,9 @@ void Node::move(Geom::Point const &new_pos)
Geom::Point delta = new_pos - position();
// save the previous nodes strength to apply it again once the node is moved
- double nodeWeight = 0.0000;
- double nextNodeWeight = 0.0000;
- double prevNodeWeight = 0.0000;
+ double nodeWeight = noPower;
+ double nextNodeWeight = noPower;
+ double prevNodeWeight = noPower;
Node *n = this;
Node * nextNode = n->nodeToward(n->front());
Node * prevNode = n->nodeToward(n->back());
@@ -672,9 +677,9 @@ void Node::transform(Geom::Affine const &m)
Geom::Point old_pos = position();
// save the previous nodes strength to apply it again once the node is moved
- double nodeWeight = 0.0000;
- double nextNodeWeight = 0.0000;
- double prevNodeWeight = 0.0000;
+ double nodeWeight = noPower;
+ double nextNodeWeight = noPower;
+ double prevNodeWeight = noPower;
Node *n = this;
Node * nextNode = n->nodeToward(n->front());
Node * prevNode = n->nodeToward(n->back());
@@ -904,12 +909,12 @@ void Node::setType(NodeType type, bool update_handles)
break;
default: break;
}
- /* in node type changes, about bspline traces, we can mantain them with 0.0000 power in border mode,
+ /* in node type changes, about bspline traces, we can mantain them with noPower power in border mode,
or we give them the default power in curve mode */
if(_pm().isBSpline()){
- double weight = 0.0000;
- if(_pm().BSplineHandlePosition(this->front()) != 0.0000 ){
- weight = 0.3334;
+ double weight = noPower;
+ if(_pm().BSplineHandlePosition(this->front()) != noPower ){
+ weight = defaultStartPower;
}
_front.setPosition(_pm().BSplineHandleReposition(this->front(),weight));
_back.setPosition(_pm().BSplineHandleReposition(this->back(),weight));
@@ -1455,7 +1460,7 @@ Glib::ustring Node::_getTip(unsigned state) const
"<b>%s</b>: drag to shape the path (more: Shift, Ctrl, Alt)"), nodetype);
}else if(_selection.size() == 1){
return format_tip(C_("Path node tip",
- "<b>BSpline node</b>: %g weight, drag to shape the path (more: Shift, Ctrl, Alt)"),0.0000/*this->bsplineWeight*/);
+ "<b>BSpline node</b>: %g weight, drag to shape the path (more: Shift, Ctrl, Alt)"),noPower/*this->bsplineWeight*/);
}
return format_tip(C_("Path node tip",
"<b>%s</b>: drag to shape the path, click to toggle scale/rotation handles (more: Shift, Ctrl, Alt)"), nodetype);
diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp
index 48b19ef7a..52ff5d42c 100644
--- a/src/ui/tool/path-manipulator.cpp
+++ b/src/ui/tool/path-manipulator.cpp
@@ -56,6 +56,10 @@ enum PathChange {
};
} // anonymous namespace
+const double handleCubicGap = 0.01;
+const double noPower = 0.0;
+const double defaultStartPower = 0.3334;
+const double defaultEndPower = 0.6667;
/**
* Notifies the path manipulator when something changes the path being edited
@@ -1003,7 +1007,7 @@ NodeList::iterator PathManipulator::subdivideSegment(NodeList::iterator first, d
lineInsideNodes->moveto(n->position());
lineInsideNodes->lineto(second->position());
SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis();
- Geom::Point next = SBasisInsideNodes.valueAt(0.3334);
+ Geom::Point next = SBasisInsideNodes.valueAt(defaultStartPower);
next = Geom::Point(next[Geom::X] + handleCubicGap,next[Geom::Y] + handleCubicGap);
lineInsideNodes->reset();
n->front()->setPosition(next);
@@ -1014,7 +1018,7 @@ NodeList::iterator PathManipulator::subdivideSegment(NodeList::iterator first, d
lineInsideNodes->moveto(n->position());
lineInsideNodes->lineto(first->position());
SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis();
- Geom::Point previous = SBasisInsideNodes.valueAt(0.3334);
+ Geom::Point previous = SBasisInsideNodes.valueAt(defaultStartPower);
previous = Geom::Point(previous[Geom::X] + handleCubicGap,previous[Geom::Y] + handleCubicGap);
n->back()->setPosition(previous);
}else{
@@ -1246,7 +1250,7 @@ double PathManipulator::BSplineHandlePosition(Handle *h, Handle *h2){
if(h2){
h = h2;
}
- double pos = 0.0000;
+ double pos = noPower;
const double handleCubicGap = 0.01;
Node *n = h->parent();
Node * nextNode = NULL;
@@ -1259,7 +1263,7 @@ double PathManipulator::BSplineHandlePosition(Handle *h, Handle *h2){
pos = Geom::nearest_point(Geom::Point(h->position()[X] - handleCubicGap, h->position()[Y] - handleCubicGap), *lineInsideNodes->first_segment());
}
}
- if (pos == 0.0000 && !h2){
+ if (pos == noPower && !h2){
return BSplineHandlePosition(h, h->other());
}
return pos;
@@ -1282,14 +1286,14 @@ Geom::Point PathManipulator::BSplineHandleReposition(Handle *h,double pos){
SPCurve *lineInsideNodes = new SPCurve();
Node * nextNode = NULL;
nextNode = n->nodeToward(h);
- if(nextNode && pos != 0.0000){
+ if(nextNode && pos != noPower){
lineInsideNodes->moveto(n->position());
lineInsideNodes->lineto(nextNode->position());
SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis();
ret = SBasisInsideNodes.valueAt(pos);
ret = Geom::Point(ret[X] + handleCubicGap,ret[Y] + handleCubicGap);
}else{
- if(pos == 0.0000){
+ if(pos == noPower){
ret = n->position();
}
}