| [48b662] | 1 | /**
|
|---|
| 2 | * @file index.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 12:19:16 2011
|
|---|
| 5 | *
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifdef HAVE_CONFIG_H
|
|---|
| 9 | #include <config.h>
|
|---|
| 10 | #endif
|
|---|
| 11 |
|
|---|
| 12 | #include "base/index.hpp"
|
|---|
| 13 | #include "base/stencil.hpp"
|
|---|
| 14 | #include "base/vector.hpp"
|
|---|
| 15 |
|
|---|
| [dfed1c] | 16 | using VMG::Index;
|
|---|
| 17 | using VMG::Vector;
|
|---|
| 18 |
|
|---|
| 19 | Index::Index(const Index& rhs)
|
|---|
| 20 | {
|
|---|
| 21 | std::memcpy(this->i, rhs.i, 3*sizeof(int));
|
|---|
| 22 | }
|
|---|
| [48b662] | 23 |
|
|---|
| 24 | Index::Index(const Vector& vec)
|
|---|
| 25 | {
|
|---|
| 26 | i[0] = static_cast<int>(vec.X());
|
|---|
| 27 | i[1] = static_cast<int>(vec.Y());
|
|---|
| 28 | i[2] = static_cast<int>(vec.Z());
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| [dfed1c] | 31 | Vector Index::operator+(const Vector& rhs) const
|
|---|
| [48b662] | 32 | {
|
|---|
| 33 | return Vector(*this) += rhs;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| [dfed1c] | 36 | Vector Index::operator-(const Vector& rhs) const
|
|---|
| [48b662] | 37 | {
|
|---|
| 38 | return Vector(*this) -= rhs;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| [dfed1c] | 41 | Vector Index::operator*(const Vector& rhs) const
|
|---|
| [48b662] | 42 | {
|
|---|
| 43 | return Vector(*this) *= rhs;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| [dfed1c] | 46 | Vector Index::operator/(const Vector& rhs) const
|
|---|
| [48b662] | 47 | {
|
|---|
| 48 | return Vector(*this) /= rhs;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| [dfed1c] | 51 | Vector Index::operator+(const vmg_float& rhs) const
|
|---|
| [48b662] | 52 | {
|
|---|
| 53 | return Vector(*this) += rhs;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| [dfed1c] | 56 | Vector Index::operator-(const vmg_float& rhs) const
|
|---|
| [48b662] | 57 | {
|
|---|
| 58 | return Vector(*this) -= rhs;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| [dfed1c] | 61 | Vector Index::operator*(const vmg_float& rhs) const
|
|---|
| [48b662] | 62 | {
|
|---|
| 63 | return Vector(*this) *= rhs;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| [dfed1c] | 66 | Vector Index::operator/(const vmg_float& rhs) const
|
|---|
| [48b662] | 67 | {
|
|---|
| 68 | return Vector(*this) /= rhs;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | bool operator<(const Index& lhs, const Index& rhs)
|
|---|
| 72 | {
|
|---|
| 73 | if (lhs.X() < rhs.X())
|
|---|
| 74 | return true;
|
|---|
| 75 | else if (lhs.X() > rhs.X())
|
|---|
| 76 | return false;
|
|---|
| 77 |
|
|---|
| 78 | if (lhs.Y() < rhs.Y())
|
|---|
| 79 | return true;
|
|---|
| 80 | else if (lhs.Y() > rhs.Y())
|
|---|
| 81 | return false;
|
|---|
| 82 |
|
|---|
| 83 | if (lhs.Z() < rhs.Z())
|
|---|
| 84 | return true;
|
|---|
| 85 | else
|
|---|
| 86 | return false;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | const Index Max(const Index& index1, const Index& index2)
|
|---|
| 90 | {
|
|---|
| 91 | return Index(std::max(index1.X(), index2.X()), std::max(index1.Y(), index2.Y()), std::max(index1.Z(), index2.Z()));
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| [dfed1c] | 94 | std::ostream& VMG::operator<<(std::ostream& out, const Index& index)
|
|---|
| [48b662] | 95 | {
|
|---|
| [dfed1c] | 96 | out << "{" << index.X() << " " << index.Y() << " " << index.Z() << "}";
|
|---|
| 97 |
|
|---|
| 98 | return out;
|
|---|
| [48b662] | 99 | }
|
|---|