src/utilities/geometry/StandardShapes.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 "StandardShapes.hpp" | ||
| 7 | |||
| 8 | #include "Point3d.hpp" | ||
| 9 | #include "Vector3d.hpp" | ||
| 10 | |||
| 11 | #include <boost/math/constants/constants.hpp> | ||
| 12 | |||
| 13 | #include <cmath> | ||
| 14 | #include <stdexcept> | ||
| 15 | #include <vector> | ||
| 16 | |||
| 17 | // GCC <10 doesn't have numbers.. | ||
| 18 | // #include <numbers> / PI | ||
| 19 | // static constexpr double PI = td::numbers::pi; | ||
| 20 | static constexpr double PI = boost::math::constants::pi<double>(); | ||
| 21 | |||
| 22 | namespace openstudio { | ||
| 23 | |||
| 24 | 26 | std::vector<Point3d> convexRegularPolygon(const Point3d& center, size_t num_sides, double side_with) { | |
| 25 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (num_sides < 3) { |
| 26 | ✗ | throw std::runtime_error("Polygon must have at least three sides."); | |
| 27 | } | ||
| 28 | |||
| 29 | 26 | std::vector<Point3d> points; | |
| 30 |
1/1✓ Branch 1 taken 26 times.
|
26 | points.reserve(num_sides); |
| 31 | 26 | const double angle = 2.0 * PI / num_sides; | |
| 32 | |||
| 33 |
2/2✓ Branch 0 taken 235 times.
✓ Branch 1 taken 26 times.
|
261 | for (size_t i = 0; i < num_sides; i++) { |
| 34 |
1/1✓ Branch 1 taken 235 times.
|
235 | double x = center.x() + side_with * std::cos(angle * i); |
| 35 |
1/1✓ Branch 1 taken 235 times.
|
235 | double y = center.y() + side_with * std::sin(angle * i); |
| 36 |
1/1✓ Branch 1 taken 235 times.
|
235 | double z = center.z(); |
| 37 |
1/1✓ Branch 1 taken 235 times.
|
235 | points.emplace_back(x, y, z); |
| 38 | } | ||
| 39 | |||
| 40 | 26 | return points; | |
| 41 | ✗ | } | |
| 42 | |||
| 43 | 3 | std::vector<Point3d> hShapedPolygon(const Point3d& center, double total_length) { | |
| 44 | |||
| 45 | // ▲ | ||
| 46 | // │(1) (9) | ||
| 47 | // L o───┐ o───┐ ▲ | ||
| 48 | // │ │ │ │ │ l2 | ||
| 49 | // │ └───┘ │ │ | ||
| 50 | // │ x (5)│ ▼ | ||
| 51 | // │ ┌───o │ | ||
| 52 | // │(2)│ │ │ | ||
| 53 | // o───┴───┴───┴──► | ||
| 54 | // ◄──► L | ||
| 55 | // l3 | ||
| 56 | |||
| 57 | 3 | const double l2 = total_length / 2.0; | |
| 58 | 3 | const double l6 = total_length / 6.0; | |
| 59 | |||
| 60 | 3 | const double x = center.x(); | |
| 61 | 3 | const double y = center.y(); | |
| 62 | 3 | const double z = center.z(); | |
| 63 | |||
| 64 | // Counter clockwise order | ||
| 65 | return { | ||
| 66 | {x - l2, y + l2, z}, // Point 1 - Upper Left Corner | ||
| 67 | {x - l2, y - l2, z}, // Point 2 | ||
| 68 | {x - l6, y - l2, z}, // | ||
| 69 | {x - l6, y - l6, z}, // | ||
| 70 | {x + l6, y - l6, z}, // Point 5 | ||
| 71 | {x + l6, y - l2, z}, // | ||
| 72 | {x + l2, y - l2, z}, // | ||
| 73 | {x + l2, y + l2, z}, // | ||
| 74 | {x + l6, y + l2, z}, // Point 9 | ||
| 75 | {x + l6, y + l6, z}, // | ||
| 76 | {x - l6, y + l6, z}, // | ||
| 77 | {x - l6, y + l2, z}, // | ||
| 78 |
3/5✓ Branch 1 taken 3 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
42 | }; |
| 79 | 3 | } | |
| 80 | |||
| 81 | 1 | std::vector<Point3d> uShapedPolygon(const Point3d& center, double total_length) { | |
| 82 | |||
| 83 | // ▲ | ||
| 84 | // │(1) (5) | ||
| 85 | // L o───┐ o───┐ ▲ | ||
| 86 | // │ │ │ │ │ l2 | ||
| 87 | // │ └───┘ │ │ | ||
| 88 | // │ x │ ▼ | ||
| 89 | // │ │ | ||
| 90 | // │(2) │ | ||
| 91 | // o───────────┴──► | ||
| 92 | // ◄──► L | ||
| 93 | // l3 | ||
| 94 | |||
| 95 | 1 | const double l2 = total_length / 2.0; | |
| 96 | 1 | const double l6 = total_length / 6.0; | |
| 97 | |||
| 98 | 1 | const double x = center.x(); | |
| 99 | 1 | const double y = center.y(); | |
| 100 | 1 | const double z = center.z(); | |
| 101 | |||
| 102 | // Counter clockwise order | ||
| 103 | return { | ||
| 104 | {x - l2, y + l2, z}, // Point 1 - Upper Left Corner | ||
| 105 | {x - l2, y - l2, z}, // Point 2 | ||
| 106 | {x + l2, y - l2, z}, // | ||
| 107 | {x + l2, y + l2, z}, // | ||
| 108 | {x + l6, y + l2, z}, // Point 5 | ||
| 109 | {x + l6, y + l6, z}, // | ||
| 110 | {x - l6, y + l6, z}, // | ||
| 111 | {x - l6, y + l2, z}, // | ||
| 112 |
3/5✓ Branch 1 taken 1 time.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
10 | }; |
| 113 | 1 | } | |
| 114 | |||
| 115 | 2 | std::vector<Point3d> tShapedPolygon(const Point3d& center, double total_length) { | |
| 116 | |||
| 117 | // ▲ | ||
| 118 | // │(1) | ||
| 119 | // L o───────────┐ ▲ | ||
| 120 | // │ (2) │ │ l2 | ||
| 121 | // o───┐ ┌───┘ │ | ||
| 122 | // │ │ x │ ▼ | ||
| 123 | // │ │ │ | ||
| 124 | // │ │ │ (5) | ||
| 125 | // └───┴───o───────► | ||
| 126 | // ◄──► L | ||
| 127 | // l3 | ||
| 128 | |||
| 129 | 2 | const double l2 = total_length / 2.0; | |
| 130 | 2 | const double l6 = total_length / 6.0; | |
| 131 | |||
| 132 | 2 | const double x = center.x(); | |
| 133 | 2 | const double y = center.y(); | |
| 134 | 2 | const double z = center.z(); | |
| 135 | |||
| 136 | // Counter clockwise order | ||
| 137 | return { | ||
| 138 | {x - l2, y + l2, z}, // Point 1 - Upper Left Corner | ||
| 139 | {x - l2, y + l6, z}, // Point 2 | ||
| 140 | {x - l6, y + l6, z}, // | ||
| 141 | {x - l6, y - l2, z}, // | ||
| 142 | {x + l6, y - l2, z}, // Point 5 | ||
| 143 | {x + l6, y + l6, z}, // | ||
| 144 | {x + l2, y + l6, z}, // | ||
| 145 | {x + l2, y + l2, z}, // | ||
| 146 |
3/5✓ Branch 1 taken 2 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 2 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
20 | }; |
| 147 | 2 | } | |
| 148 | |||
| 149 | 2 | std::vector<Point3d> lShapedPolygon(const Point3d& center, double total_length) { | |
| 150 | // ▲ | ||
| 151 | // │(1) | ||
| 152 | // L o─────┐ ▲ | ||
| 153 | // │ │ │ | ||
| 154 | // │ │ (5) │ l2 | ||
| 155 | // │ x─────┐ ▼ | ||
| 156 | // │ │ | ||
| 157 | // │ │ | ||
| 158 | // o───────────┴──► | ||
| 159 | // L | ||
| 160 | |||
| 161 | 2 | const double l2 = total_length / 2.0; | |
| 162 | |||
| 163 | 2 | const double x = center.x(); | |
| 164 | 2 | const double y = center.y(); | |
| 165 | 2 | const double z = center.z(); | |
| 166 | |||
| 167 | // Counter clockwise order | ||
| 168 | return { | ||
| 169 | {x - l2, y + l2, z}, // Point 1 - Upper Left Corner | ||
| 170 | {x - l2, y - l2, z}, // Point 2 | ||
| 171 | {x + l2, y - l2, z}, // | ||
| 172 | {x + l2, y, z}, // | ||
| 173 | {x, y, z}, // Point 5 | ||
| 174 | {x, y + l2, z}, // | ||
| 175 |
3/5✓ Branch 1 taken 2 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 2 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
16 | }; |
| 176 | 2 | } | |
| 177 | |||
| 178 | 3 | std::vector<Point3d> squaredPolygon(const Point3d& center, double side_with) { | |
| 179 | |||
| 180 | // ▲ | ||
| 181 | // │(1) | ||
| 182 | // L o───────────┐ ▲ | ||
| 183 | // │ │ l2 | ||
| 184 | // │ │ │ | ||
| 185 | // │ x │ ▼ | ||
| 186 | // │ │ | ||
| 187 | // │(2) │ | ||
| 188 | // o───────────┴──► | ||
| 189 | // L | ||
| 190 | |||
| 191 | 3 | const double l2 = side_with / 2.0; | |
| 192 | |||
| 193 | 3 | const double x = center.x(); | |
| 194 | 3 | const double y = center.y(); | |
| 195 | 3 | const double z = center.z(); | |
| 196 | |||
| 197 | // Counter clockwise order | ||
| 198 | return { | ||
| 199 | {x - l2, y + l2, z}, // Point 1 - Upper Left Corner | ||
| 200 | {x - l2, y - l2, z}, // Point 2 | ||
| 201 | {x + l2, y - l2, z}, // | ||
| 202 | {x + l2, y + l2, z}, // | ||
| 203 |
3/5✓ Branch 1 taken 3 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
18 | }; |
| 204 | 3 | } | |
| 205 | |||
| 206 | 1 | std::vector<Point3d> rectangularPolygon(const Point3d& center, double length_x, double length_y) { | |
| 207 | |||
| 208 | // ▲ | ||
| 209 | // │(1) | ||
| 210 | //L_yo───────────┐ ▲ | ||
| 211 | // │ │ ly2 | ||
| 212 | // │ │ │ | ||
| 213 | // │ x │ ▼ | ||
| 214 | // │ │ | ||
| 215 | // │(2) │ | ||
| 216 | // o───────────┴──► | ||
| 217 | // L_x | ||
| 218 | |||
| 219 | 1 | const double lx2 = length_x / 2.0; | |
| 220 | 1 | const double ly2 = length_y / 2.0; | |
| 221 | |||
| 222 | 1 | const double x = center.x(); | |
| 223 | 1 | const double y = center.y(); | |
| 224 | 1 | const double z = center.z(); | |
| 225 | |||
| 226 | // Counter clockwise order | ||
| 227 | return { | ||
| 228 | {x - lx2, y + ly2, z}, // Point 1 - Upper Left Corner | ||
| 229 | {x - lx2, y - ly2, z}, // Point 2 | ||
| 230 | {x + lx2, y - ly2, z}, // | ||
| 231 | {x + lx2, y + ly2, z}, // | ||
| 232 |
3/5✓ Branch 1 taken 1 time.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
6 | }; |
| 233 | 1 | } | |
| 234 | |||
| 235 | } // namespace openstudio | ||
| 236 |