Flow123d  release_2.2.0-914-gf1a3a4f
point.cpp
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file point.cpp
15  * @brief
16  */
17 
18 #include <iostream>
19 
20 #include "system/exc_common.hh"
21 #include "mesh/ngh/include/point.h"
23 
24 using namespace mathfce;
25 
26 namespace ngh {
27 
28 
29 int TPoint::numberInstance = 0;
30 
31 int TPoint::generateId() {
32  return TPoint::numberInstance++;
33 }
34 
35 TPoint::TPoint() {
36  x = 0;
37  y = 0;
38  z = 0;
39 
40  id = generateId();
41 }
42 
43 TPoint::TPoint(double x, double y, double z) {
44  this->x = x;
45  this->y = y;
46  this->z = z;
47 
48  id = generateId();
49 }
50 
51 TPoint::TPoint(const TPoint& point) {
52  x = point.X();
53  y = point.Y();
54  z = point.Z();
55 
56  id = generateId();
57 }
58 
59 TPoint::~TPoint() {
60 }
61 
62 TPoint& TPoint::operator =(const TPoint& P) {
63  x = P.x;
64  y = P.y;
65  z = P.z;
66 
67  return *this;
68 }
69 
70 bool TPoint::operator ==(const TPoint& P) const {
71  if (IsEqual(x, P.x) && IsEqual(y, P.y) && IsEqual(z, P.z)) {
72  return true;
73  }
74  return false;
75 }
76 
77 TPoint& TPoint::operator =(const TVector& U) {
78  x = U.X1();
79  y = U.X2();
80  z = U.X3();
81 
82  return *this;
83 }
84 
85 TVector TPoint::operator -(const TPoint& P) const {
86  return TVector( x - P.x, y - P.y, z - P.z);
87 }
88 
89 TPoint TPoint::operator +(const TPoint& P) const {
90  TPoint res;
91 
92  res.x = x + P.x;
93  res.y = y + P.y;
94  res.z = z + P.z;
95 
96  return res;
97 }
98 
99 void TPoint::SetCoord(double x, double y, double z) {
100  this->x = x;
101  this->y = y;
102  this->z = z;
103 }
104 
105 void TPoint::SetCoord(const TVector& U) {
106  x = U.X1();
107  y = U.X2();
108  z = U.X3();
109 }
110 
111 double TPoint::X() const {
112  return x;
113 }
114 
115 double TPoint::Y() const {
116  return y;
117 }
118 
119 double TPoint::Z() const {
120  return z;
121 }
122 
123 double TPoint::Get(int i) const {
124  if (!(i >= 1 && i <= 3)) {
125  THROW( ExcAssertMsg() << EI_Message( "Invalid specification of the element of the vector.") );
126  }
127 
128  switch (i) {
129  case 1: return x;
130  case 2: return y;
131  case 3: return z;
132  }
133 
134  return 0.0;
135 }
136 
137 std::ostream & operator <<(std::ostream& stream, const TPoint& P) {
138  stream << "[" << P.x << " " << P.y << " " << P.z << "]";
139  return stream;
140 }
141 
142 } //namespace ngh
Definition: abscissa.h:25
double z
Definition: point.h:36
double y
Definition: point.h:35
double Y() const
Definition: point.cpp:115
std::ostream & operator<<(std::ostream &stream, const TPoint &P)
Definition: point.cpp:137
double X2() const
Definition: vector.cpp:224
bool operator==(const Null &, const Null &)
double x
Definition: point.h:34
double X3() const
Definition: vector.cpp:228
double X() const
Definition: point.cpp:111
double Z() const
Definition: point.cpp:119
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
bool IsEqual(double, double)
Definition: mathfce.cpp:29
double X1() const
Definition: vector.cpp:220