summaryrefslogtreecommitdiffstats
path: root/src/helper
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-05-09 20:48:48 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-05-09 20:48:48 +0000
commit3ce6cb91e8259ec064956c79c2cc4f9050dccbce (patch)
tree32c37696d62b47f8e01dae448a07fdaff70d471b /src/helper
parentupdate to trunk (diff)
downloadinkscape-3ce6cb91e8259ec064956c79c2cc4f9050dccbce.tar.gz
inkscape-3ce6cb91e8259ec064956c79c2cc4f9050dccbce.zip
fixing review
(bzr r13645.1.86)
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/geom-pathinfo.cpp73
-rw-r--r--src/helper/geom-pathinfo.h25
-rw-r--r--src/helper/geom-pointwise.cpp45
-rw-r--r--src/helper/geom-pointwise.h23
-rw-r--r--src/helper/geom-satellite-enum.h39
-rw-r--r--src/helper/geom-satellite.cpp201
-rw-r--r--src/helper/geom-satellite.h50
7 files changed, 200 insertions, 256 deletions
diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp
index 38d58d417..9e5e409c3 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 pathvector and allow get info about it
*/ /*
* Authors:
* 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
@@ -11,48 +11,37 @@
#include <helper/geom-pathinfo.h>
#include <2geom/sbasis-to-bezier.h>
-namespace Geom {
-
/**
- * @brief Pathinfo store the data of a pathvector and allow get info about it
+ * @brief Pathinfo store the _data of a pathvector and allow get info about it
*
*/
Pathinfo::Pathinfo(Piecewise<D2<SBasis> > pwd2)
{
- _setPathInfo(pwd2);
+ set(pwd2);
}
-;
+
Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate)
{
- _setPathInfo(path_vector, skip_degenerate);
+ set(path_vector, skip_degenerate);
}
-;
-Pathinfo::~Pathinfo() {}
-;
-void Pathinfo::setPwd2(Piecewise<D2<SBasis> > pwd2)
-{
- _setPathInfo(pwd2);
-}
+Pathinfo::~Pathinfo() {}
-void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate)
-{
- _setPathInfo(path_vector, skip_degenerate);
-}
-void Pathinfo::_setPathInfo(Piecewise<D2<SBasis> > pwd2)
+void Pathinfo::set(Piecewise<D2<SBasis> > pwd2)
{
- _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001));
+ set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001));
}
-/** Store the base path data
+/** Store the base path _data
*/
-void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate)
+void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate)
{
- data.clear();
+ _data.clear();
size_t counter = 0;
for (PathVector::const_iterator path_it = path_vector.begin();
- path_it != path_vector.end(); ++path_it) {
+ path_it != path_vector.end(); ++path_it)
+ {
if (path_it->empty()) {
continue;
}
@@ -73,31 +62,31 @@ void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate)
counter++;
}
if (path_it->closed()) {
- data.push_back(std::make_pair(counter - 1, true));
+ _data.push_back(std::make_pair(counter - 1, true));
} else {
- data.push_back(std::make_pair(counter - 1, false));
+ _data.push_back(std::make_pair(counter - 1, false));
}
}
}
-size_t Pathinfo::size() const
+size_t Pathinfo::subPathCounter() const
{
- return data.back().first + 1;
+ return _data.back().first + 1;
}
size_t Pathinfo::subPathSize(size_t index) const
{
size_t size = 0;
- if( data.size() > index){
- size = data[index].first + 1;
+ if( _data.size() > index){
+ size = _data[index].first + 1;
}
return size;
}
size_t Pathinfo::subPathIndex(size_t index) const
{
- for (size_t i = 0; i < data.size(); i++) {
- if (index <= data[i].first) {
+ for (size_t i = 0; i < _data.size(); i++) {
+ if (index <= _data[i].first) {
return i;
}
}
@@ -106,9 +95,9 @@ size_t Pathinfo::subPathIndex(size_t index) const
size_t Pathinfo::last(size_t index) const
{
- for (size_t i = 0; i < data.size(); i++) {
- if (index <= data[i].first) {
- return data[i].first;
+ for (size_t i = 0; i < _data.size(); i++) {
+ if (index <= _data[i].first) {
+ return _data[i].first;
}
}
return 0;
@@ -116,12 +105,12 @@ size_t Pathinfo::last(size_t index) const
size_t Pathinfo::first(size_t index) const
{
- for (size_t i = 0; i < data.size(); i++) {
- if (index <= data[i].first) {
+ for (size_t i = 0; i < _data.size(); i++) {
+ if (index <= _data[i].first) {
if (i == 0) {
return 0;
} else {
- return data[i - 1].first + 1;
+ return _data[i - 1].first + 1;
}
}
}
@@ -152,16 +141,14 @@ boost::optional<size_t> Pathinfo::next(size_t index) const
bool Pathinfo::closed(size_t index) const
{
- for (size_t i = 0; i < data.size(); i++) {
- if (index <= data[i].first) {
- return data[i].second;
+ for (size_t i = 0; i < _data.size(); i++) {
+ if (index <= _data[i].first) {
+ return _data[i].second;
}
}
return false;
}
-}; // namespace Geom
-
/*
Local Variables:
mode:c++
diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h
index 85c4ca6fa..ae05f5b89 100644
--- a/src/helper/geom-pathinfo.h
+++ b/src/helper/geom-pathinfo.h
@@ -1,6 +1,7 @@
/**
* \file
- * \brief Pathinfo store the data of a pathvector and allow get info about it
+ * \brief Pathinfo store data of a pathvector and allow get info about it
+ * \
*/ /*
* Authors:
* 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
@@ -8,26 +9,26 @@
* This code is in public domain
*/
-#ifndef SEEN_GEOM_PATHINFO_H
-#define SEEN_GEOM_PATHINFO_H
+#ifndef SEEN_PATHINFO_H
+#define SEEN_PATHINFO_H
#include <2geom/path.h>
#include <boost/optional.hpp>
-namespace Geom {
-
/**
* @brief Pathinfo store the data of a pathvector and allow get info about it
*
*/
+using namespace Geom;
class Pathinfo {
public:
Pathinfo(Piecewise<D2<SBasis> > pwd2);
Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false);
virtual ~Pathinfo();
- void setPwd2(Piecewise<D2<SBasis> > pwd2);
- void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false);
- size_t size() const;
+ void set(Piecewise<D2<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 subPathSize(size_t index) const;
size_t subPathIndex(size_t index) const;
size_t last(size_t index) const;
@@ -35,16 +36,12 @@ public:
boost::optional<size_t> previous(size_t index) const;
boost::optional<size_t> next(size_t index) const;
bool closed(size_t index) const;
- std::vector<std::pair<size_t, bool> > data;
private:
- void _setPathInfo(Piecewise<D2<SBasis> > pwd2);
- void _setPathInfo(Geom::PathVector path_vector, bool skip_degenerate = false);
+ std::vector<std::pair<size_t, bool> > _data;
};
-} //namespace Geom
-
-#endif //SEEN_GEOM_PATHINFO_H
+#endif //SEEN_PATHINFO_H
/*
Local Variables:
mode:c++
diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp
index 89bde4130..bd03f1d89 100644
--- a/src/helper/geom-pointwise.cpp
+++ b/src/helper/geom-pointwise.cpp
@@ -10,8 +10,6 @@
#include <helper/geom-pointwise.h>
-namespace Geom {
-
/**
* @brief Pointwise a class to manage a vector of satellites per piecewise curve
*
@@ -31,20 +29,20 @@ Pointwise::Pointwise(Piecewise<D2<SBasis> > pwd2,
{
setStart();
}
-;
+
Pointwise::~Pointwise() {}
-;
+
Piecewise<D2<SBasis> > Pointwise::getPwd2() const
{
return _pwd2;
}
-void Pointwise::setPwd2(Piecewise<D2<SBasis> > pwd2_in)
+void Pointwise::setPwd2(Piecewise<D2<SBasis> > const pwd2_in)
{
_pwd2 = pwd2_in;
- _path_info.setPwd2(_pwd2);
+ _path_info.set(_pwd2);
}
std::vector<Satellite> Pointwise::getSatellites() const
@@ -52,7 +50,7 @@ std::vector<Satellite> Pointwise::getSatellites() const
return _satellites;
}
-void Pointwise::setSatellites(std::vector<Satellite> sats)
+void Pointwise::setSatellites(std::vector<Satellite> const sats)
{
_satellites = sats;
setStart();
@@ -62,7 +60,7 @@ void Pointwise::setSatellites(std::vector<Satellite> sats)
*/
void Pointwise::setStart()
{
- std::vector<std::pair<size_t, bool> > path_info = _path_info.data;
+ std::vector<std::pair<size_t, bool> > path_info = _path_info.get();
for (size_t i = 0; i < path_info.size(); i++) {
size_t firstNode = _path_info.first(path_info[i].first);
size_t lastNode = _path_info.last(path_info[i].first);
@@ -78,7 +76,7 @@ void Pointwise::setStart()
/** Fired when a path is modified.
*/
-void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > A, Geom::PathVector B, Satellite S)
+void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > const A, Geom::PathVector const B, Satellite const S)
{
if (_pwd2.size() > A.size()) {
pwd2Sustract(A);
@@ -91,7 +89,7 @@ void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > A, Geom::PathVector
/** Some nodes/subpaths are removed.
*/
-void Pointwise::pwd2Sustract(Piecewise<D2<SBasis> > A)
+void Pointwise::pwd2Sustract(Piecewise<D2<SBasis> > const A)
{
size_t counter = 0;
std::vector<Satellite> sats;
@@ -99,7 +97,8 @@ void Pointwise::pwd2Sustract(Piecewise<D2<SBasis> > A)
setPwd2(A);
for (size_t i = 0; i < _satellites.size(); i++) {
if (_path_info.last(i - counter) < i - counter ||
- !are_near(pwd2[i].at0(), A[i - counter].at0())) {
+ !are_near(pwd2[i].at0(), A[i - counter].at0()))
+ {
counter++;
} else {
sats.push_back(_satellites[i - counter]);
@@ -110,7 +109,7 @@ void Pointwise::pwd2Sustract(Piecewise<D2<SBasis> > A)
/** Append nodes/subpaths to current pointwise
*/
-void Pointwise::pwd2Append(Piecewise<D2<SBasis> > A, Satellite S)
+void Pointwise::pwd2Append(Piecewise<D2<SBasis> > const A, Satellite const S)
{
size_t counter = 0;
std::vector<Satellite> sats;
@@ -120,9 +119,9 @@ void Pointwise::pwd2Append(Piecewise<D2<SBasis> > A, Satellite S)
size_t last = _path_info.last(i - counter);
//Check for subpath closed. If a subpath is closed, is not reversed or moved
//to back
- _path_info.setPwd2(A);
+ _path_info.set(A);
size_t new_subpath_index = _path_info.subPathIndex(i);
- _path_info.setPwd2(_pwd2);
+ _path_info.set(_pwd2);
bool subpath_is_changed = false;
if (_pwd2.size() <= i - counter) {
subpath_is_changed = false;
@@ -163,7 +162,8 @@ void Pointwise::subpathToBack(size_t subpath)
std::vector<Geom::Path> tmp_path;
Geom::Path to_back;
for (PathVector::const_iterator path_it = path_in.begin();
- path_it != path_in.end(); ++path_it) {
+ path_it != path_in.end(); ++path_it)
+ {
if (path_it->empty()) {
continue;
}
@@ -208,7 +208,8 @@ void Pointwise::subpathReverse(size_t start, size_t end)
std::vector<Geom::Path> tmp_path;
Geom::Path rev;
for (PathVector::const_iterator path_it = path_in.begin();
- path_it != path_in.end(); ++path_it) {
+ path_it != path_in.end(); ++path_it)
+ {
if (path_it->empty()) {
continue;
}
@@ -225,11 +226,11 @@ 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> > A, Geom::PathVector B, Satellite S)
+void Pointwise::insertDegenerateSatellites(Piecewise<D2<SBasis> > const A, Geom::PathVector const B, Satellite const S)
{
size_t size_A = A.size();
- _path_info.setPathVector(B);
- size_t size_B = _path_info.size();
+ _path_info.set(B);
+ size_t size_B = _path_info.subPathCounter();
size_t satellite_gap = size_B - size_A;
if (satellite_gap == 0){
return;
@@ -237,7 +238,8 @@ void Pointwise::insertDegenerateSatellites(Piecewise<D2<SBasis> > A, Geom::PathV
size_t counter = 0;
size_t counter_added = 0;
for (PathVector::const_iterator path_it = B.begin();
- path_it != B.end(); ++path_it) {
+ path_it != B.end(); ++path_it)
+ {
if (path_it->empty()) {
continue;
}
@@ -259,11 +261,10 @@ void Pointwise::insertDegenerateSatellites(Piecewise<D2<SBasis> > A, Geom::PathV
}
}
- _path_info.setPwd2(A);
+ _path_info.set(A);
setPwd2(A);
}
-} // namespace Geom
/*
Local Variables:
mode:c++
diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h
index e4b9f2b05..787cdbfff 100644
--- a/src/helper/geom-pointwise.h
+++ b/src/helper/geom-pointwise.h
@@ -8,8 +8,8 @@
* This code is in public domain
*/
-#ifndef SEEN_GEOM_POINTWISE_H
-#define SEEN_GEOM_POINTWISE_H
+#ifndef SEEN_POINTWISE_H
+#define SEEN_POINTWISE_H
#include <helper/geom-satellite.h>
#include <helper/geom-pathinfo.h>
@@ -20,8 +20,6 @@
#include <2geom/path.h>
#include <boost/optional.hpp>
-namespace Geom {
-
/**
* @brief Pointwise a class to manage a vector of satellites per piecewise curve
*
@@ -35,25 +33,26 @@ namespace Geom {
* optional satellites, and remove the active variable in satellites.
*
*/
+using namespace Geom;
class Pointwise {
public:
Pointwise(Piecewise<D2<SBasis> > pwd2, std::vector<Satellite> satellites);
virtual ~Pointwise();
Piecewise<D2<SBasis> > getPwd2() const;
- void setPwd2(Piecewise<D2<SBasis> > pwd2_in);
+ void setPwd2(Piecewise<D2<SBasis> > const pwd2_in);
std::vector<Satellite> getSatellites() const;
- void setSatellites(std::vector<Satellite> sats);
+ void setSatellites(std::vector<Satellite> const sats);
void setStart();
- void recalculateForNewPwd2(Piecewise<D2<SBasis> > A, Geom::PathVector B, Satellite S);
- void pwd2Sustract(Piecewise<D2<SBasis> > A);
- void pwd2Append(Piecewise<D2<SBasis> > A, Satellite S);
+ 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 subpathToBack(size_t subpath);
void subpathReverse(size_t start, size_t end);
- void insertDegenerateSatellites(Piecewise<D2<SBasis> > A, Geom::PathVector B, Satellite S);
+ void insertDegenerateSatellites(Piecewise<D2<SBasis> > const A, Geom::PathVector const B, Satellite const S);
private:
Piecewise<D2<SBasis> > _pwd2;
@@ -61,9 +60,7 @@ private:
Pathinfo _path_info;
};
-} // end namespace Geom
-
-#endif //SEEN_GEOM_POINTWISE_H
+#endif //SEEN_POINTWISE_H
/*
Local Variables:
mode:c++
diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h
deleted file mode 100644
index d82cdabe0..000000000
--- a/src/helper/geom-satellite-enum.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H
-#define LIB2GEOM_SEEN_SATELLITE_ENUM_H
-
-/**
- * \file
- * \brief Satellite types enum
- */ /*
- * Authors:
- * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
- *
- * This code is in public domain
- */
-
-#include "util/enums.h"
-
-namespace Geom {
-
-enum SatelliteType {
- F = 0, //Fillet
- IF, //Inverse Fillet
- C, //Chamfer
- IC, //Inverse Chamfer
- KO // Invalid Satellite)
-};
-
-} //namespace Geom
-
-#endif
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp
index efe6bb37a..397a556a9 100644
--- a/src/helper/geom-satellite.cpp
+++ b/src/helper/geom-satellite.cpp
@@ -17,38 +17,32 @@
#include <2geom/ray.h>
#include <boost/optional.hpp>
-namespace Geom {
-
/**
* @brief Satellite a per ?node/curve holder of data.
*/
Satellite::Satellite() {}
-;
-Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active,
- bool hasMirror, bool hidden, double amount, double angle,
- size_t steps)
- : satelliteType(satelliteType), isTime(isTime), active(active),
- hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle),
- steps(steps) {}
-;
+
+Satellite::Satellite(SatelliteType satellite_type)
+ : satellite_type(satellite_type)
+{}
Satellite::~Satellite() {}
-;
/**
* Calculate the time in d2_in with a size of A
+ * TODO: find a better place to it
*/
-double Satellite::toTime(double A, Geom::D2<Geom::SBasis> d2_in) const
+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 lenghtPart = Geom::length(d2_in, Geom::EPSILON);
- if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) {
- if (lenghtPart != 0) {
- t = A / lenghtPart;
+ 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;
@@ -65,16 +59,17 @@ double Satellite::toTime(double A, Geom::D2<Geom::SBasis> d2_in) const
/**
* Calculate the size in d2_in with a point at A
+ * TODO: find a better place to it
*/
-double Satellite::toSize(double A, Geom::D2<Geom::SBasis> d2_in) const
+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 lenghtPart = Geom::length(d2_in, Geom::EPSILON);
- if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) {
- s = (A * lenghtPart);
+ 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);
@@ -86,81 +81,79 @@ double Satellite::toSize(double A, Geom::D2<Geom::SBasis> d2_in) const
}
/**
- * Calculate the lenght of a satellite from a radious A input.
+ * Calculate the length of a satellite from a radious A input.
+ * convert a arc radius to a satellite length
*/
double Satellite::radToLen(
- double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in,
- Geom::D2<Geom::SBasis> d2_out,
- boost::optional<Geom::Satellite> previousSatellite) const
+ double A, Geom::D2<Geom::SBasis> const d2_in,
+ Geom::D2<Geom::SBasis> const d2_out,
+ Satellite const previousSatellite) const
{
double len = 0;
- if (d2_in && previousSatellite) {
- Piecewise<D2<SBasis> > offset_curve0 =
- Piecewise<D2<SBasis> >(*d2_in) +
- rot90(unitVector(derivative(*d2_in))) * (A);
- Piecewise<D2<SBasis> > offset_curve1 =
- Piecewise<D2<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);
- double p0pt = nearest_point(cp, d2_out);
- len = (*previousSatellite).toSize(p0pt, d2_out);
- } else {
- if (A > 0) {
- len = radToLen(A * -1, *d2_in, d2_out, previousSatellite);
- }
+ Piecewise<D2<SBasis> > offset_curve0 =
+ Piecewise<D2<SBasis> >(d2_in) +
+ rot90(unitVector(derivative(d2_in))) * (A);
+ Piecewise<D2<SBasis> > offset_curve1 =
+ Piecewise<D2<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);
+ double p0pt = nearest_point(cp, d2_out);
+ len = arcLengthAt(p0pt, d2_out);
+ } else {
+ if (A > 0) {
+ len = radToLen(A * -1, d2_in, d2_out, previousSatellite);
}
}
return len;
}
/**
-* Calculate the radious of a satellite from a lenght A input.
+* Calculate the radious of a satellite from a length A input.
+* convert a satellite length to a arc radius
*/
double Satellite::lenToRad(
- double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in,
- Geom::D2<Geom::SBasis> d2_out,
- boost::optional<Geom::Satellite> previousSatellite) const
+ double A, Geom::D2<Geom::SBasis> const d2_in,
+ Geom::D2<Geom::SBasis> const d2_out,
+ Satellite const previousSatellite) const
{
- if (d2_in && previousSatellite) {
- double time_in = (*previousSatellite).time(A, true, *d2_in);
- double time_out = (*previousSatellite).toTime(A, d2_out);
- Geom::Point startArcPoint = (*d2_in).valueAt(time_in);
- Geom::Point endArcPoint = d2_out.valueAt(time_out);
- Piecewise<D2<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;
- 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::CubicBezier const *cubic1 =
- dynamic_cast<Geom::CubicBezier const *>(&*knotCurve1);
- 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);
- if (cubic2) {
- ray2.setPoints(endArcPoint, (*cubic2)[1]);
- }
- bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint,
- endArcPoint - startArcPoint) < 0;
- double distanceArc =
- Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint));
- double angleBetween = angle_between(ray1, ray2, ccwToggle);
- double divisor = std::sin(angleBetween / 2.0);
- if (divisor > 0) {
- return distanceArc / divisor;
- }
+ double time_in = (previousSatellite).time(A, true, d2_in);
+ 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;
+ 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;
+ 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::CubicBezier const *cubic1 =
+ dynamic_cast<Geom::CubicBezier const *>(&*knotCurve1);
+ 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);
+ if (cubic2) {
+ ray2.setPoints(endArcPoint, (*cubic2)[1]);
+ }
+ bool ccwToggle = cross((d2_in).valueAt(1) - startArcPoint,
+ endArcPoint - startArcPoint) < 0;
+ double distanceArc =
+ Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint));
+ double angleBetween = angle_between(ray1, ray2, ccwToggle);
+ double divisor = std::sin(angleBetween / 2.0);
+ if (divisor > 0) {
+ return distanceArc / divisor;
}
return 0;
}
@@ -171,8 +164,8 @@ double Satellite::lenToRad(
double Satellite::time(Geom::D2<Geom::SBasis> d2_in) const
{
double t = amount;
- if (!isTime) {
- t = toTime(t, d2_in);
+ if (!is_time) {
+ t = timeAtArcLength(t, d2_in);
}
if (t > 1) {
t = 1;
@@ -181,7 +174,7 @@ double Satellite::time(Geom::D2<Geom::SBasis> d2_in) const
}
/**.
- * Get the time from a lenght A in other curve, a bolean I gived to reverse time
+ * Get the time from a length A in other curve, a bolean I gived to reverse time
*/
double Satellite::time(double A, bool I,
Geom::D2<Geom::SBasis> d2_in) const
@@ -193,21 +186,21 @@ double Satellite::time(double A, bool I,
return 0;
}
if (!I) {
- return toTime(A, d2_in);
+ return timeAtArcLength(A, d2_in);
}
- double lenghtPart = Geom::length(d2_in, Geom::EPSILON);
- A = lenghtPart - A;
- return toTime(A, d2_in);
+ double length_part = Geom::length(d2_in, Geom::EPSILON);
+ A = length_part - A;
+ return timeAtArcLength(A, d2_in);
}
/**
- * Get the lenght of the satellite in d2_in
+ * Get the length of the satellite in d2_in
*/
-double Satellite::size(Geom::D2<Geom::SBasis> d2_in) const
+double Satellite::arcDistance(Geom::D2<Geom::SBasis> d2_in) const
{
double s = amount;
- if (isTime) {
- s = toSize(s, d2_in);
+ if (is_time) {
+ s = arcLengthAt(s, d2_in);
}
return s;
}
@@ -227,8 +220,8 @@ Geom::Point Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in) const
void Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in)
{
double A = Geom::nearest_point(p, d2_in);
- if (!isTime) {
- A = toSize(A, d2_in);
+ if (!is_time) {
+ A = arcLengthAt(A, d2_in);
}
amount = A;
}
@@ -238,9 +231,13 @@ void Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in)
*/
void Satellite::setSatelliteType(gchar const *A)
{
- std::map<std::string, SatelliteType> GcharMapToSatelliteType =
- boost::assign::map_list_of("F", F)("IF", IF)("C", C)("IC", IC)("KO", KO);
- satelliteType = GcharMapToSatelliteType.find(std::string(A))->second;
+ std::map<std::string, SatelliteType> gchar_map_to_satellite_type =
+ boost::assign::map_list_of("F", FILLET)("IF", INVERSE_FILLET)("C", CHAMFER)("IC", INVERSE_CHAMFER)("KO", INVALID_SATELLITE);
+ std::map<std::string, SatelliteType>::iterator it = gchar_map_to_satellite_type.find(std::string(A));
+ if(it != gchar_map_to_satellite_type.end())
+ {
+ satellite_type = it->second;
+ }
}
/**
@@ -248,13 +245,11 @@ void Satellite::setSatelliteType(gchar const *A)
*/
gchar const *Satellite::getSatelliteTypeGchar() const
{
- std::map<SatelliteType, gchar const *> SatelliteTypeToGcharMap =
- boost::assign::map_list_of(F, "F")(IF, "IF")(C, "C")(IC, "IC")(KO, "KO");
- return SatelliteTypeToGcharMap.at(satelliteType);
+ std::map<SatelliteType, gchar const *> satellite_type_to_gchar_map =
+ boost::assign::map_list_of(FILLET, "F")(INVERSE_FILLET, "IF")(CHAMFER, "C")(INVERSE_CHAMFER, "IC")(INVALID_SATELLITE, "KO");
+ return satellite_type_to_gchar_map.at(satellite_type);
}
-} //namespace Geom
-
/*
Local Variables:
mode:c++
diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h
index df54819fd..263cefa68 100644
--- a/src/helper/geom-satellite.h
+++ b/src/helper/geom-satellite.h
@@ -8,61 +8,67 @@
* This code is in public domain
*/
-#ifndef LIB2GEOM_SEEN_SATELLITE_H
-#define LIB2GEOM_SEEN_SATELLITE_H
+#ifndef SEEN_SATELLITE_H
+#define SEEN_SATELLITE_H
-#include <helper/geom-satellite-enum.h>
#include <2geom/d2.h>
#include <map>
#include <boost/assign.hpp>
+#include "util/enums.h"
-namespace Geom {
+enum SatelliteType {
+ FILLET = 0, //Fillet
+ INVERSE_FILLET, //Inverse Fillet
+ CHAMFER, //Chamfer
+ INVERSE_CHAMFER, //Inverse Chamfer
+ INVALID_SATELLITE // Invalid Satellite)
+};
/**
* @brief Satellite a per ?node/curve holder of data.
*/
+using namespace Geom;
class Satellite {
public:
Satellite();
- Satellite(SatelliteType satelliteType, bool isTime, bool active,
- bool hasMirror, bool hidden, double amount, double angle,
- size_t steps);
+ Satellite(SatelliteType satellite_type);
virtual ~Satellite();
-
- double toSize(double A, Geom::D2<Geom::SBasis> d2_in) const;
- double toTime(double A, Geom::D2<Geom::SBasis> d2_in) const;
- double lenToRad(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in,
+ void setIsTime(bool set_is_time){is_time = set_is_time;}
+ void setActive(bool set_active){active = set_active;}
+ void setHasMirror(bool set_has_mirror){has_mirror = set_has_mirror;}
+ void setHidden(bool set_hidden){hidden = set_hidden;}
+ void setAmount(bool set_amount){amount = set_amount;}
+ void setAngle(bool set_angle){angle = set_angle;}
+ void setSteps(bool set_steps){steps = set_steps;}
+ double lenToRad(double A, Geom::D2<Geom::SBasis> d2_in,
Geom::D2<Geom::SBasis> d2_out,
- boost::optional<Geom::Satellite> previousSatellite) const;
- double radToLen(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in,
+ Satellite previousSatellite) const;
+ double radToLen(double A, Geom::D2<Geom::SBasis> d2_in,
Geom::D2<Geom::SBasis> d2_out,
- boost::optional<Geom::Satellite> previousSatellite) const;
+ Satellite previousSatellite) const;
double time(Geom::D2<Geom::SBasis> d2_in) const;
double time(double A, bool I, Geom::D2<Geom::SBasis> d2_in) const;
- double size(Geom::D2<Geom::SBasis> d2_in) const;
+ double arcDistance(Geom::D2<Geom::SBasis> d2_in) const;
void setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in);
Geom::Point getPosition(Geom::D2<Geom::SBasis> d2_in) const;
void setSatelliteType(gchar const *A);
gchar const *getSatelliteTypeGchar() const;
- //TODO: maybe make after variables protected?
- SatelliteType satelliteType;
- bool isTime;
+ SatelliteType satellite_type;
+ bool is_time;
bool active;
- bool hasMirror;
+ bool has_mirror;
bool hidden;
double amount;
double angle;
size_t steps;
};
-} // end namespace Geom
-
-#endif // LIB2GEOM_SEEN_SATELLITE_H
+#endif // SEEN_SATELLITE_H
/*
Local Variables: