Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracles + python #7

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions include/cartesian_geom/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#define POINT_H

#include <iostream>
#include <cmath>
#include <vector>

template <class K>
class point
{
private:
unsigned int d;
typedef std::vector<typename K::FT> Coeff;
typedef typename std::vector<typename K::FT> Coeff;
Coeff coeffs;
typedef typename std::vector<typename K::FT>::iterator iter;
public:
Expand All @@ -33,13 +35,30 @@ class point
d = dim;
coeffs = Coeff(begin,endit);
}

point(const unsigned int dim, FT* data) {
d = dim;
coeffs.reserve(d);
for (uint i=0; i<dim; i++) {
coeffs[i] = data[i];
}
}

FT* data() {
return coeffs.data();
}

Coeff& get_coeffs() {
return coeffs;
}

int dimension() {
return d;
}

void set_dimension(const unsigned int dim) {
d = dim;
coeffs.reserve(d);
}

void set_coord(const unsigned int i, FT coord) {
Expand Down Expand Up @@ -76,6 +95,16 @@ class point
return temp;
}

double squared_distance(point& p) {

double dist = 0.0;
for (auto mit = coeffs.begin(), pit=p.iter_begin(); pit < p.iter_end(); ++pit, ++mit) {
double tmp = (*mit)-(*pit);
dist += tmp*tmp;
}
return dist;
}

point operator* (const FT& k) {
point temp(d, iter_begin(), iter_end());

Expand Down Expand Up @@ -121,7 +150,13 @@ class point
std::cout<<"\n";
#endif
}


void normalize() {
FT lsq=std::sqrt(squared_length());
for (auto mit=coeffs.begin(); mit!=coeffs.end(); mit++){
(*mit) = (*mit)/lsq;
}
}

iter iter_begin() {
return coeffs.begin();
Expand Down
Loading