diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-04-01 15:54:35 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-04-01 15:54:35 +0000 |
| commit | f3965759e52107c1cdcd8b7e248e5538fdaa11b6 (patch) | |
| tree | efa7e5eb155b812903d14e76244e462dd84f47d8 /src/helper/geom-satellite.cpp | |
| parent | add documentation (diff) | |
| download | inkscape-f3965759e52107c1cdcd8b7e248e5538fdaa11b6.tar.gz inkscape-f3965759e52107c1cdcd8b7e248e5538fdaa11b6.zip | |
Added documentation and fix to coding style.
(bzr r13645.1.66)
Diffstat (limited to 'src/helper/geom-satellite.cpp')
| -rw-r--r-- | src/helper/geom-satellite.cpp | 153 |
1 files changed, 83 insertions, 70 deletions
diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 6304b4148..efe6bb37a 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -1,12 +1,12 @@ /** * \file * \brief Satellite a per ?node/curve holder of data. - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> + * + * This code is in public domain + */ #include <helper/geom-satellite.h> #include <2geom/curve.h> @@ -17,26 +17,31 @@ #include <2geom/ray.h> #include <boost/optional.hpp> - namespace Geom { /** * @brief Satellite a per ?node/curve holder of data. */ -Satellite::Satellite(){}; +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 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() {}; +Satellite::~Satellite() {} +; /** * Calculate the time in d2_in with a size of A */ -double -Satellite::toTime(double A,Geom::D2<Geom::SBasis> d2_in) const +double Satellite::toTime(double A, Geom::D2<Geom::SBasis> d2_in) const { - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double t = 0; @@ -61,10 +66,9 @@ Satellite::toTime(double A,Geom::D2<Geom::SBasis> d2_in) const /** * Calculate the size in d2_in with a point at A */ -double -Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) const +double Satellite::toSize(double A, Geom::D2<Geom::SBasis> d2_in) const { - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double s = 0; @@ -84,66 +88,78 @@ Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) const /** * Calculate the lenght of a satellite from a radious A input. */ -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 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 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); + 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); + if (cs.size() > 0) { + Point cp = p0(cs[0].ta); double p0pt = nearest_point(cp, d2_out); - len = (*previousSatellite).toSize(p0pt,d2_out); + len = (*previousSatellite).toSize(p0pt, d2_out); } else { - if(A > 0){ - len = rad_to_len(A * -1, *d2_in, d2_out, previousSatellite); + 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. - */ -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 +/** +* Calculate the radious of a satellite from a lenght A input. +*/ +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 { - if(d2_in && previousSatellite){ - double time_in = (*previousSatellite).getOpositeTime(A, *d2_in); - double time_out = (*previousSatellite).toTime(A,d2_out); + 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(); + 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(); + 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); + 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); + 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)); + 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 divisor = std::sin(angleBetween / 2.0); + if (divisor > 0) { + return distanceArc / divisor; } } return 0; @@ -152,14 +168,13 @@ Satellite::len_to_rad(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, /** * Get the time position of the satellite in d2_in */ -double -Satellite::getTime(Geom::D2<Geom::SBasis> d2_in) const +double Satellite::time(Geom::D2<Geom::SBasis> d2_in) const { double t = amount; - if(!isTime){ + if (!isTime) { t = toTime(t, d2_in); } - if(t > 1){ + if (t > 1) { t = 1; } return t; @@ -168,16 +183,16 @@ Satellite::getTime(Geom::D2<Geom::SBasis> d2_in) const /**. * Get the time from a lenght A in other curve, a bolean I gived to reverse time */ -double -Satellite::getTime(double A, bool I, Geom::D2<Geom::SBasis> d2_in) const +double Satellite::time(double A, bool I, + Geom::D2<Geom::SBasis> d2_in) const { - if(A == 0 && I){ + if (A == 0 && I) { return 1; } - if(A == 0 && !I){ + if (A == 0 && !I) { return 0; } - if(!I){ + if (!I) { return toTime(A, d2_in); } double lenghtPart = Geom::length(d2_in, Geom::EPSILON); @@ -188,11 +203,10 @@ Satellite::getTime(double A, bool I, Geom::D2<Geom::SBasis> d2_in) const /** * Get the lenght of the satellite in d2_in */ -double -Satellite::getSize(Geom::D2<Geom::SBasis> d2_in) const +double Satellite::size(Geom::D2<Geom::SBasis> d2_in) const { double s = amount; - if(isTime){ + if (isTime) { s = toSize(s, d2_in); } return s; @@ -201,21 +215,19 @@ Satellite::getSize(Geom::D2<Geom::SBasis> d2_in) const /** * Get the point position of the satellite */ -Geom::Point -Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in) const +Geom::Point Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in) const { - double t = getTime(d2_in); + double t = time(d2_in); return d2_in.valueAt(t); } /** * Set the position of the satellite from a gived point P */ -void -Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in) +void Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in) { double A = Geom::nearest_point(p, d2_in); - if(!isTime){ + if (!isTime) { A = toSize(A, d2_in); } amount = A; @@ -224,21 +236,20 @@ Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in) /** * Map a satellite type with gchar */ -void -Satellite::setSatelliteType(gchar const * 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); + 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; } - /** * Map a gchar with satelliteType */ -gchar const * -Satellite::getSatelliteTypeGchar() const +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"); + 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); } @@ -253,4 +264,6 @@ Satellite::getSatelliteTypeGchar() const fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : |
