Skip to content

Commit

Permalink
const cast
Browse files Browse the repository at this point in the history
  • Loading branch information
institution committed Jul 21, 2014
1 parent 8731814 commit 8047f79
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 90 deletions.
206 changes: 152 additions & 54 deletions aga2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Mv0 {
}

template<class F>
Mv0<F> cast() {
Mv0<F> cast() const {
return Mv0<F>(F(arr[0]));
}

Expand All @@ -58,6 +58,34 @@ class Mv0 {
return 1;
}

R norm2() const {

auto& x = *this;
return pow(x[0], 2);
}


Mv0<R> rev() const {

auto& x = *this;
return Mv0<R>(x[0]);
}


Mv0<R> inv() const {

auto& x = *this;
return Mv0<R>(pow(x[0], -1));
}


Mv0<R> operator-() const {

auto& x = *this;
return Mv0<R>((-x[0]));
}


R const* data() const {
return arr.data();
}
Expand Down Expand Up @@ -127,7 +155,7 @@ class Mv1 {
}

template<class F>
Mv1<F> cast() {
Mv1<F> cast() const {
return Mv1<F>(F(arr[0]), F(arr[1]));
}

Expand All @@ -140,6 +168,34 @@ class Mv1 {
return 2;
}

R norm2() const {

auto& x = *this;
return (pow(x[0], 2) + pow(x[1], 2));
}


Mv1<R> rev() const {

auto& x = *this;
return Mv1<R>(x[0], x[1]);
}


Mv1<R> inv() const {

auto& x = *this;
return Mv1<R>((x[0] * pow((pow(x[0], 2) + pow(x[1], 2)), -1)), (x[1] * pow((pow(x[0], 2) + pow(x[1], 2)), -1)));
}


Mv1<R> operator-() const {

auto& x = *this;
return Mv1<R>((-x[0]), (-x[1]));
}


R const* data() const {
return arr.data();
}
Expand Down Expand Up @@ -212,7 +268,7 @@ class Mv2 {
}

template<class F>
Mv2<F> cast() {
Mv2<F> cast() const {
return Mv2<F>(F(arr[0]));
}

Expand All @@ -225,6 +281,34 @@ class Mv2 {
return 1;
}

R norm2() const {

auto& x = *this;
return pow(x[0], 2);
}


Mv2<R> rev() const {

auto& x = *this;
return Mv2<R>((-x[0]));
}


Mv2<R> inv() const {

auto& x = *this;
return Mv2<R>((-pow(x[0], -1)));
}


Mv2<R> operator-() const {

auto& x = *this;
return Mv2<R>((-x[0]));
}


R const* data() const {
return arr.data();
}
Expand Down Expand Up @@ -294,7 +378,7 @@ class Mv02 {
}

template<class F>
Mv02<F> cast() {
Mv02<F> cast() const {
return Mv02<F>(F(arr[0]), F(arr[1]));
}

Expand All @@ -307,6 +391,34 @@ class Mv02 {
return 2;
}

R norm2() const {

auto& x = *this;
return (pow(x[0], 2) + pow(x[1], 2));
}


Mv02<R> rev() const {

auto& x = *this;
return Mv02<R>(x[0], (-x[1]));
}


Mv02<R> inv() const {

auto& x = *this;
return Mv02<R>((x[0] * pow((pow(x[0], 2) + pow(x[1], 2)), -1)), (-1 * x[1] * pow((pow(x[0], 2) + pow(x[1], 2)), -1)));
}


Mv02<R> operator-() const {

auto& x = *this;
return Mv02<R>((-x[0]), (-x[1]));
}


R const* data() const {
return arr.data();
}
Expand Down Expand Up @@ -655,56 +767,6 @@ Mv0<R> inn2(Mv02<R> const& x) {
return Mv0<R>((-pow(x[1], 2)));
}

// reverse
template <class R>
Mv0<R> operator~(Mv0<R> const& x) {

return Mv0<R>(x[0]);
}

template <class R>
Mv1<R> operator~(Mv1<R> const& x) {

return Mv1<R>(x[0], x[1]);
}

template <class R>
Mv2<R> operator~(Mv2<R> const& x) {

return Mv2<R>((-x[0]));
}

template <class R>
Mv02<R> operator~(Mv02<R> const& x) {

return Mv02<R>(x[0], (-x[1]));
}

// norm_r2
template <class R>
Mv0<R> norm_r2(Mv0<R> const& x) {

return Mv0<R>(pow(x[0], 2));
}

template <class R>
Mv0<R> norm_r2(Mv1<R> const& x) {

return Mv0<R>((pow(x[0], 2) + pow(x[1], 2)));
}

template <class R>
Mv0<R> norm_r2(Mv2<R> const& x) {

return Mv0<R>(pow(x[0], 2));
}

template <class R>
Mv0<R> norm_r2(Mv02<R> const& x) {

return Mv0<R>((pow(x[0], 2) + pow(x[1], 2)));
}

// add
template <class R>
Mv0<R> operator+(Mv0<R> const& x, Mv0<R> const& y) {
Expand Down Expand Up @@ -814,6 +876,12 @@ Mv0<R> operator-(Mv0<R> const& x, Mv0<R> const& y) {
return Mv0<R>(((-y[0]) + x[0]));
}

template <class R>
void operator-=(Mv0<R> & x, Mv0<R> const& y) {

x = x - y;
}

template <class R>
Mv02<R> operator-(Mv0<R> const& x, Mv2<R> const& y) {

Expand All @@ -833,6 +901,12 @@ Mv1<R> operator-(Mv1<R> const& x, Mv1<R> const& y) {
return Mv1<R>(((-y[0]) + x[0]), (x[1] + (-y[1])));
}

template <class R>
void operator-=(Mv1<R> & x, Mv1<R> const& y) {

x = x - y;
}

template <class R>
Mv02<R> operator-(Mv2<R> const& x, Mv0<R> const& y) {

Expand All @@ -846,6 +920,12 @@ Mv2<R> operator-(Mv2<R> const& x, Mv2<R> const& y) {
return Mv2<R>(((-y[0]) + x[0]));
}

template <class R>
void operator-=(Mv2<R> & x, Mv2<R> const& y) {

x = x - y;
}

template <class R>
Mv02<R> operator-(Mv2<R> const& x, Mv02<R> const& y) {

Expand All @@ -858,19 +938,37 @@ Mv02<R> operator-(Mv02<R> const& x, Mv0<R> const& y) {
return Mv02<R>(((-y[0]) + x[0]), x[1]);
}

template <class R>
void operator-=(Mv02<R> & x, Mv0<R> const& y) {

x = x - y;
}

template <class R>
Mv02<R> operator-(Mv02<R> const& x, Mv2<R> const& y) {

return Mv02<R>(x[0], ((-y[0]) + x[1]));
}

template <class R>
void operator-=(Mv02<R> & x, Mv2<R> const& y) {

x = x - y;
}

template <class R>
Mv02<R> operator-(Mv02<R> const& x, Mv02<R> const& y) {
assert(&x != &y);

return Mv02<R>(((-y[0]) + x[0]), (x[1] + (-y[1])));
}

template <class R>
void operator-=(Mv02<R> & x, Mv02<R> const& y) {

x = x - y;
}

// rotated
template <class R>
Mv1<R> rotated(Mv1<R> const& x, Mv02<R> const& y) {
Expand Down
Loading

0 comments on commit 8047f79

Please sign in to comment.