| 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 |
|
|---|
| 16 | using namespace VMG;
|
|---|
| 17 |
|
|---|
| 18 | Index::Index(const Vector& vec)
|
|---|
| 19 | {
|
|---|
| 20 | i[0] = static_cast<int>(vec.X());
|
|---|
| 21 | i[1] = static_cast<int>(vec.Y());
|
|---|
| 22 | i[2] = static_cast<int>(vec.Z());
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | Index::Index(const Stencil::iterator& iter)
|
|---|
| 26 | {
|
|---|
| 27 | i[0] = iter->m;
|
|---|
| 28 | i[1] = iter->n;
|
|---|
| 29 | i[2] = iter->o;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | const Vector Index::operator+(const Vector& rhs) const
|
|---|
| 33 | {
|
|---|
| 34 | return Vector(*this) += rhs;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | const Vector Index::operator-(const Vector& rhs) const
|
|---|
| 38 | {
|
|---|
| 39 | return Vector(*this) -= rhs;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | const Vector Index::operator*(const Vector& rhs) const
|
|---|
| 43 | {
|
|---|
| 44 | return Vector(*this) *= rhs;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | const Vector Index::operator/(const Vector& rhs) const
|
|---|
| 48 | {
|
|---|
| 49 | return Vector(*this) /= rhs;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | const Vector Index::operator+(const vmg_float& rhs) const
|
|---|
| 53 | {
|
|---|
| 54 | return Vector(*this) += rhs;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | const Vector Index::operator-(const vmg_float& rhs) const
|
|---|
| 58 | {
|
|---|
| 59 | return Vector(*this) -= rhs;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | const Vector Index::operator*(const vmg_float& rhs) const
|
|---|
| 63 | {
|
|---|
| 64 | return Vector(*this) *= rhs;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | const Vector Index::operator/(const vmg_float& rhs) const
|
|---|
| 68 | {
|
|---|
| 69 | return Vector(*this) /= rhs;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | bool operator<(const Index& lhs, const Index& rhs)
|
|---|
| 73 | {
|
|---|
| 74 | if (lhs.X() < rhs.X())
|
|---|
| 75 | return true;
|
|---|
| 76 | else if (lhs.X() > rhs.X())
|
|---|
| 77 | return false;
|
|---|
| 78 |
|
|---|
| 79 | if (lhs.Y() < rhs.Y())
|
|---|
| 80 | return true;
|
|---|
| 81 | else if (lhs.Y() > rhs.Y())
|
|---|
| 82 | return false;
|
|---|
| 83 |
|
|---|
| 84 | if (lhs.Z() < rhs.Z())
|
|---|
| 85 | return true;
|
|---|
| 86 | else
|
|---|
| 87 | return false;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | const Index Max(const Index& index1, const Index& index2)
|
|---|
| 91 | {
|
|---|
| 92 | return Index(std::max(index1.X(), index2.X()), std::max(index1.Y(), index2.Y()), std::max(index1.Z(), index2.Z()));
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | std::ostream& operator<<(std::ostream& out, const Index& base)
|
|---|
| 96 | {
|
|---|
| 97 | return out << "{" << base.X() << " " << base.Y() << " " << base.Z() << "}";
|
|---|
| 98 | }
|
|---|