summaryrefslogtreecommitdiffstats
path: root/src/helper
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-04-01 02:13:16 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-04-01 02:13:16 +0000
commitdff3aa428ff050c2cce501f646977ddad921feca (patch)
tree3152c9b571095e1db57af2522129d278b5f4ce39 /src/helper
parentremoved code comments (diff)
downloadinkscape-dff3aa428ff050c2cce501f646977ddad921feca.tar.gz
inkscape-dff3aa428ff050c2cce501f646977ddad921feca.zip
Move 2Geom work to a intermediate positon -helper-
Removed dependency to helper/geom.h Now use a simple vector, not a vector of pairs of size_t and Satellite Getters and setters on Satellite removed Update store parameter to a more friendly string, like powerstroke Todo: Documentation and Fix coding style. (bzr r13645.1.63)
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/Makefile_insert7
-rw-r--r--src/helper/geom-pathinfo.cpp178
-rw-r--r--src/helper/geom-pathinfo.h81
-rw-r--r--src/helper/geom-pointwise.cpp268
-rw-r--r--src/helper/geom-pointwise.h96
-rw-r--r--src/helper/geom-satellite-enum.h51
-rw-r--r--src/helper/geom-satellite.cpp237
-rw-r--r--src/helper/geom-satellite.h87
8 files changed, 1005 insertions, 0 deletions
diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert
index e59fcfb70..1d051734e 100644
--- a/src/helper/Makefile_insert
+++ b/src/helper/Makefile_insert
@@ -12,8 +12,15 @@ ink_common_sources += \
helper/geom-curves.h \
helper/geom-nodetype.cpp \
helper/geom-nodetype.h \
+ helper/geom-pathinfo.cpp \
+ helper/geom-pathinfo.h \
helper/geom-pathstroke.cpp \
helper/geom-pathstroke.h \
+ helper/geom-pointwise.cpp \
+ 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
new file mode 100644
index 000000000..c8ba01bd0
--- /dev/null
+++ b/src/helper/geom-pathinfo.cpp
@@ -0,0 +1,178 @@
+/*
+ * pathinfo.cpp
+ * Authors:
+ * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
+ * Copyright 2015 authors
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, output to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ */
+
+#include <helper/geom-pathinfo.h>
+#include <2geom/sbasis-to-bezier.h>
+
+namespace Geom {
+
+Pathinfo::Pathinfo(Piecewise<D2<SBasis> > pwd2)
+ : _pwd2(pwd2)
+{
+ setPathInfo();
+};
+
+Pathinfo::~Pathinfo(){};
+
+Piecewise<D2<SBasis> >
+Pathinfo::getPwd2() const
+{
+ return _pwd2;
+}
+
+void
+Pathinfo::setPwd2(Piecewise<D2<SBasis> > pwd2_in)
+{
+ _pwd2 = pwd2_in;
+ setPathInfo();
+}
+
+
+void
+Pathinfo::setPathInfo()
+{
+ _pathInfo.clear();
+ std::vector<Geom::Path> path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001);
+ size_t counter = 0;
+ for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) {
+ if (path_it->empty()){
+ continue;
+ }
+ 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();
+ if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ curve_endit = path_it->end_open();
+ }
+ }
+ while (curve_it1 != curve_endit) {
+ ++curve_it1;
+ counter++;
+ }
+ if(path_it->closed()){
+ _pathInfo.push_back(std::make_pair(counter-1,true));
+ } else {
+ _pathInfo.push_back(std::make_pair(counter-1,false));
+ }
+ }
+}
+
+size_t
+Pathinfo::getSubPathIndex(size_t index) const
+{
+ for(size_t i = 0; i < _pathInfo.size(); i++){
+ if(index <= _pathInfo[i].first){
+ return i;
+ }
+ }
+ return 0;
+}
+
+size_t
+Pathinfo::getLast(size_t index) const
+{
+ for(size_t i = 0; i < _pathInfo.size(); i++){
+ if(index <= _pathInfo[i].first){
+ return _pathInfo[i].first;
+ }
+ }
+ return 0;
+}
+
+size_t
+Pathinfo::getFirst(size_t index) const
+{
+ for(size_t i = 0; i < _pathInfo.size(); i++){
+ if(index <= _pathInfo[i].first){
+ if(i==0){
+ return 0;
+ } else {
+ return _pathInfo[i-1].first + 1;
+ }
+ }
+ }
+ return 0;
+}
+
+boost::optional<size_t>
+Pathinfo::getPrevious(size_t index) const
+{
+ if(getFirst(index) == index && getIsClosed(index)){
+ return getLast(index);
+ }
+ if(getFirst(index) == index && !getIsClosed(index)){
+ return boost::none;
+ }
+ return index - 1;
+}
+
+boost::optional<size_t>
+Pathinfo::getNext(size_t index) const
+{
+ if(getLast(index) == index && getIsClosed(index)){
+ return getFirst(index);
+ }
+ if(getLast(index) == index && !getIsClosed(index)){
+ return boost::none;
+ }
+ return index + 1;
+}
+
+bool
+Pathinfo::getIsClosed(size_t index) const
+{
+ for(size_t i = 0; i < _pathInfo.size(); i++){
+ if(index <= _pathInfo[i].first){
+ return _pathInfo[i].second;
+ }
+ }
+ return false;
+}
+
+std::vector<std::pair<size_t, bool> >
+Pathinfo::getPathInfo() const
+{
+ return _pathInfo;
+}
+
+}; // namespace Geom
+
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h
new file mode 100644
index 000000000..1696fd366
--- /dev/null
+++ b/src/helper/geom-pathinfo.h
@@ -0,0 +1,81 @@
+/**
+ * \file
+ * \brief Pathinfo
+ *//*
+ * Authors:
+ * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
+ * Copyright 2015 authors
+ *
+ * Pathinfo maintains ....
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, output to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ */
+
+#ifndef SEEN_GEOM_PATHINFO_H
+#define SEEN_GEOM_PATHINFO_H
+
+#include <2geom/path.h>
+#include <boost/optional.hpp>
+
+namespace Geom {
+
+/**
+ * %Pathinfo function class.
+ */
+
+class Pathinfo
+{
+ public:
+ Pathinfo(Piecewise<D2<SBasis> > pwd2);
+ virtual ~Pathinfo();
+ Piecewise<D2<SBasis> > getPwd2() const;
+ void setPwd2(Piecewise<D2<SBasis> > pwd2_in);
+ size_t getSubPathIndex(size_t index) const;
+ size_t getLast(size_t index) const;
+ size_t getFirst(size_t index) const;
+ boost::optional<size_t> getPrevious(size_t index) const;
+ boost::optional<size_t> getNext(size_t index) const;
+ bool getIsClosed(size_t index) const;
+ std::vector<std::pair<size_t, bool> > getPathInfo() const;
+
+ private:
+ void setPathInfo();
+ Piecewise<D2<SBasis> > _pwd2;
+ std::vector<std::pair<size_t, bool> > _pathInfo;
+};
+
+} //namespace Geom
+
+
+#endif //SEEN_GEOM_PATHINFO_H
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp
new file mode 100644
index 000000000..4926bcc47
--- /dev/null
+++ b/src/helper/geom-pointwise.cpp
@@ -0,0 +1,268 @@
+/*
+ * pointwise.cpp
+ * Authors:
+ * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
+ * Copyright 2015 authors
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, output to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ */
+
+#include <helper/geom-pointwise.h>
+#include <cmath>
+
+namespace Geom {
+
+Pointwise::Pointwise(Piecewise<D2<SBasis> > pwd2, std::vector<Satellite> satellites)
+ : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2)
+{
+};
+
+Pointwise::~Pointwise(){};
+
+Piecewise<D2<SBasis> >
+Pointwise::getPwd2() const
+{
+ return _pwd2;
+}
+
+void
+Pointwise::setPwd2(Piecewise<D2<SBasis> > pwd2_in)
+{
+ _pwd2 = pwd2_in;
+ _pathInfo.setPwd2(_pwd2);
+}
+
+std::vector<Satellite>
+Pointwise::getSatellites() const
+{
+ return _satellites;
+}
+
+void
+Pointwise::setSatellites(std::vector<Satellite> sats)
+{
+ _satellites = sats;
+}
+
+void
+Pointwise::recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A)
+{
+ if( _pwd2.size() > A.size()){
+ pwd2_sustract(A);
+ } else if (_pwd2.size() < A.size()){
+ pwd2_append(A);
+ }
+}
+
+void
+Pointwise::pwd2_append(Piecewise<D2<SBasis> > A)
+{
+ size_t counter = 0;
+ std::vector<Satellite> sats;
+ bool reversed = false;
+ bool reorder = false;
+ for(size_t i = 0; i < A.size(); i++){
+ size_t first = _pathInfo.getFirst(i-counter);
+ size_t last = _pathInfo.getLast(i-counter);
+ _pathInfo.setPwd2(A);
+ size_t subpathAIndex = _pathInfo.getSubPathIndex(i);
+ _pathInfo.setPwd2(_pwd2);
+ bool changedSubpath = false;
+ if(_pwd2.size() <= i-counter){
+ changedSubpath = false;
+ } else {
+ changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter);
+ }
+ if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){
+ subpath_append_reorder(_pathInfo.getSubPathIndex(first));
+ reorder = true;
+ i--;
+ continue;
+ }
+ if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){
+ reverse(first, last);
+ reversed = true;
+ }
+ if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){
+ counter++;
+ bool active = true;
+ bool hidden = false;
+ bool isTime = _satellites[0].isTime;
+ bool mirror_knots = _satellites[0].hasMirror;
+ double amount = 0.0;
+ double degrees = 0.0;
+ int steps = 0;
+ Satellite sat(_satellites[0].satelliteType, isTime, active, mirror_knots, hidden, amount, degrees, steps);
+ sats.push_back(sat);
+ } else {
+ sats.push_back(_satellites[i-counter]);
+ }
+ }
+ setPwd2(A);
+ setSatellites(sats);
+}
+
+void
+Pointwise::pwd2_sustract(Piecewise<D2<SBasis> > A)
+{
+ size_t counter = 0;
+ std::vector<Satellite> sats;
+ Piecewise<D2<SBasis> > pwd2 = _pwd2;
+ setPwd2(A);
+ for(size_t i = 0; i < _satellites.size(); i++){
+ if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){
+ counter++;
+ } else {
+ sats.push_back(_satellites[i-counter]);
+ }
+ }
+ setSatellites(sats);
+}
+
+void
+Pointwise::set_extremes(bool active, bool hidden, double amount, double angle)
+{
+ std::vector<std::pair<size_t, bool> > pathInfo = _pathInfo.getPathInfo();
+ for(size_t i = 0; i < pathInfo.size(); i++){
+ size_t firstNode = _pathInfo.getFirst(pathInfo[i].first);
+ size_t lastNode = _pathInfo.getLast(pathInfo[i].first);
+ if(!_pathInfo.getIsClosed(lastNode)){
+ for(size_t j = 0; j < _satellites.size(); j++){
+ if(j < firstNode || j > lastNode){
+ continue;
+ }
+ if(j == firstNode){
+ _satellites[j].active = active;
+ _satellites[j].hidden = hidden;
+ if(amount >= 0){
+ _satellites[j].amount = amount;
+ }
+ if(angle >= 0){
+ _satellites[j].angle = angle;
+ }
+ }
+ }
+ } else {
+ for(size_t j = 0; j < _satellites.size(); j++){
+ if(j < firstNode){
+ continue;
+ }
+ if(j == firstNode && !_satellites[j].active){
+ _satellites[j].active = true;
+ _satellites[j].hidden = _satellites[j+1].hidden;
+ }
+
+ }
+ }
+ }
+}
+
+void
+Pointwise::subpath_append_reorder(size_t subpath){
+ std::vector<Geom::Path> path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001);
+ size_t nSubpath = 0;
+ size_t counter = 0;
+ 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) {
+ if (path_it->empty()){
+ continue;
+ }
+ 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();
+ if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ curve_endit = path_it->end_open();
+ }
+ while (curve_it1 != curve_endit) {
+ if(nSubpath == subpath){
+ _satellites.push_back(_satellites[counter]);
+ deleteSatellite(counter);
+ } else {
+ counter++;
+ }
+ ++curve_it1;
+ }
+ if(nSubpath == subpath){
+ rev = *path_it;
+ } else {
+ tmp_path.push_back(*path_it);
+ }
+ nSubpath++;
+ }
+ tmp_path.push_back(rev);
+ setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01));
+}
+
+void
+Pointwise::reverse(size_t start,size_t end){
+ start ++;
+ for(size_t i = end; i >= start; i--){
+ _satellites.push_back(_satellites[i]);
+ deleteSatellite(i);
+ }
+ std::vector<Geom::Path> path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001);
+ size_t counter = 0;
+ size_t nSubpath = 0;
+ size_t subpath = _pathInfo.getSubPathIndex(start);
+ 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) {
+ if (path_it->empty()){
+ continue;
+ }
+ counter ++;
+ if(nSubpath == subpath){
+ tmp_path.push_back(path_it->reverse());
+ } else {
+ tmp_path.push_back(*path_it);
+ }
+ nSubpath++;
+ }
+ setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01));
+}
+
+void
+Pointwise::deleteSatellite(size_t A)
+{
+ for (std::vector<Satellite>::iterator it = _satellites.begin(); it != _satellites.end();)
+ {
+ if((unsigned)(it - _satellites.begin()) == A){
+ it = _satellites.erase(it);
+ }
+ }
+}
+
+} // namespace Geom
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h
new file mode 100644
index 000000000..8b5c275b9
--- /dev/null
+++ b/src/helper/geom-pointwise.h
@@ -0,0 +1,96 @@
+/**
+ * \file
+ * \brief Pointwise
+ *//*
+ * Authors:
+ * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
+ * Copyright 2015 authors
+ *
+ * Pointwise maintains a set of "Satellite" positions along a curve/pathvector.
+ * The positions are specified as arc length distances along the curve or by
+ * time in the curve. Splicing operations automatically update the satellite
+ * positions to preserve the intent.
+ * The data is serialised to SVG using a specialiced pointwise LPE parameter to
+ * handle it in th future can be a inkscape based property to paths
+ * Anywhere a Piecewise is used, a Pointwise can be substituted, allowing
+ * existing algorithms to correctly update satellite positions.
+
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, output to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ */
+
+#ifndef SEEN_GEOM_POINTWISE_H
+#define SEEN_GEOM_POINTWISE_H
+
+#include <vector>
+#include <2geom/sbasis.h>
+#include <2geom/sbasis-2d.h>
+#include <2geom/piecewise.h>
+#include <helper/geom-satellite.h>
+#include <helper/geom-pathinfo.h>
+#include <2geom/sbasis-to-bezier.h>
+#include <2geom/path.h>
+#include <boost/optional.hpp>
+
+namespace Geom {
+/**
+ * %Pointwise function class.
+ */
+
+class Pointwise
+{
+ public:
+ Pointwise(Piecewise<D2<SBasis> > pwd2, std::vector<Satellite> satellites);
+ virtual ~Pointwise();
+ std::vector<Satellite> getSatellites() const;
+ void setSatellites(std::vector<Satellite> sats);
+ Piecewise<D2<SBasis> > getPwd2() const;
+ void setPwd2(Piecewise<D2<SBasis> > pwd2_in);
+ void recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A);
+ void pwd2_append(Piecewise<D2<SBasis> > A);
+ void pwd2_sustract(Piecewise<D2<SBasis> > A);
+ void set_extremes(bool active, bool hidden, double amount = -1, double angle = -1);
+ void deleteSatellite(size_t A);
+ void subpath_append_reorder(size_t subpath);
+ void reverse(size_t start,size_t end);
+
+ private:
+ Piecewise<D2<SBasis> > _pwd2;
+ std::vector<Satellite> _satellites;
+ Pathinfo _pathInfo;
+};
+
+} // end namespace Geom
+
+#endif //SEEN_GEOM_POINTWISE_H
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h
new file mode 100644
index 000000000..bcd8d1bb3
--- /dev/null
+++ b/src/helper/geom-satellite-enum.h
@@ -0,0 +1,51 @@
+#ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H
+#define LIB2GEOM_SEEN_SATELLITE_ENUM_H
+
+/*
+ *
+ *
+* Copyright (C) Jabier Arraiza Cenoz <jabier.arraiza@marker.es>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "util/enums.h"
+/*#include <boost/bimap.hpp>
+*/
+
+namespace Geom {
+
+enum SatelliteType {
+ F=0, //Fillet
+ IF, //Inverse Fillet
+ C, //Chamfer
+ IC, //Inverse Chamfer
+ KO // Invalid Satellite)
+};
+
+/* TODO maybe is best do next by bimap
+ typedef boost::bimap< Geom::SatelliteType,gchar const *> map_type ;
+
+ map_type SatelliteTypeBimap;
+
+ SatelliteTypeBimap.insert( map_type::value_type(FILLET, "FILLET"));
+ SatelliteTypeBimap.insert( map_type::value_type(INVERSE_FILLET, "INVERSE_FILLET"));
+ SatelliteTypeBimap.insert( map_type::value_type(CHAMFER, "CHAMFER")) );
+ SatelliteTypeBimap.insert( map_type::value_type(INVERSE_CHAMFER, "INVERSE_CHAMFER"));
+ SatelliteTypeBimap.insert( map_type::value_type(INVALID_SATELLITE, "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
new file mode 100644
index 000000000..73201445a
--- /dev/null
+++ b/src/helper/geom-satellite.cpp
@@ -0,0 +1,237 @@
+/**
+ * \file
+ * \brief Satellite
+ *//*
+ * Authors:
+ * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
+ * Copyright 2015 authors
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ */
+
+#include <helper/geom-satellite.h>
+#include <2geom/curve.h>
+#include <2geom/nearest-point.h>
+#include <2geom/sbasis-geometric.h>
+#include <2geom/path-intersection.h>
+#include <2geom/sbasis-to-bezier.h>
+#include <2geom/ray.h>
+#include <boost/optional.hpp>
+
+
+namespace Geom {
+
+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() {};
+
+double
+Satellite::toTime(double A,Geom::D2<Geom::SBasis> d2_in) const
+{
+ 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;
+ }
+ } 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;
+}
+
+double
+Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) const
+{
+ 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);
+ } 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
+Satellite::rad_to_len(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> 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 = rad_to_len(A * -1, *d2_in, d2_out, previousSatellite);
+ }
+ }
+ }
+ return len;
+}
+
+double
+Satellite::len_to_rad(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> previousSatellite) const
+{
+ if(d2_in && previousSatellite){
+ double time_in = (*previousSatellite).getOpositeTime(A, *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;
+ }
+ }
+ return 0;
+}
+
+double
+Satellite::getOpositeTime(double s, Geom::D2<Geom::SBasis> d2_in) const
+{
+ if(s == 0){
+ return 1;
+ }
+ double lenghtPart = Geom::length(d2_in, Geom::EPSILON);
+ double size = lenghtPart - s;
+ return toTime(size, d2_in);
+}
+
+double
+Satellite::getTime(Geom::D2<Geom::SBasis> d2_in) const
+{
+ double t = amount;
+ if(!isTime){
+ t = toTime(t, d2_in);
+ }
+ if(t > 1){
+ t = 1;
+ }
+ return t;
+}
+
+double
+Satellite::getSize(Geom::D2<Geom::SBasis> d2_in) const
+{
+ double s = amount;
+ if(isTime){
+ s = toSize(s, d2_in);
+ }
+ return s;
+}
+
+
+Geom::Point
+Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in) const
+{
+ double t = getTime(d2_in);
+ return d2_in.valueAt(t);
+}
+
+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);
+ }
+ amount = A;
+}
+
+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;
+}
+
+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);
+}
+
+} //namespace Geom
+
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h
new file mode 100644
index 000000000..f367bb7f3
--- /dev/null
+++ b/src/helper/geom-satellite.h
@@ -0,0 +1,87 @@
+/**
+ * \file
+ * \brief Satellite
+ *//*
+ * Authors:
+ * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
+ * Copyright 2015 authors
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ */
+
+#ifndef LIB2GEOM_SEEN_SATELLITE_H
+#define LIB2GEOM_SEEN_SATELLITE_H
+
+#include <helper/geom-satellite-enum.h>
+#include <2geom/d2.h>
+#include <map>
+#include <boost/assign.hpp>
+
+namespace Geom {
+
+class Satellite
+{
+ public:
+
+ Satellite();
+ Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps);
+
+ virtual ~Satellite();
+
+ void setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in);
+ Geom::Point getPosition(Geom::D2<Geom::SBasis> d2_in) const;
+ double getSize(Geom::D2<Geom::SBasis> d2_in) const;
+ double getTime(Geom::D2<Geom::SBasis> d2_in) const;
+ double getOpositeTime(double A,Geom::D2<Geom::SBasis> SBasisCurve) const;
+ double toSize(double A,Geom::D2<Geom::SBasis> d2_in) const;
+ double toTime(double A,Geom::D2<Geom::SBasis> d2_in) const;
+ double len_to_rad(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> previousSatellite) const;
+ double rad_to_len(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> previousSatellite) const;
+ void setSatelliteType(gchar const * A);
+ gchar const * getSatelliteTypeGchar() const;
+
+ SatelliteType satelliteType;
+ bool isTime;
+ bool active;
+ bool hasMirror;
+ bool hidden;
+ double amount;
+ double angle;
+ size_t steps;
+};
+
+} // end namespace Geom
+
+#endif // LIB2GEOM_SEEN_SATELLITE_H
+
+/*
+ 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:fileencoding=utf-8:textwidth=99 :