src/utilities/geometry/Point3d.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "Point3d.hpp" | ||
| 7 | #include "Vector3d.hpp" | ||
| 8 | |||
| 9 | namespace openstudio { | ||
| 10 | |||
| 11 | /// default constructor creates point at 0, 0, 0 | ||
| 12 |
1/1✓ Branch 1 taken 5009878 times.
|
5009878 | Point3d::Point3d() : m_storage(3, 0.0) {} |
| 13 | |||
| 14 | /// constructor with x, y, z | ||
| 15 | 11782831 | Point3d::Point3d(double x, double y, double z) : m_storage(3) { | |
| 16 |
1/1✓ Branch 1 taken 11782831 times.
|
11782831 | m_storage[0] = x; |
| 17 |
1/1✓ Branch 1 taken 11782831 times.
|
11782831 | m_storage[1] = y; |
| 18 |
1/1✓ Branch 1 taken 11782831 times.
|
11782831 | m_storage[2] = z; |
| 19 | 11782831 | } | |
| 20 | |||
| 21 | /// get x | ||
| 22 | 64089447 | double Point3d::x() const { | |
| 23 | 64089447 | return m_storage[0]; | |
| 24 | } | ||
| 25 | |||
| 26 | /// get y | ||
| 27 | 60113516 | double Point3d::y() const { | |
| 28 | 60113516 | return m_storage[1]; | |
| 29 | } | ||
| 30 | |||
| 31 | /// get z | ||
| 32 | 59218212 | double Point3d::z() const { | |
| 33 | 59218212 | return m_storage[2]; | |
| 34 | } | ||
| 35 | |||
| 36 | /// point plus a vector is a new point | ||
| 37 | 1235986 | Point3d Point3d::operator+(const Vector3d& vec) const { | |
| 38 | 1235986 | double newX = x() + vec.x(); | |
| 39 | 1235986 | double newY = y() + vec.y(); | |
| 40 | 1235986 | double newZ = z() + vec.z(); | |
| 41 | 1235986 | return {newX, newY, newZ}; | |
| 42 | } | ||
| 43 | |||
| 44 | /// point plus a vector is a new point | ||
| 45 | 535 | Point3d& Point3d::operator+=(const Vector3d& vec) { | |
| 46 | 535 | m_storage[0] += vec.x(); | |
| 47 | 535 | m_storage[1] += vec.y(); | |
| 48 | 535 | m_storage[2] += vec.z(); | |
| 49 | 535 | return *this; | |
| 50 | } | ||
| 51 | |||
| 52 | /// point minus another point is a vector | ||
| 53 | 15208718 | Vector3d Point3d::operator-(const Point3d& other) const { | |
| 54 | 15208718 | double newX = x() - other.x(); | |
| 55 | 15208718 | double newY = y() - other.y(); | |
| 56 | 15208718 | double newZ = z() - other.z(); | |
| 57 | 15208718 | return {newX, newY, newZ}; | |
| 58 | } | ||
| 59 | |||
| 60 | /// check equality | ||
| 61 | 85860 | bool Point3d::operator==(const Point3d& other) const { | |
| 62 | 85860 | return (m_storage == other.m_storage); | |
| 63 | } | ||
| 64 | |||
| 65 | /// check inequality | ||
| 66 | 308 | bool Point3d::operator!=(const Point3d& other) const { | |
| 67 | 308 | return (m_storage != other.m_storage); | |
| 68 | } | ||
| 69 | |||
| 70 | /// ostream operator | ||
| 71 | 4287 | std::ostream& operator<<(std::ostream& os, const Point3d& point) { | |
| 72 | 4287 | os << "[" << point.x() << ", " << point.y() << ", " << point.z() << "]"; | |
| 73 | 4287 | return os; | |
| 74 | } | ||
| 75 | |||
| 76 | /// ostream operator | ||
| 77 | 72 | std::ostream& operator<<(std::ostream& os, const std::vector<Point3d>& pointVector) { | |
| 78 | 72 | os << "["; | |
| 79 |
2/2✓ Branch 1 taken 395 times.
✓ Branch 2 taken 72 times.
|
467 | for (unsigned i = 0; i < pointVector.size(); ++i) { |
| 80 | 395 | os << pointVector[i]; | |
| 81 |
2/2✓ Branch 1 taken 347 times.
✓ Branch 2 taken 48 times.
|
395 | if (i < pointVector.size() - 1) { |
| 82 | 347 | os << ", "; | |
| 83 | } | ||
| 84 | } | ||
| 85 | 72 | os << "]"; | |
| 86 | 72 | return os; | |
| 87 | } | ||
| 88 | |||
| 89 | // Writes a json string representing the vector of point vectors | ||
| 90 | // Will deserialize in to a simple class that defines three double properties for X,Y,Z | ||
| 91 | 2 | std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<Point3d>>& pointVectorVector) { | |
| 92 | 2 | os << "[\n"; | |
| 93 |
2/2✓ Branch 5 taken 5 times.
✓ Branch 6 taken 2 times.
|
7 | for (const auto& points : pointVectorVector) { |
| 94 |
1/1✓ Branch 1 taken 5 times.
|
5 | os << " ["; |
| 95 |
2/2✓ Branch 5 taken 23 times.
✓ Branch 6 taken 5 times.
|
28 | for (const auto& point : points) { |
| 96 |
3/3✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
✓ Branch 7 taken 23 times.
|
23 | os << "\n " << point << ", "; |
| 97 | } | ||
| 98 |
1/1✓ Branch 1 taken 5 times.
|
5 | os << "\n ],\n"; |
| 99 | } | ||
| 100 | 2 | os << "]"; | |
| 101 | |||
| 102 | 2 | return os; | |
| 103 | } | ||
| 104 | |||
| 105 | } // namespace openstudio | ||
| 106 |