summaryrefslogtreecommitdiffstats
path: root/src/helper
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-05-10 11:40:31 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-05-10 11:40:31 +0000
commit870dbb0348163f55263eb9dca601d525d53a8d79 (patch)
tree63ad837d271d8134f393aa587516e45cf4e6550b /src/helper
parentupdate to trunk (diff)
downloadinkscape-870dbb0348163f55263eb9dca601d525d53a8d79.tar.gz
inkscape-870dbb0348163f55263eb9dca601d525d53a8d79.zip
Working on Krzysztof review. Seems to be all fixed.
TODO: double check review and comment (bzr r13645.1.89)
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/Makefile_insert1
-rw-r--r--src/helper/geom-pathinfo.cpp20
-rw-r--r--src/helper/geom-pathinfo.h12
-rw-r--r--src/helper/geom-pointwise.cpp34
-rw-r--r--src/helper/geom-pointwise.h20
-rw-r--r--src/helper/geom-satellite.cpp71
-rw-r--r--src/helper/geom-satellite.h55
7 files changed, 111 insertions, 102 deletions
diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert
index 1d051734e..919234b47 100644
--- a/src/helper/Makefile_insert
+++ b/src/helper/Makefile_insert
@@ -20,7 +20,6 @@ ink_common_sources += \
helper/geom-pointwise.h \
helper/geom-satellite.cpp \
helper/geom-satellite.h \
- helper/geom-satellite-enum.h \
helper/gnome-utils.cpp \
helper/gnome-utils.h \
helper/mathfns.h \
diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp
index 9e5e409c3..5ffd1d31e 100644
--- a/src/helper/geom-pathinfo.cpp
+++ b/src/helper/geom-pathinfo.cpp
@@ -1,6 +1,6 @@
/**
* \file
- * \brief Pathinfo store the _data of a pathvector and allow get info about it
+ * \brief Pathinfo store the _data of a Geom::PathVector and allow get info about it
*/ /*
* Authors:
* 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
@@ -12,10 +12,10 @@
#include <2geom/sbasis-to-bezier.h>
/**
- * @brief Pathinfo store the _data of a pathvector and allow get info about it
+ * @brief Pathinfo store the _data of a Geom::PathVector and allow get info about it
*
*/
-Pathinfo::Pathinfo(Piecewise<D2<SBasis> > pwd2)
+Pathinfo::Pathinfo(Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2)
{
set(pwd2);
}
@@ -29,7 +29,7 @@ Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate)
Pathinfo::~Pathinfo() {}
-void Pathinfo::set(Piecewise<D2<SBasis> > pwd2)
+void Pathinfo::set(Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2)
{
set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001));
}
@@ -39,7 +39,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate)
{
_data.clear();
size_t counter = 0;
- for (PathVector::const_iterator path_it = path_vector.begin();
+ for (Geom::PathVector::const_iterator path_it = path_vector.begin();
path_it != path_vector.end(); ++path_it)
{
if (path_it->empty()) {
@@ -48,7 +48,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate)
Geom::Path::const_iterator curve_it1 = path_it->begin();
Geom::Path::const_iterator curve_endit = path_it->end_default();
if (path_it->closed()) {
- const Curve &closingline = path_it->back_closed();
+ Geom::Curve const &closingline = path_it->back_closed();
if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
curve_endit = path_it->end_open();
}
@@ -69,7 +69,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate)
}
}
-size_t Pathinfo::subPathCounter() const
+size_t Pathinfo::size() const
{
return _data.back().first + 1;
}
@@ -78,7 +78,11 @@ size_t Pathinfo::subPathSize(size_t index) const
{
size_t size = 0;
if( _data.size() > index){
- size = _data[index].first + 1;
+ double prev = 0;
+ if(index != 0){
+ prev = _data[index - 1].first;
+ }
+ size = prev - _data[index].first + 1;
}
return size;
}
diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h
index ae05f5b89..8a6c51e51 100644
--- a/src/helper/geom-pathinfo.h
+++ b/src/helper/geom-pathinfo.h
@@ -1,6 +1,6 @@
/**
* \file
- * \brief Pathinfo store data of a pathvector and allow get info about it
+ * \brief Pathinfo store data of a Geom::PathVector and allow get info about it
* \
*/ /*
* Authors:
@@ -16,19 +16,19 @@
#include <boost/optional.hpp>
/**
- * @brief Pathinfo store the data of a pathvector and allow get info about it
+ * @brief Pathinfo store the data of a Geom::PathVector and allow get info about it
*
*/
-using namespace Geom;
+
class Pathinfo {
public:
- Pathinfo(Piecewise<D2<SBasis> > pwd2);
+ Pathinfo(Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2);
Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false);
virtual ~Pathinfo();
- void set(Piecewise<D2<SBasis> > pwd2);
+ void set(Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2);
void set(Geom::PathVector path_vector, bool skip_degenerate = false);
std::vector<std::pair<size_t, bool> > get(){return _data;};
- size_t subPathCounter() const;
+ size_t size() const;
size_t subPathSize(size_t index) const;
size_t subPathIndex(size_t index) const;
size_t last(size_t index) const;
diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp
index bd03f1d89..3041c60ea 100644
--- a/src/helper/geom-pointwise.cpp
+++ b/src/helper/geom-pointwise.cpp
@@ -23,7 +23,7 @@
* optional satellites, and remove the active variable in satellites.
*
*/
-Pointwise::Pointwise(Piecewise<D2<SBasis> > pwd2,
+Pointwise::Pointwise(Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2,
std::vector<Satellite> satellites)
: _pwd2(pwd2), _satellites(satellites), _path_info(pwd2)
{
@@ -34,17 +34,23 @@ Pointwise::Pointwise(Piecewise<D2<SBasis> > pwd2,
Pointwise::~Pointwise() {}
-Piecewise<D2<SBasis> > Pointwise::getPwd2() const
+Geom::Piecewise<Geom::D2<Geom::SBasis> > Pointwise::getPwd2() const
{
return _pwd2;
}
-void Pointwise::setPwd2(Piecewise<D2<SBasis> > const pwd2_in)
+void Pointwise::setPwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const pwd2_in)
{
_pwd2 = pwd2_in;
_path_info.set(_pwd2);
}
+void Pointwise::setPathInfo(Geom::PathVector const pv)
+{
+ _path_info.set(pv);
+ setStart();
+}
+
std::vector<Satellite> Pointwise::getSatellites() const
{
return _satellites;
@@ -76,7 +82,7 @@ void Pointwise::setStart()
/** Fired when a path is modified.
*/
-void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > const A, Geom::PathVector const B, Satellite const S)
+void Pointwise::recalculateForNewPwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Geom::PathVector const B, Satellite const S)
{
if (_pwd2.size() > A.size()) {
pwd2Sustract(A);
@@ -89,11 +95,11 @@ void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > const A, Geom::Path
/** Some nodes/subpaths are removed.
*/
-void Pointwise::pwd2Sustract(Piecewise<D2<SBasis> > const A)
+void Pointwise::pwd2Sustract(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A)
{
size_t counter = 0;
std::vector<Satellite> sats;
- Piecewise<D2<SBasis> > pwd2 = _pwd2;
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = _pwd2;
setPwd2(A);
for (size_t i = 0; i < _satellites.size(); i++) {
if (_path_info.last(i - counter) < i - counter ||
@@ -109,7 +115,7 @@ void Pointwise::pwd2Sustract(Piecewise<D2<SBasis> > const A)
/** Append nodes/subpaths to current pointwise
*/
-void Pointwise::pwd2Append(Piecewise<D2<SBasis> > const A, Satellite const S)
+void Pointwise::pwd2Append(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Satellite const S)
{
size_t counter = 0;
std::vector<Satellite> sats;
@@ -161,7 +167,7 @@ void Pointwise::subpathToBack(size_t subpath)
size_t counter = 0;
std::vector<Geom::Path> tmp_path;
Geom::Path to_back;
- for (PathVector::const_iterator path_it = path_in.begin();
+ for (Geom::PathVector::const_iterator path_it = path_in.begin();
path_it != path_in.end(); ++path_it)
{
if (path_it->empty()) {
@@ -169,7 +175,7 @@ void Pointwise::subpathToBack(size_t subpath)
}
Geom::Path::const_iterator curve_it1 = path_it->begin();
Geom::Path::const_iterator curve_endit = path_it->end_default();
- const Curve &closingline = path_it->back_closed();
+ Geom::Curve const &closingline = path_it->back_closed();
if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
curve_endit = path_it->end_open();
}
@@ -207,7 +213,7 @@ void Pointwise::subpathReverse(size_t start, size_t end)
size_t subpath = _path_info.subPathIndex(start);
std::vector<Geom::Path> tmp_path;
Geom::Path rev;
- for (PathVector::const_iterator path_it = path_in.begin();
+ for (Geom::PathVector::const_iterator path_it = path_in.begin();
path_it != path_in.end(); ++path_it)
{
if (path_it->empty()) {
@@ -226,18 +232,18 @@ void Pointwise::subpathReverse(size_t start, size_t end)
/** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves.
*/
-void Pointwise::insertDegenerateSatellites(Piecewise<D2<SBasis> > const A, Geom::PathVector const B, Satellite const S)
+void Pointwise::insertDegenerateSatellites(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Geom::PathVector const B, Satellite const S)
{
size_t size_A = A.size();
_path_info.set(B);
- size_t size_B = _path_info.subPathCounter();
+ size_t size_B = _path_info.size();
size_t satellite_gap = size_B - size_A;
if (satellite_gap == 0){
return;
}
size_t counter = 0;
size_t counter_added = 0;
- for (PathVector::const_iterator path_it = B.begin();
+ for (Geom::PathVector::const_iterator path_it = B.begin();
path_it != B.end(); ++path_it)
{
if (path_it->empty()) {
@@ -246,7 +252,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise<D2<SBasis> > const A, Geom:
Geom::Path::const_iterator curve_it1 = path_it->begin();
Geom::Path::const_iterator curve_endit = path_it->end_default();
if (path_it->closed()) {
- const Curve &closingline = path_it->back_closed();
+ Geom::Curve const &closingline = path_it->back_closed();
if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
curve_endit = path_it->end_open();
}
diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h
index 787cdbfff..b1f2235c6 100644
--- a/src/helper/geom-pointwise.h
+++ b/src/helper/geom-pointwise.h
@@ -33,29 +33,29 @@
* optional satellites, and remove the active variable in satellites.
*
*/
-using namespace Geom;
+
class Pointwise {
public:
- Pointwise(Piecewise<D2<SBasis> > pwd2, std::vector<Satellite> satellites);
+ Pointwise(Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2, std::vector<Satellite> satellites);
virtual ~Pointwise();
- Piecewise<D2<SBasis> > getPwd2() const;
- void setPwd2(Piecewise<D2<SBasis> > const pwd2_in);
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > getPwd2() const;
+ void setPwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const pwd2_in);
std::vector<Satellite> getSatellites() const;
void setSatellites(std::vector<Satellite> const sats);
-
+ void setPathInfo(Geom::PathVector const pv);
void setStart();
- void recalculateForNewPwd2(Piecewise<D2<SBasis> > const A, Geom::PathVector const B, Satellite const S);
- void pwd2Sustract(Piecewise<D2<SBasis> > const A);
- void pwd2Append(Piecewise<D2<SBasis> > const A, Satellite const S);
+ void recalculateForNewPwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Geom::PathVector const B, Satellite const S);
+ void pwd2Sustract(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A);
+ void pwd2Append(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Satellite const S);
void subpathToBack(size_t subpath);
void subpathReverse(size_t start, size_t end);
- void insertDegenerateSatellites(Piecewise<D2<SBasis> > const A, Geom::PathVector const B, Satellite const S);
+ void insertDegenerateSatellites(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Geom::PathVector const B, Satellite const S);
private:
- Piecewise<D2<SBasis> > _pwd2;
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > _pwd2;
std::vector<Satellite> _satellites;
Pathinfo _path_info;
};
diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp
index 51cff7d79..c2d4ef715 100644
--- a/src/helper/geom-satellite.cpp
+++ b/src/helper/geom-satellite.cpp
@@ -28,7 +28,56 @@ Satellite::Satellite(SatelliteType satellite_type)
Satellite::~Satellite() {}
+/**
+ * Calculate the time in d2_in with a size of A
+ * TODO: find a better place to it
+ */
+double timeAtArcLength(double A, Geom::D2<Geom::SBasis> const d2_in)
+{
+ if (!d2_in.isFinite() || d2_in.isZero() || A == 0) {
+ return 0;
+ }
+ double t = 0;
+ double length_part = Geom::length(d2_in, Geom::EPSILON);
+ if (A > length_part || d2_in[0].degreesOfFreedom() == 2) {
+ if (length_part != 0) {
+ t = A / length_part;
+ }
+ } else if (d2_in[0].degreesOfFreedom() != 2) {
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > u;
+ u.push_cut(0);
+ u.push(d2_in, 1);
+ std::vector<double> t_roots = roots(arcLengthSb(u) - A);
+ if (t_roots.size() > 0) {
+ t = t_roots[0];
+ }
+ }
+ return t;
+}
+
+/**
+ * Calculate the size in d2_in with a point at A
+ * TODO: find a better place to it
+ */
+double arcLengthAt(double A, Geom::D2<Geom::SBasis> const d2_in)
+{
+ if (!d2_in.isFinite() || d2_in.isZero() || A == 0) {
+ return 0;
+ }
+ double s = 0;
+ double length_part = Geom::length(d2_in, Geom::EPSILON);
+ if (A > length_part || d2_in[0].degreesOfFreedom() == 2) {
+ s = (A * length_part);
+ } else if (d2_in[0].degreesOfFreedom() != 2) {
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > u;
+ u.push_cut(0);
+ u.push(d2_in, 1);
+ u = Geom::portion(u, 0.0, A);
+ s = Geom::length(u, 0.001);
+ }
+ return s;
+}
/**
* Calculate the length of a satellite from a radious A input.
@@ -40,17 +89,17 @@ double Satellite::radToLen(
Satellite const previousSatellite) const
{
double len = 0;
- Piecewise<D2<SBasis> > offset_curve0 =
- Piecewise<D2<SBasis> >(d2_in) +
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > offset_curve0 =
+ Geom::Piecewise<Geom::D2<Geom::SBasis> >(d2_in) +
rot90(unitVector(derivative(d2_in))) * (A);
- Piecewise<D2<SBasis> > offset_curve1 =
- Piecewise<D2<SBasis> >(d2_out) +
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > offset_curve1 =
+ Geom::Piecewise<Geom::D2<Geom::SBasis> >(d2_out) +
rot90(unitVector(derivative(d2_out))) * (A);
Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0];
Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0];
Geom::Crossings cs = Geom::crossings(p0, p1);
if (cs.size() > 0) {
- Point cp = p0(cs[0].ta);
+ Geom::Point cp = p0(cs[0].ta);
double p0pt = nearest_point(cp, d2_out);
len = arcLengthAt(p0pt, d2_out);
} else {
@@ -74,25 +123,25 @@ double Satellite::lenToRad(
double time_out = timeAtArcLength(A, d2_out);
Geom::Point startArcPoint = (d2_in).valueAt(time_in);
Geom::Point endArcPoint = d2_out.valueAt(time_out);
- Piecewise<D2<SBasis> > u;
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > u;
u.push_cut(0);
u.push(d2_in, 1);
Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate();
- Piecewise<D2<SBasis> > u2;
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > u2;
u2.push_cut(0);
u2.push(d2_out, 1);
Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate();
- Curve *knotCurve1 = C->portion(0, time_in);
- Curve *knotCurve2 = D->portion(time_out, 1);
+ Geom::Curve *knotCurve1 = C->portion(0, time_in);
+ Geom::Curve *knotCurve2 = D->portion(time_out, 1);
Geom::CubicBezier const *cubic1 =
dynamic_cast<Geom::CubicBezier const *>(&*knotCurve1);
- Ray ray1(startArcPoint, (d2_in).valueAt(1));
+ Geom::Ray ray1(startArcPoint, (d2_in).valueAt(1));
if (cubic1) {
ray1.setPoints((*cubic1)[2], startArcPoint);
}
Geom::CubicBezier const *cubic2 =
dynamic_cast<Geom::CubicBezier const *>(&*knotCurve2);
- Ray ray2(d2_out.valueAt(0), endArcPoint);
+ Geom::Ray ray2(d2_out.valueAt(0), endArcPoint);
if (cubic2) {
ray2.setPoints(endArcPoint, (*cubic2)[1]);
}
diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h
index a4b1b23b9..722adbef4 100644
--- a/src/helper/geom-satellite.h
+++ b/src/helper/geom-satellite.h
@@ -28,7 +28,7 @@ enum SatelliteType {
/**
* @brief Satellite a per ?node/curve holder of data.
*/
-using namespace Geom;
+
class Satellite {
public:
@@ -68,57 +68,8 @@ public:
double angle;
size_t steps;
};
-
-/**
- * Calculate the time in d2_in with a size of A
- * TODO: find a better place to it
- */
-double timeAtArcLength(double A, Geom::D2<Geom::SBasis> const d2_in)
-{
- if (!d2_in.isFinite() || d2_in.isZero() || A == 0) {
- return 0;
- }
- double t = 0;
- double length_part = Geom::length(d2_in, Geom::EPSILON);
- if (A > length_part || d2_in[0].degreesOfFreedom() == 2) {
- if (length_part != 0) {
- t = A / length_part;
- }
- } else if (d2_in[0].degreesOfFreedom() != 2) {
- Geom::Piecewise<Geom::D2<Geom::SBasis> > u;
- u.push_cut(0);
- u.push(d2_in, 1);
- std::vector<double> t_roots = roots(arcLengthSb(u) - A);
- if (t_roots.size() > 0) {
- t = t_roots[0];
- }
- }
-
- return t;
-}
-
-/**
- * Calculate the size in d2_in with a point at A
- * TODO: find a better place to it
- */
-double arcLengthAt(double A, Geom::D2<Geom::SBasis> const d2_in)
-{
- if (!d2_in.isFinite() || d2_in.isZero() || A == 0) {
- return 0;
- }
- double s = 0;
- double length_part = Geom::length(d2_in, Geom::EPSILON);
- if (A > length_part || d2_in[0].degreesOfFreedom() == 2) {
- s = (A * length_part);
- } else if (d2_in[0].degreesOfFreedom() != 2) {
- Geom::Piecewise<Geom::D2<Geom::SBasis> > u;
- u.push_cut(0);
- u.push(d2_in, 1);
- u = Geom::portion(u, 0.0, A);
- s = Geom::length(u, 0.001);
- }
- return s;
-}
+double timeAtArcLength(double A, Geom::D2<Geom::SBasis> const d2_in);
+double arcLengthAt(double A, Geom::D2<Geom::SBasis> const d2_in);
#endif // SEEN_SATELLITE_H