source: src/base/index.cpp@ 01be70

Last change on this file since 01be70 was dfed1c, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Major vmg update.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1136 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 1.8 KB
Line 
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
16using VMG::Index;
17using VMG::Vector;
18
19Index::Index(const Index& rhs)
20{
21 std::memcpy(this->i, rhs.i, 3*sizeof(int));
22}
23
24Index::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
31Vector Index::operator+(const Vector& rhs) const
32{
33 return Vector(*this) += rhs;
34}
35
36Vector Index::operator-(const Vector& rhs) const
37{
38 return Vector(*this) -= rhs;
39}
40
41Vector Index::operator*(const Vector& rhs) const
42{
43 return Vector(*this) *= rhs;
44}
45
46Vector Index::operator/(const Vector& rhs) const
47{
48 return Vector(*this) /= rhs;
49}
50
51Vector Index::operator+(const vmg_float& rhs) const
52{
53 return Vector(*this) += rhs;
54}
55
56Vector Index::operator-(const vmg_float& rhs) const
57{
58 return Vector(*this) -= rhs;
59}
60
61Vector Index::operator*(const vmg_float& rhs) const
62{
63 return Vector(*this) *= rhs;
64}
65
66Vector Index::operator/(const vmg_float& rhs) const
67{
68 return Vector(*this) /= rhs;
69}
70
71bool 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
89const 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
94std::ostream& VMG::operator<<(std::ostream& out, const Index& index)
95{
96 out << "{" << index.X() << " " << index.Y() << " " << index.Z() << "}";
97
98 return out;
99}
Note: See TracBrowser for help on using the repository browser.