| #pragma once |
| |
| #ifndef TCG_POLYLINE_OPS |
| #define TCG_POLYLINE_OPS |
| |
| |
| #include "traits.h" |
| #include "containers_reader.h" |
| #include "point.h" |
| #include "point_ops.h" |
| |
| namespace tcg |
| { |
| namespace polyline_ops |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename ForIt> |
| double length(ForIt begin, ForIt end) |
| { |
| typedef typename std::iterator_traits<ForIt>::value_type point_type; |
| |
| double result = 0.0; |
| |
| for (ForIt jt = begin, it = ++jt; jt != end; it = jt, ++jt) |
| result += tcg::point_ops::dist(*it, *jt); |
| |
| return result; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename ForIt> |
| double area(ForIt begin, ForIt end) |
| { |
| typedef typename std::iterator_traits<ForIt>::value_type point_type; |
| |
| double result = 0.0; |
| |
| if (begin != end) { |
| ForIt jt = begin, it = jt++; |
| |
| for (; jt != end; it = jt++) |
| result += 0.5 * |
| (tcg::point_traits<point_type>::y(*jt) + tcg::point_traits<point_type>::y(*it)) * |
| (tcg::point_traits<point_type>::x(*jt) - tcg::point_traits<point_type>::x(*it)); |
| |
| result += 0.5 * |
| (tcg::point_traits<point_type>::y(*begin) + tcg::point_traits<point_type>::y(*it)) * |
| (tcg::point_traits<point_type>::x(*begin) - tcg::point_traits<point_type>::x(*it)); |
| } |
| |
| return result; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename point_type, typename iter_type> |
| void tripletToQuadratics(const point_type &a, const iter_type &bt, const point_type &c, |
| tcg::sequential_reader<std::vector<point_type>> &output) |
| { |
| |
| output.addElement(*bt); |
| output.addElement(c); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename iter_type, typename containers_reader, typename toQuadsFunc> |
| void toQuadratics(iter_type begin, iter_type end, containers_reader &output, |
| toQuadsFunc &toQuads = &tripletToQuadratics< |
| typename iter_type::value_type, iter_type>, |
| double mergeTol = 1.0); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename RanIt> |
| class StandardDeviationEvaluator |
| { |
| public: |
| typedef RanIt iterator_type; |
| typedef typename std::iterator_traits<RanIt>::difference_type diff_type; |
| typedef typename std::iterator_traits<RanIt>::value_type point_type; |
| typedef typename tcg::point_traits<point_type>::value_type value_type; |
| typedef double penalty_type; |
| |
| protected: |
| iterator_type m_begin, m_end; |
| |
| std::vector<double> m_sums_x, m_sums_y; |
| std::vector<double> m_sums2_x, m_sums2_y; |
| std::vector<double> m_sums_xy; |
| |
| public: |
| StandardDeviationEvaluator(const iterator_type &begin, const iterator_type &end); |
| |
| penalty_type penalty(const iterator_type &a, const iterator_type &b); |
| |
| const iterator_type &begin() const { return m_begin; } |
| const iterator_type &end() const { return m_end; } |
| |
| const std::vector<double> &sums_x() const { return m_sums_x; } |
| const std::vector<double> &sums_y() const { return m_sums_y; } |
| const std::vector<double> &sums2_x() const { return m_sums2_x; } |
| const std::vector<double> &sums2_y() const { return m_sums2_y; } |
| const std::vector<double> &sums_xy() const { return m_sums_xy; } |
| }; |
| } |
| } |
| |
| #ifdef INCLUDE_HPP |
| #include "hpp/polyline_ops.hpp" |
| #endif |
| |
| #endif |