summaryrefslogtreecommitdiffstats
path: root/src/2geom/poly.h
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2008-07-16 21:36:19 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2008-07-16 21:36:19 +0000
commit680344945f84364fbbcbe4d4a353a52d4a724653 (patch)
tree1e8f541be4d451eff0e58ec6d76e066dd3167086 /src/2geom/poly.h
parentimproving SVG Fonts UI (diff)
downloadinkscape-680344945f84364fbbcbe4d4a353a52d4a724653.tar.gz
inkscape-680344945f84364fbbcbe4d4a353a52d4a724653.zip
update to latest 2geom (rev1497)
(bzr r6332)
Diffstat (limited to 'src/2geom/poly.h')
-rw-r--r--src/2geom/poly.h48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/2geom/poly.h b/src/2geom/poly.h
index 2d7b79bfe..152626698 100644
--- a/src/2geom/poly.h
+++ b/src/2geom/poly.h
@@ -1,5 +1,5 @@
-#ifndef SEEN_POLY_H
-#define SEEN_POLY_H
+#ifndef LIB2GEOM_SEEN_POLY_H
+#define LIB2GEOM_SEEN_POLY_H
#include <assert.h>
#include <vector>
#include <iostream>
@@ -7,22 +7,24 @@
#include <complex>
#include <2geom/utils.h>
+namespace Geom {
+
class Poly : public std::vector<double>{
public:
// coeff; // sum x^i*coeff[i]
-
+
//unsigned size() const { return coeff.size();}
unsigned degree() const { return size()-1;}
//double operator[](const int i) const { return (*this)[i];}
//double& operator[](const int i) { return (*this)[i];}
-
+
Poly operator+(const Poly& p) const {
Poly result;
const unsigned out_size = std::max(size(), p.size());
const unsigned min_size = std::min(size(), p.size());
//result.reserve(out_size);
-
+
for(unsigned i = 0; i < min_size; i++) {
result.push_back((*this)[i] + p[i]);
}
@@ -38,7 +40,7 @@ public:
const unsigned out_size = std::max(size(), p.size());
const unsigned min_size = std::min(size(), p.size());
result.reserve(out_size);
-
+
for(unsigned i = 0; i < min_size; i++) {
result.push_back((*this)[i] - p[i]);
}
@@ -53,7 +55,7 @@ public:
const unsigned out_size = std::max(size(), p.size());
const unsigned min_size = std::min(size(), p.size());
resize(out_size);
-
+
for(unsigned i = 0; i < min_size; i++) {
(*this)[i] -= p[i];
}
@@ -65,7 +67,7 @@ public:
Poly result;
const unsigned out_size = size();
result.reserve(out_size);
-
+
for(unsigned i = 0; i < out_size; i++) {
result.push_back((*this)[i]);
}
@@ -75,7 +77,7 @@ public:
Poly operator-() const {
Poly result;
result.resize(size());
-
+
for(unsigned i = 0; i < size(); i++) {
result[i] = -(*this)[i];
}
@@ -85,29 +87,27 @@ public:
Poly result;
const unsigned out_size = size();
result.reserve(out_size);
-
+
for(unsigned i = 0; i < out_size; i++) {
result.push_back((*this)[i]*p);
}
assert(result.size() == out_size);
return result;
}
-
- /** Equivalent to multiply by x^terms. */
+ // equivalent to multiply by x^terms, negative terms are disallowed
Poly shifted(unsigned const terms) const {
Poly result;
size_type const out_size = size() + terms;
result.reserve(out_size);
- result.resize(terms, 0.0);
- result.insert(result.end(), this->begin(), this->end());
+ result.resize(terms, 0.0);
+ result.insert(result.end(), this->begin(), this->end());
assert(result.size() == out_size);
return result;
}
-
Poly operator*(const Poly& p) const;
-
+
template <typename T>
T eval(T x) const {
T r = 0;
@@ -116,17 +116,17 @@ public:
}
return r;
}
-
+
template <typename T>
T operator()(T t) const { return (T)eval(t);}
-
+
void normalize();
-
+
void monicify();
Poly() {}
Poly(const Poly& p) : std::vector<double>(p) {}
Poly(const double a) {push_back(a);}
-
+
public:
template <class T, class U>
void val_and_deriv(T x, U &pd) const {
@@ -147,7 +147,7 @@ public:
pd[i] *= cnst;
}
}
-
+
static Poly linear(double ax, double b) {
Poly p;
p.push_back(b);
@@ -191,12 +191,15 @@ inline std::ostream &operator<< (std::ostream &out_file, const Poly &in_poly) {
out_file << " + ";
} else
out_file << in_poly[i];
-
+
}
}
return out_file;
}
+} // namespace Geom
+
+#endif //LIB2GEOM_SEEN_POLY_H
/*
Local Variables:
@@ -208,4 +211,3 @@ inline std::ostream &operator<< (std::ostream &out_file, const Poly &in_poly) {
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
-#endif