summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-03-21 09:55:27 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-03-21 09:55:27 +0000
commitcfe5bd077cc29fd43385792435f687d468aca13f (patch)
tree3e23e244b5e33a6ab9ad5f2eadf4f65f6c1b5d4f /src
parentAdded delete nodes/satellites (diff)
downloadinkscape-cfe5bd077cc29fd43385792435f687d468aca13f.tar.gz
inkscape-cfe5bd077cc29fd43385792435f687d468aca13f.zip
fix bspline calls and atemp to fic a bug whith map
(bzr r13645.1.46)
Diffstat (limited to 'src')
-rw-r--r--src/2geom/pointwise.cpp109
-rw-r--r--src/2geom/pointwise.h7
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp46
-rw-r--r--src/live_effects/parameter/satellitepairarray.cpp12
-rw-r--r--src/ui/tool/node.cpp20
-rw-r--r--src/ui/tool/path-manipulator.cpp6
-rw-r--r--src/ui/tool/path-manipulator.h2
7 files changed, 84 insertions, 118 deletions
diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp
index 8f7a0b402..f476821ff 100644
--- a/src/2geom/pointwise.cpp
+++ b/src/2geom/pointwise.cpp
@@ -192,66 +192,27 @@ Pointwise::recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A)
void
Pointwise::new_pwd_append(Piecewise<D2<SBasis> > A)
{
- //not working
- PathVector pathv = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001);
- PathVector pathv_new = path_from_piecewise(remove_short_cuts(A, 0.1), 0.001);
unsigned int counter = 0;
- unsigned int counterPaths = 0;
- unsigned int counterCurves = 0;
- for (PathVector::const_iterator path_it = pathv.begin();
- path_it != pathv.end(); ++path_it) {
- if (path_it->empty()) {
- counterPaths++;
- counter++;
- continue;
- }
- Geom::Path::const_iterator curve_it1 = path_it->begin();
- Geom::Path::const_iterator curve_it2 = ++(path_it->begin());
- Geom::Path::const_iterator curve_endit = path_it->end_default();
- if (path_it->closed() && path_it->back_closed().isDegenerate()) {
- const Curve &closingline = path_it->back_closed();
- if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
- curve_endit = path_it->end_open();
- }
- }
- counterCurves = 0;
- while (curve_it2 != curve_endit) {
- counter++;
- counterCurves++;
- ++curve_it1;
- ++curve_it2;
- }
- if(!are_near(curve_it2->pointAt(1),pathv_new[counterPaths].finalPoint(),0.001)){
- pathv_new[counterPaths] = pathv_new[counterPaths].reverse();
+ std::vector<std::pair<unsigned int,Satellite> > sats;
+ for(unsigned i = 0; i < _satellites.size(); i++){
+ if(_satellites[i].second.getIsEndOpen()){
+ _satellites.erase(_satellites.begin() + i);
}
- counterPaths++;
}
- A = paths_to_pw(pathv_new);
-
- counter = 0;
- std::vector<std::pair<unsigned int,Satellite> > sats;
- unsigned int start = 0;
for(unsigned i = 0; i < A.size(); i++){
- if(/*getIsStart(i, A) &&/*/ i!=0 ){
- if(!are_near(A[i-1].at0(),A[start].at0(),0.001)){
- sats.back().second.setIsEndOpen(true);
- }
- start = i;
- }
if(!are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){
counter++;
bool isEndOpen = false;
bool active = true;
bool hidden = false;
- bool flexible = true;
- bool mirror_knots = true;
+ bool isTime = sats[0].second.getIsTime();
+ bool mirror_knots = sats[0].second.getHasMirror();
double amount = 0.0;
double degrees = 0.0;
int steps = 0;
- Satellite sat(F, flexible, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps);
+ Satellite sat(sats[0].second.getSatelliteType(), isTime, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps);
sats.push_back(std::make_pair(i,sat));
} else {
- sats[i-counter].second.setIsEndOpen(false);
sats.push_back(std::make_pair(i,_satellites[i-counter].second));
}
}
@@ -267,52 +228,60 @@ Pointwise::new_pwd_sustract(Piecewise<D2<SBasis> > A)
Piecewise<D2<SBasis> > pwd2 = _pwd2;
setPwd2(A);
for(unsigned i = 0; i < _satellites.size(); i++){
- if(!_satellites[i].second.getIsEndOpen() && (getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001))){
+ if(_satellites[i].second.getIsEndOpen()){
+ _satellites.erase(_satellites.begin() + i);
+ }
+ }
+ for(unsigned i = 0; i < _satellites.size(); i++){
+ if(getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){
counter++;
} else {
sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second));
}
}
- set_extremes(sats,false,true,0.0,0.0);
+ std::cout << sats.size() << "SAAAAAAAAAAAAAAAAAAAAAAAATTSSIZE\n";
+ std::cout << sats.size() << "SAAAAAAAAAAAAAAAAAAAAAAAATTSSIZE\n";
setSatellites(sats);
}
void
-Pointwise::set_extremes(std::vector<std::pair<unsigned int,Satellite> > sats, bool active, bool hidden, double amount, double angle)
+Pointwise::set_extremes(std::vector<std::pair<unsigned int,Satellite> > &sats, bool active, bool hidden, double amount, double angle)
{
for(unsigned int i = 0; i < _pathInfo.size(); i++){
unsigned int firstNode = getFirst(_pathInfo[i].first);
unsigned int lastNode = getLast(_pathInfo[i].first);
if(!getIsClosed(lastNode)){
- bool endOpen = false;
+ unsigned int lastIndex = 0;
for(unsigned i = 0; i < sats.size(); i++){
sats[i].second.setIsEndOpen(false);
if(sats[i].first > lastNode){
break;
}
- if(sats[i].first == firstNode || sats[i].first == lastNode){
+ if(sats[i].first == firstNode){
sats[i].second.setActive(active);
sats[i].second.setHidden(hidden);
- if(sats[i].first == lastNode){
- if(!endOpen){
- endOpen = true;
- } else {
- endOpen = false;
- sats[i].second.setIsEndOpen(true);
- sats[i].second.setAmount(amount);
- sats[i].second.setAngle(angle);
- }
- }
- if(sats[i].first == firstNode){
- sats[i].second.setAmount(amount);
- sats[i].second.setAngle(angle);
- }
+ sats[i].second.setAmount(amount);
+ sats[i].second.setAngle(angle);
+ }
+ if(sats[i].first == lastNode){
+ lastIndex = i;
}
}
+ Satellite sat(sats[0].second.getSatelliteType(), sats[0].second.getIsTime(), true, active, sats[0].second.getHasMirror(), hidden, amount, angle, sats[0].second.getSteps());
+ sats.insert(sats.begin() + lastIndex,std::make_pair(lastNode,sat));
}
}
}
+void
+Pointwise::reverse(unsigned int start,unsigned int end){
+ for(unsigned int i = start; i < end / 2; i++){
+ std::pair<unsigned int,Satellite> tmp = _satellites[i];
+ _satellites[i] = _satellites[end - start - i - 1];
+ _satellites[end - start - i - 1] = tmp;
+ }
+}
+
double
Pointwise::rad_to_len(double A, std::pair<unsigned int,Geom::Satellite> sat) const
{
@@ -381,28 +350,28 @@ Pointwise::len_to_rad(double A, std::pair<unsigned int,Geom::Satellite> sat) co
return 0;
}
-std::vector<Satellite>
+std::vector<unsigned int>
Pointwise::findSatellites(unsigned int A, int B) const
{
- std::vector<Satellite> ret;
+ std::vector<unsigned int> ret;
int counter = 0;
for(unsigned i = 0; i < _satellites.size(); i++){
if(_satellites[i].first == A){
if(counter >= B && B != -1){
return ret;
}
- ret.push_back(_satellites[i].second);
+ ret.push_back(i);
counter++;
}
}
return ret;
}
-std::vector<Satellite>
+std::vector<unsigned int >
Pointwise::findPeviousSatellites(unsigned int A, int B) const
{
boost::optional<unsigned int> previous = getPrevious(A);
- std::vector<Satellite> ret;
+ std::vector<unsigned int> ret;
if(previous){
ret = findSatellites(*previous,B);
}
diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h
index e313722a1..72ff852d0 100644
--- a/src/2geom/pointwise.h
+++ b/src/2geom/pointwise.h
@@ -65,8 +65,8 @@ class Pointwise
public:
Pointwise(Piecewise<D2<SBasis> > pwd2);
virtual ~Pointwise();
- std::vector<Satellite> findSatellites(unsigned int A, int B = -1) const;
- std::vector<Satellite> findPeviousSatellites(unsigned int A, int B) const;
+ std::vector<unsigned int> findSatellites(unsigned int A, int B = -1) const;
+ std::vector<unsigned int> findPeviousSatellites(unsigned int A, int B) const;
double rad_to_len(double A, std::pair<unsigned int,Geom::Satellite> sat) const;
double len_to_rad(double A, std::pair<unsigned int,Geom::Satellite> sat) const;
std::vector<std::pair<unsigned int,Satellite> > getSatellites() const;
@@ -76,7 +76,8 @@ class Pointwise
void recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A);
void new_pwd_append(Piecewise<D2<SBasis> > A);
void new_pwd_sustract(Piecewise<D2<SBasis> > A);
- void set_extremes(std::vector<std::pair<unsigned int,Satellite> > sats, bool active, bool hidden, double amount, double angle);
+ void set_extremes(std::vector<std::pair<unsigned int,Satellite> > &sats, bool active, bool hidden, double amount, double angle);
+ void reverse(unsigned int start,unsigned int end);
void setPathInfo();
void setPathInfo(Piecewise<D2<SBasis> >);
unsigned int getSubPathIndex(unsigned int index) const;
diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp
index 38645a943..09436676c 100644
--- a/src/live_effects/lpe-fillet-chamfer.cpp
+++ b/src/live_effects/lpe-fillet-chamfer.cpp
@@ -374,17 +374,13 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
pwd2_in = remove_short_cuts(pwd2_in, 0.01);
std::vector<std::pair<unsigned int,Geom::Satellite> > sats;
sats = satellitepairarrayparam_values.data();
- pointwise = new Pointwise(pwd2_in);
- pointwise->setSatellites(sats);
- //mandatory call
- satellitepairarrayparam_values.set_pointwise(pointwise);
+
//optional call
if(hide_knots){
satellitepairarrayparam_values.set_helper_size(0);
} else {
satellitepairarrayparam_values.set_helper_size(helper_size);
}
- bool changed = false;
bool refresh = false;
for (std::vector<std::pair<unsigned int,Geom::Satellite> >::iterator it = sats.begin(); it != sats.end(); ++it) {
if(it->second.getIsTime() != flexible){
@@ -398,23 +394,20 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
double size = it->second.toSize(amount,d2_in);
it->second.setAmount(size);
}
- changed = true;
}
if(it->second.getHasMirror() != mirror_knots){
it->second.setHasMirror(mirror_knots);
- changed = true;
refresh = true;
}
if(it->second.getHidden() != hide_knots){
it->second.setHidden(hide_knots);
- changed = true;
refresh = true;
}
}
- if(changed){
- pointwise->setSatellites(sats);
- satellitepairarrayparam_values.set_pointwise(pointwise);
- }
+ pointwise = new Pointwise(pwd2_in);
+ pointwise->setSatellites(sats);
+ //mandatory call
+ satellitepairarrayparam_values.set_pointwise(pointwise);
if(refresh){
refreshKnots();
}
@@ -428,6 +421,9 @@ LPEFilletChamfer::adjustForNewPath(std::vector<Geom::Path> const &path_in)
{
if (!path_in.empty() && pointwise) {
pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)));
+ std::vector<std::pair<unsigned int,Geom::Satellite> > sats = pointwise->getSatellites();
+ pointwise->set_extremes(sats,false,true,0.0,0.0);
+ pointwise->setSatellites(sats);
satellitepairarrayparam_values.set_pointwise(pointwise);
}
}
@@ -476,15 +472,15 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in)
g_warning("LPE Fillet not handle degenerate curves.");
return path_in;
}
- std::vector<Satellite> satVector;
+ std::vector<unsigned int> satIndexes;
Satellite satellite;
Curve *curve_it2Fixed = path_it->begin()->duplicate();
if(!path_it->closed()){
if(curve_it2 != curve_endit){
curve_it2Fixed = (*curve_it2).duplicate();
- satVector = pointwise->findSatellites(counter+1,1);
- if(satVector.size()>0){
- satellite = satVector[0];
+ satIndexes = pointwise->findSatellites(counter+1,1);
+ if(satIndexes.size()>0){
+ satellite = pointwise->getSatellites()[satIndexes[0]].second;
}
} else {
if(time0 != 1){
@@ -500,21 +496,21 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in)
} else {
if(curve_it2 != curve_endit){
curve_it2Fixed = (*curve_it2).duplicate();
- satVector = pointwise->findSatellites(counter+1,1);
- if(satVector.size()>0){
- satellite = satVector[0];
+ satIndexes = pointwise->findSatellites(counter+1,1);
+ if(satIndexes.size()>0){
+ satellite = pointwise->getSatellites()[satIndexes[0]].second;
}
} else {
- satVector = pointwise->findSatellites(first,1);
- if(satVector.size()>0){
- satellite = satVector[0];
+ satIndexes = pointwise->findSatellites(first,1);
+ if(satIndexes.size()>0){
+ satellite = pointwise->getSatellites()[satIndexes[0]].second;
}
}
}
if(first == counter){
- satVector = pointwise->findSatellites(first,1);
- if(satVector.size()>0 && satVector[0].getActive()){
- time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis());
+ satIndexes = pointwise->findSatellites(first,1);
+ if(satIndexes.size()>0 && pointwise->getSatellites()[satIndexes[0]].second.getActive()){
+ time0 = pointwise->getSatellites()[satIndexes[0]].second.getTime(path_it->begin()->duplicate()->toSBasis());
} else {
time0 = 0;
}
diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp
index 045ef2060..47f023c29 100644
--- a/src/live_effects/parameter/satellitepairarray.cpp
+++ b/src/live_effects/parameter/satellitepairarray.cpp
@@ -291,9 +291,9 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p,
Geom::D2<Geom::SBasis> d2_in = pwd2[*d2_prev_index];
double mirrorTime = Geom::nearest_point(s, d2_in);
double timeStart = 0;
- std::vector<Satellite> satVector = pointwise->findPeviousSatellites(satellite.first,1);
- if(satVector.size()>0){
- timeStart = satVector[0].getTime(d2_in);
+ std::vector<unsigned int> satIndexes = pointwise->findPeviousSatellites(satellite.first,1);
+ if(satIndexes.size()>0){
+ timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in);
}
if(timeStart > mirrorTime){
mirrorTime = timeStart;
@@ -349,9 +349,9 @@ FilletChamferKnotHolderEntity::knot_get() const
t = 0;
}
double timeStart = 0;
- std::vector<Satellite> satVector = pointwise->findPeviousSatellites(satellite.first,1);
- if(satVector.size()>0){
- timeStart = satVector[0].getTime(d2_in);
+ std::vector<unsigned int> satIndexes = pointwise->findPeviousSatellites(satellite.first,1);
+ if(satIndexes.size()>0){
+ timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in);
}
if(timeStart > t){
t = timeStart;
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp
index eeea47e4d..5cfc2a0ca 100644
--- a/src/ui/tool/node.cpp
+++ b/src/ui/tool/node.cpp
@@ -175,7 +175,7 @@ void Handle::move(Geom::Point const &new_pos)
setPosition(new_pos);
//move the handler and its oposite the same proportion
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
setPosition(_pm().BSplineHandleReposition(this,this));
this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this));
}
@@ -192,7 +192,7 @@ void Handle::move(Geom::Point const &new_pos)
setRelativePos(new_delta);
//move the handler and its oposite the same proportion
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
setPosition(_pm().BSplineHandleReposition(this,this));
this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this));
}
@@ -218,7 +218,7 @@ void Handle::move(Geom::Point const &new_pos)
setPosition(new_pos);
// moves the handler and its oposite the same proportion
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
setPosition(_pm().BSplineHandleReposition(this,this));
this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this));
}
@@ -313,7 +313,7 @@ bool Handle::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEven
//this function moves the handler and its oposite to the default proportion of defaultStartPower
void Handle::handle_2button_press(){
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
setPosition(_pm().BSplineHandleReposition(this,defaultStartPower));
this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),defaultStartPower));
_pm().update();
@@ -373,7 +373,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event)
new_pos = result;
// moves the handler and its oposite in X fixed positions depending on parameter "steps with control"
// by default in live BSpline
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
setPosition(new_pos);
int steps = _pm().BSplineGetSteps();
new_pos=_pm().BSplineHandleReposition(this,ceilf(_pm().BSplineHandlePosition(this,this)*steps)/steps);
@@ -423,7 +423,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event)
}
}
//if it is bspline but SHIFT or CONTROL are not pressed it fixes it in the original position
- if(_pm().isBSpline() && !held_shift(*event) && !held_control(*event)){
+ if(_pm().isBSpline(false) && !held_shift(*event) && !held_control(*event)){
new_pos=_last_drag_origin();
}
move(new_pos); // needed for correct update, even though it's redundant
@@ -656,7 +656,7 @@ void Node::move(Geom::Point const &new_pos)
_fixNeighbors(old_pos, new_pos);
// move the affected handlers. First the node ones, later the adjoining ones.
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
_front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight));
_back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight));
if(prevNode){
@@ -709,7 +709,7 @@ void Node::transform(Geom::Affine const &m)
_fixNeighbors(old_pos, position());
// move the involved handlers, first the node ones, later the adjoining ones
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
_front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight));
_back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight));
if(prevNode){
@@ -916,7 +916,7 @@ void Node::setType(NodeType type, bool update_handles)
}
/* 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()){
+ if(_pm().isBSpline(false)){
double weight = noPower;
if(_pm().BSplineHandlePosition(this->front()) != noPower ){
weight = defaultStartPower;
@@ -1172,7 +1172,7 @@ void Node::_setState(State state)
mgr.setActive(_canvas_item, true);
mgr.setPrelight(_canvas_item, false);
//this shows the handlers when selecting the nodes
- if(_pm().isBSpline()){
+ if(_pm().isBSpline(false)){
this->front()->setPosition(_pm().BSplineHandleReposition(this->front()));
this->back()->setPosition(_pm().BSplineHandleReposition(this->back()));
}
diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp
index dbcde240a..64eba3921 100644
--- a/src/ui/tool/path-manipulator.cpp
+++ b/src/ui/tool/path-manipulator.cpp
@@ -670,7 +670,7 @@ unsigned PathManipulator::_deleteStretch(NodeList::iterator start, NodeList::ite
start = next;
}
// if we are removing, we readjust the handlers
- if(isBSpline()){
+ if(isBSpline(false)){
if(start.prev()){
start.prev()->front()->setPosition(BSplineHandleReposition(start.prev()->front(),start.prev()->back()));
}
@@ -999,7 +999,7 @@ NodeList::iterator PathManipulator::subdivideSegment(NodeList::iterator first, d
// set new handle positions
Node *n = new Node(_multi_path_manipulator._path_data.node_data, seg2[0]);
- if(!isBSpline()){
+ if(!isBSpline(false)){
n->back()->setPosition(seg1[2]);
n->front()->setPosition(seg2[1]);
n->setType(NODE_SMOOTH, false);
@@ -1245,7 +1245,7 @@ bool PathManipulator::isBSpline(bool recalculate){
return _is_bspline;
}
-bool PathManipulator::isBSpline() const {
+bool PathManipulator::isBSpline(false) const {
return BSplineGetSteps() > 0;
}
diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h
index 4d2bf4300..4badec569 100644
--- a/src/ui/tool/path-manipulator.h
+++ b/src/ui/tool/path-manipulator.h
@@ -107,7 +107,7 @@ private:
void _createControlPointsFromGeometry();
- bool isBSpline(bool recalculate = false);
+ bool isBSpline(bool recalculate);
bool isBSpline() const;
double BSplineHandlePosition(Handle *h, Handle *h2 = NULL);
Geom::Point BSplineHandleReposition(Handle *h, Handle *h2 = NULL);