Flow123d  last_with_con_2.0.0-4-g42e6930
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 
27 
29  return TPoint::numberInstance++;
30 }
31 
33  x = 0;
34  y = 0;
35  z = 0;
36 
37  id = generateId();
38 }
39 
40 TPoint::TPoint(double x, double y, double z) {
41  this->x = x;
42  this->y = y;
43  this->z = z;
44 
45  id = generateId();
46 }
47 
49  x = point.X();
50  y = point.Y();
51  z = point.Z();
52 
53  id = generateId();
54 }
55 
57 }
58 
60  x = P.x;
61  y = P.y;
62  z = P.z;
63 
64  return *this;
65 }
66 
67 bool TPoint::operator ==(const TPoint& P) const {
68  if (IsEqual(x, P.x) && IsEqual(y, P.y) && IsEqual(z, P.z)) {
69  return true;
70  }
71  return false;
72 }
73 
75  x = U.X1();
76  y = U.X2();
77  z = U.X3();
78 
79  return *this;
80 }
81 
83  return TVector( x - P.x, y - P.y, z - P.z);
84 }
85 
86 TPoint TPoint::operator +(const TPoint& P) const {
87  TPoint res;
88 
89  res.x = x + P.x;
90  res.y = y + P.y;
91  res.z = z + P.z;
92 
93  return res;
94 }
95 
96 void TPoint::SetCoord(double x, double y, double z) {
97  this->x = x;
98  this->y = y;
99  this->z = z;
100 }
101 
102 void TPoint::SetCoord(const TVector& U) {
103  x = U.X1();
104  y = U.X2();
105  z = U.X3();
106 }
107 
108 double TPoint::X() const {
109  return x;
110 }
111 
112 double TPoint::Y() const {
113  return y;
114 }
115 
116 double TPoint::Z() const {
117  return z;
118 }
119 
120 double TPoint::Get(int i) const {
121  if (!(i >= 1 && i <= 3)) {
122  THROW( ExcAssertMsg() << EI_Message( "Invalid specification of the element of the vector.") );
123  }
124 
125  switch (i) {
126  case 1: return x;
127  case 2: return y;
128  case 3: return z;
129  }
130 
131  return 0.0;
132 }
133 
134 std::ostream & operator <<(std::ostream& stream, const TPoint& P) {
135  stream << "[" << P.x << " " << P.y << " " << P.z << "]";
136  return stream;
137 }
double y
Definition: point.h:33
double X2() const
Definition: vector.cpp:222
TPoint * operator+(TPoint *)
double X1() const
Definition: vector.cpp:218
TPoint * operator=(TPoint *)
double X3() const
Definition: vector.cpp:226
double X() const
Definition: point.cpp:108
Definition: point.h:27
int generateId()
Definition: point.cpp:28
double Y() const
Definition: point.cpp:112
void SetCoord(double, double, double)
Definition: point.cpp:96
TVector operator-(const TPoint &) const
Definition: point.cpp:82
std::ostream & operator<<(std::ostream &stream, const TPoint &P)
Definition: point.cpp:134
double Z() const
Definition: point.cpp:116
double x
Definition: point.h:32
bool operator==(TPoint *)
TPoint()
Definition: point.cpp:32
double Get(int) const
Definition: point.cpp:120
static int numberInstance
Definition: point.h:29
double z
Definition: point.h:34
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:45
bool IsEqual(double, double)
Definition: mathfce.cpp:29
~TPoint()
Definition: point.cpp:56