GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 89.8% 466 / 0 / 519
Functions: 100.0% 22 / 0 / 22
Branches: 78.0% 440 / 0 / 564

src/utilities/geometry/Geometry.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 "Geometry.hpp"
7 #include "Intersection.hpp"
8 #include "Transformation.hpp"
9 #include "Vector3d.hpp"
10
11 #include "../core/Assert.hpp"
12
13 #include <boost/math/constants/constants.hpp>
14
15 #include <polypartition/polypartition.h>
16
17 #include <cmath>
18
19 namespace openstudio {
20 /// convert degrees to radians
21 12041 double degToRad(double degrees) {
22 12041 return degrees * boost::math::constants::pi<double>() / 180.0;
23 }
24
25 /// convert radians to degrees
26 65705 double radToDeg(double radians) {
27 65705 return radians * 180.0 / boost::math::constants::pi<double>();
28 }
29
30 /// compute area from surface as Point3dVector
31 1406072 boost::optional<double> getArea(const Point3dVector& points) {
32 1406072 boost::optional<double> result;
33
1/1
✓ Branch 1 taken 1406072 times.
1406072 OptionalVector3d newell = getNewellVector(points);
34
1/2
✓ Branch 0 taken 1406072 times.
✗ Branch 1 not taken.
1406072 if (newell) {
35
3/3
✓ Branch 1 taken 1406072 times.
✓ Branch 4 taken 1406072 times.
✓ Branch 7 taken 1406072 times.
1406072 result = newell->length() / 2.0;
36 }
37 1406072 return result;
38 1406072 }
39
40 // compute Newell vector from Point3dVector, direction is same as outward normal
41 // magnitude is twice the area
42 2345639 OptionalVector3d getNewellVector(const Point3dVector& points) {
43 2345639 OptionalVector3d result;
44 2345639 const size_t N = points.size();
45
1/2
✓ Branch 0 taken 2345639 times.
✗ Branch 1 not taken.
2345639 if (N >= 3) {
46
1/1
✓ Branch 1 taken 2345639 times.
2345639 Vector3d vec;
47
2/2
✓ Branch 0 taken 6268884 times.
✓ Branch 1 taken 2345639 times.
8614523 for (unsigned i = 1; i < N - 1; ++i) {
48
1/1
✓ Branch 3 taken 6268884 times.
6268884 const Vector3d v1 = points[i] - points[0];
49
1/1
✓ Branch 3 taken 6268884 times.
6268884 const Vector3d v2 = points[i + 1] - points[0];
50
2/2
✓ Branch 1 taken 6268884 times.
✓ Branch 4 taken 6268884 times.
6268884 vec += v1.cross(v2);
51 6268884 }
52
1/1
✓ Branch 1 taken 2345639 times.
2345639 result = vec;
53 2345639 }
54 2345639 return result;
55 ✗ }
56
57 // compute outward normal from Point3dVector
58 933631 OptionalVector3d getOutwardNormal(const Point3dVector& points) {
59 933631 OptionalVector3d result = getNewellVector(points);
60
1/2
✓ Branch 0 taken 933631 times.
✗ Branch 1 not taken.
933631 if (result) {
61
4/4
✓ Branch 1 taken 933631 times.
✓ Branch 4 taken 933631 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 933625 times.
933631 if (!result->normalize()) {
62 6 result.reset();
63 }
64 }
65 933631 return result;
66 ✗ }
67
68 /// compute centroid from surface as Point3dVector
69 112 OptionalPoint3d getCentroid(const Point3dVector& points) {
70 112 OptionalPoint3d result;
71
72
2/2
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 1 time.
112 if (points.size() >= 3) {
73 // convert to face coordinates
74
1/1
✓ Branch 1 taken 111 times.
111 const Transformation alignFace = Transformation::alignFace(points);
75
2/2
✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
111 Point3dVector surfacePoints = alignFace.inverse() * points;
76
77 111 const size_t N = surfacePoints.size();
78 111 double A = 0;
79 111 double cx = 0;
80 111 double cy = 0;
81
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 111 times.
571 for (size_t i = 0; i < N; ++i) {
82 460 double x1 = 0.0;
83 460 double x2 = 0.0;
84 460 double y1 = 0.0;
85 460 double y2 = 0.0;
86
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 349 times.
460 if (i == N - 1) {
87
1/1
✓ Branch 2 taken 111 times.
111 x1 = surfacePoints[i].x();
88
1/1
✓ Branch 2 taken 111 times.
111 x2 = surfacePoints[0].x();
89
1/1
✓ Branch 2 taken 111 times.
111 y1 = surfacePoints[i].y();
90
1/1
✓ Branch 2 taken 111 times.
111 y2 = surfacePoints[0].y();
91 } else {
92
1/1
✓ Branch 2 taken 349 times.
349 x1 = surfacePoints[i].x();
93
1/1
✓ Branch 2 taken 349 times.
349 x2 = surfacePoints[i + 1].x();
94
1/1
✓ Branch 2 taken 349 times.
349 y1 = surfacePoints[i].y();
95
1/1
✓ Branch 2 taken 349 times.
349 y2 = surfacePoints[i + 1].y();
96 }
97
98 460 const double dA = (x1 * y2 - x2 * y1);
99 460 A += 0.5 * dA;
100 460 cx += (x1 + x2) * dA;
101 460 cy += (y1 + y2) * dA;
102 }
103
104
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 if (A > 0) {
105 // centroid in face coordinates
106
1/1
✓ Branch 1 taken 111 times.
111 const Point3d surfaceCentroid(cx / (6.0 * A), cy / (6.0 * A), 0.0);
107
108 // centroid
109
2/2
✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
111 result = alignFace * surfaceCentroid;
110 111 }
111 111 }
112 112 return result;
113 ✗ }
114
115 /// reorder points to upper-left-corner convention
116 22828 Point3dVector reorderULC(const Point3dVector& points) {
117 22828 const size_t N = points.size();
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22828 times.
22828 if (N < 3) {
119 ✗ return {};
120 }
121
122 // transformation to align face
123
1/1
✓ Branch 1 taken 22828 times.
22828 const Transformation t = Transformation::alignFace(points);
124
2/2
✓ Branch 1 taken 22828 times.
✓ Branch 4 taken 22828 times.
22828 Point3dVector facePoints = t.inverse() * points;
125
126 // find ulc index in face coordinates
127 22828 double maxY = std::numeric_limits<double>::min();
128 22828 double minX = std::numeric_limits<double>::max();
129 22828 size_t ulcIndex = 0;
130
2/2
✓ Branch 0 taken 110928 times.
✓ Branch 1 taken 22828 times.
133756 for (size_t i = 0; i < N; ++i) {
131
2/4
✓ Branch 2 taken 110928 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 110928 times.
✗ Branch 8 not taken.
110928 OS_ASSERT(std::abs(facePoints[i].z()) < 0.001);
132
11/11
✓ Branch 2 taken 110928 times.
✓ Branch 4 taken 79077 times.
✓ Branch 5 taken 31851 times.
✓ Branch 8 taken 79077 times.
✓ Branch 10 taken 32761 times.
✓ Branch 11 taken 46316 times.
✓ Branch 14 taken 32761 times.
✓ Branch 16 taken 27054 times.
✓ Branch 17 taken 5707 times.
✓ Branch 18 taken 58905 times.
✓ Branch 19 taken 52023 times.
110928 if ((maxY < facePoints[i].y()) || ((maxY < facePoints[i].y() + 0.00001) && (minX > facePoints[i].x()))) {
133 58905 ulcIndex = i;
134
1/1
✓ Branch 2 taken 58905 times.
58905 maxY = facePoints[i].y();
135
1/1
✓ Branch 2 taken 58905 times.
58905 minX = facePoints[i].x();
136 }
137 }
138
139 // no-op
140
2/2
✓ Branch 0 taken 3711 times.
✓ Branch 1 taken 19117 times.
22828 if (ulcIndex == 0) {
141
1/1
✓ Branch 1 taken 3711 times.
3711 return points;
142 }
143
144 // create result
145
1/1
✓ Branch 1 taken 19117 times.
19117 Point3dVector result = points;
146
1/1
✓ Branch 4 taken 19117 times.
38234 std::rotate(result.begin(), std::next(result.begin(), ulcIndex), result.end());
147 19117 return result;
148 22828 }
149
150 67 std::vector<Point3d> removeCollinear(const Point3dVector& points, double tol) {
151
1/1
✓ Branch 1 taken 67 times.
67 const Transformation t = Transformation::alignFace(points);
152
4/4
✓ Branch 1 taken 67 times.
✓ Branch 4 taken 67 times.
✓ Branch 7 taken 67 times.
✓ Branch 10 taken 67 times.
67 std::vector<Point3d> result = t * simplify(t.inverse() * points, true, tol);
153 134 return result;
154 67 }
155
156 3450 std::vector<Point3d> removeCollinearLegacy(const Point3dVector& points, double tol) {
157 3450 const size_t N = points.size();
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3450 times.
3450 if (N < 3) {
159 ✗ return points;
160 }
161
162 3450 std::vector<Point3d> result;
163
1/1
✓ Branch 2 taken 3450 times.
3450 Point3d lastPoint = points[0];
164
1/1
✓ Branch 1 taken 3450 times.
3450 result.push_back(lastPoint);
165
166
2/2
✓ Branch 0 taken 17035 times.
✓ Branch 1 taken 3450 times.
20485 for (unsigned i = 1; i < N; ++i) {
167 17035 const Point3d& currentPoint = points[i];
168
1/1
✓ Branch 2 taken 17035 times.
17035 Point3d nextPoint = points[0];
169
2/2
✓ Branch 0 taken 13585 times.
✓ Branch 1 taken 3450 times.
17035 if (i < N - 1) {
170
1/1
✓ Branch 2 taken 13585 times.
13585 nextPoint = points[i + 1];
171 }
172
173
1/1
✓ Branch 1 taken 17035 times.
17035 Vector3d a = (currentPoint - lastPoint);
174
1/1
✓ Branch 1 taken 17035 times.
17035 Vector3d b = (nextPoint - currentPoint);
175
176 // if these fail to normalize we have zero length vectors (e.g. adjacent points)
177
3/3
✓ Branch 1 taken 17035 times.
✓ Branch 3 taken 17032 times.
✓ Branch 4 taken 3 times.
17035 if (a.normalize()) {
178
3/3
✓ Branch 1 taken 17032 times.
✓ Branch 3 taken 17026 times.
✓ Branch 4 taken 6 times.
17032 if (b.normalize()) {
179
180
1/1
✓ Branch 1 taken 17026 times.
17026 const Vector3d c = a.cross(b);
181
3/3
✓ Branch 1 taken 17026 times.
✓ Branch 3 taken 16893 times.
✓ Branch 4 taken 133 times.
17026 if (c.length() >= tol) {
182 // cross product is significant
183
1/1
✓ Branch 1 taken 16893 times.
16893 result.push_back(currentPoint);
184
1/1
✓ Branch 1 taken 16893 times.
16893 lastPoint = currentPoint;
185 } else {
186 // see if dot product is near -1
187
1/1
✓ Branch 1 taken 133 times.
133 const double d = a.dot(b);
188
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 114 times.
133 if (d <= -1.0 + tol) {
189 // this is a line reversal
190
1/1
✓ Branch 1 taken 19 times.
19 result.push_back(currentPoint);
191
1/1
✓ Branch 1 taken 19 times.
19 lastPoint = currentPoint;
192 }
193 }
194 17026 }
195 }
196 17035 }
197
198 3450 size_t iBegin = 0;
199 3450 size_t iEnd = result.size();
200
201 3450 bool resizeBegin = true;
202
2/2
✓ Branch 0 taken 3473 times.
✓ Branch 1 taken 3450 times.
10373 while (resizeBegin) {
203 3473 resizeBegin = false;
204 3473 const unsigned newN = iEnd - iBegin;
205
2/2
✓ Branch 0 taken 3467 times.
✓ Branch 1 taken 6 times.
3473 if (newN > 3) {
206
1/1
✓ Branch 3 taken 3467 times.
3467 Vector3d a = (result[iBegin] - result[iEnd - 1]);
207
1/1
✓ Branch 3 taken 3467 times.
3467 Vector3d b = (result[iBegin + 1] - result[iBegin]);
208
2/3
✓ Branch 1 taken 3467 times.
✓ Branch 3 taken 3467 times.
✗ Branch 4 not taken.
3467 if (a.normalize()) {
209
2/3
✓ Branch 1 taken 3467 times.
✓ Branch 3 taken 3467 times.
✗ Branch 4 not taken.
3467 if (b.normalize()) {
210
1/1
✓ Branch 1 taken 3467 times.
3467 const double d = a.dot(b);
211
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 3444 times.
3467 if (d >= 1.0 - tol) {
212 23 iBegin++;
213 23 resizeBegin = true;
214 }
215 } else {
216 ✗ iBegin++;
217 ✗ resizeBegin = true;
218 }
219 } else {
220 ✗ iBegin++;
221 ✗ resizeBegin = true;
222 }
223 3467 }
224 }
225
226 3450 bool resizeEnd = true;
227
2/2
✓ Branch 0 taken 3450 times.
✓ Branch 1 taken 3450 times.
10350 while (resizeEnd) {
228 3450 resizeEnd = false;
229 3450 const unsigned newN = iEnd - iBegin;
230
2/2
✓ Branch 0 taken 3444 times.
✓ Branch 1 taken 6 times.
3450 if (newN > 3) {
231
1/1
✓ Branch 3 taken 3444 times.
3444 Vector3d a = (result[iEnd - 1] - result[iEnd - 2]);
232
1/1
✓ Branch 3 taken 3444 times.
3444 Vector3d b = (result[iBegin] - result[iEnd - 1]);
233
2/3
✓ Branch 1 taken 3444 times.
✓ Branch 3 taken 3444 times.
✗ Branch 4 not taken.
3444 if (a.normalize()) {
234
2/3
✓ Branch 1 taken 3444 times.
✓ Branch 3 taken 3444 times.
✗ Branch 4 not taken.
3444 if (b.normalize()) {
235
1/1
✓ Branch 1 taken 3444 times.
3444 const double d = a.dot(b);
236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3444 times.
3444 if (d >= 1.0 - tol) {
237 ✗ iEnd--;
238 ✗ resizeEnd = true;
239 }
240 } else {
241 ✗ iEnd--;
242 ✗ resizeEnd = true;
243 }
244 } else {
245 ✗ iEnd--;
246 ✗ resizeEnd = true;
247 }
248 3444 }
249 }
250
251
1/1
✓ Branch 5 taken 3450 times.
3450 result = std::vector<Point3d>(result.begin() + iBegin, result.begin() + iEnd);
252 3450 return result;
253 3450 }
254
255 1280868 double getDistanceSquared(const Point3d& point1, const Point3d& point2) {
256 1280868 const double dx = point1.x() - point2.x();
257 1280868 const double dy = point1.y() - point2.y();
258 1280868 const double dz = point1.z() - point2.z();
259 1280868 const double result = dx * dx + dy * dy + dz * dz;
260 1280868 return result;
261 }
262
263 1279462 double getDistance(const Point3d& point1, const Point3d& point2) {
264 1279462 double result = std::sqrt(getDistanceSquared(point1, point2));
265 1279462 return result;
266 }
267
268 491199 double getDistancePointToLineSegment(const Point3d& point, const std::vector<Point3d>& lineSegment) {
269
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 491198 times.
491199 if (lineSegment.size() != 2) {
270 1 return 0;
271 }
272
273 // http://paulbourke.net/geometry/pointlineplane/
274
275
1/1
✓ Branch 2 taken 491198 times.
491198 Point3d point1 = lineSegment[0];
276
1/1
✓ Branch 2 taken 491198 times.
491198 Point3d point2 = lineSegment[1];
277
278
1/1
✓ Branch 1 taken 491198 times.
491198 Vector3d p2p1 = point2 - point1;
279
1/1
✓ Branch 1 taken 491198 times.
491198 Vector3d p3p1 = point - point1;
280
281
1/1
✓ Branch 1 taken 491198 times.
491198 double d12 = p2p1.length();
282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 491198 times.
491198 if (d12 < 1.0e-12) {
283 ✗ return p3p1.length();
284 }
285
286
1/1
✓ Branch 1 taken 491198 times.
491198 Point3d closestPoint;
287
1/1
✓ Branch 1 taken 491198 times.
491198 double u = p3p1.dot(p2p1) / (d12 * d12);
288
2/2
✓ Branch 0 taken 149987 times.
✓ Branch 1 taken 341211 times.
491198 if (u < 0) {
289
1/1
✓ Branch 1 taken 149987 times.
149987 closestPoint = point1;
290
2/2
✓ Branch 0 taken 159676 times.
✓ Branch 1 taken 181535 times.
341211 } else if (u > 1) {
291
1/1
✓ Branch 1 taken 159676 times.
159676 closestPoint = point2;
292 } else {
293
2/2
✓ Branch 1 taken 181535 times.
✓ Branch 4 taken 181535 times.
181535 closestPoint = point1 + u * p2p1;
294 }
295
296
1/1
✓ Branch 1 taken 491198 times.
491198 Vector3d diff = point - closestPoint;
297
298
1/1
✓ Branch 1 taken 491198 times.
491198 return diff.length();
299 491198 }
300
301 30 double getDistancePointToTriangle(const Point3d& point, const std::vector<Point3d>& triangle) {
302
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if (triangle.size() != 3) {
303 ✗ return 0;
304 }
305
306 //Distance Between Point and Triangle in 3D
307 //David Eberly
308 //Geometric Tools, LLC
309 //http://www.geometrictools.com/
310
311 //T(s; t) = B+sE0+tE1
312
313 30 const Point3d& B = triangle[0];
314
1/1
✓ Branch 3 taken 30 times.
30 const Vector3d E0 = triangle[1] - triangle[0];
315
1/1
✓ Branch 3 taken 30 times.
30 const Vector3d E1 = triangle[2] - triangle[0];
316
1/1
✓ Branch 1 taken 30 times.
30 const Vector3d BminusP = B - point;
317
318
1/1
✓ Branch 1 taken 30 times.
30 const double b = E0.dot(E1);
319
320
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if (std::abs(b) > 1.0 - 1.0E-12) {
321 // triangle is collinear
322 ✗ return 0;
323 }
324
325
1/1
✓ Branch 1 taken 30 times.
30 const double a = E0.dot(E0);
326
1/1
✓ Branch 1 taken 30 times.
30 const double c = E1.dot(E1);
327
1/1
✓ Branch 1 taken 30 times.
30 const double d = E0.dot(BminusP);
328
1/1
✓ Branch 1 taken 30 times.
30 const double e = E1.dot(BminusP);
329 // const double f = BminusP.dot(BminusP); // unused
330
331 30 const double det = a * c - b * b;
332 30 const double s = b * e - c * d;
333 30 const double t = b * d - a * e;
334
335
1/1
✓ Branch 1 taken 30 times.
30 Point3d closestPoint;
336
337
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 if (s + t <= det) {
338
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 if (s < 0) {
339
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (t < 0) {
340 //region 4, closest to point triangle[0]
341
1/1
✓ Branch 2 taken 2 times.
2 return getDistance(point, triangle[0]);
342 } else {
343 //region 3, closest to line triangle[0] to triangle[2]
344 4 std::vector<Point3d> line;
345
1/1
✓ Branch 2 taken 4 times.
4 line.push_back(triangle[0]);
346
1/1
✓ Branch 2 taken 4 times.
4 line.push_back(triangle[2]);
347
1/1
✓ Branch 1 taken 4 times.
4 return getDistancePointToLineSegment(point, line);
348 4 }
349
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14 times.
18 } else if (t < 0) {
350 //region 5, closest to line triangle[0] to triangle[1]
351 4 std::vector<Point3d> line;
352
1/1
✓ Branch 2 taken 4 times.
4 line.push_back(triangle[0]);
353
1/1
✓ Branch 2 taken 4 times.
4 line.push_back(triangle[1]);
354
1/1
✓ Branch 1 taken 4 times.
4 return getDistancePointToLineSegment(point, line);
355 4 } else {
356 //region 0, closest point is inside triangle
357 14 const double invDet = 1.0 / det;
358
4/4
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✓ Branch 10 taken 14 times.
14 closestPoint = B + invDet * s * E0 + invDet * t * E1;
359 }
360 } else {
361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (s < 0) {
362 //region 2, closest to point triangle[2]
363 ✗ return getDistance(point, triangle[2]);
364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 } else if (t < 0) {
365 //region 6, closest to point triangle[1]
366 ✗ return getDistance(point, triangle[1]);
367 } else {
368 //region 1, closest to line triangle[1] to triangle[2]
369 6 std::vector<Point3d> line;
370
1/1
✓ Branch 2 taken 6 times.
6 line.push_back(triangle[1]);
371
1/1
✓ Branch 2 taken 6 times.
6 line.push_back(triangle[2]);
372
1/1
✓ Branch 1 taken 6 times.
6 return getDistancePointToLineSegment(point, line);
373 6 }
374 }
375
376
1/1
✓ Branch 1 taken 14 times.
14 const Vector3d diff = point - closestPoint;
377
1/1
✓ Branch 1 taken 14 times.
14 return diff.length();
378 30 }
379
380 64585 double getAngle(const Vector3d& vector1, const Vector3d& vector2) {
381
1/1
✓ Branch 1 taken 64585 times.
64585 Vector3d working1(vector1);
382
1/1
✓ Branch 1 taken 64585 times.
64585 working1.normalize();
383
1/1
✓ Branch 1 taken 64585 times.
64585 Vector3d working2(vector2);
384
1/1
✓ Branch 1 taken 64585 times.
64585 working2.normalize();
385
1/1
✓ Branch 1 taken 64585 times.
129170 return acos(working1.dot(working2));
386 64585 }
387
388 136835 bool circularEqual(const Point3dVector& points1, const Point3dVector& points2, double tol) {
389 136835 const size_t N = points1.size();
390
2/2
✓ Branch 1 taken 27300 times.
✓ Branch 2 taken 109535 times.
136835 if (N != points2.size()) {
391 27300 return false;
392 }
393
394
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 109531 times.
109535 if (N == 0) {
395 4 return true;
396 }
397
398 109531 bool result = false;
399
400 // look for a common starting point
401
2/2
✓ Branch 0 taken 389301 times.
✓ Branch 1 taken 89830 times.
479131 for (size_t i = 0; i < N; ++i) {
402
2/2
✓ Branch 3 taken 28049 times.
✓ Branch 4 taken 361252 times.
389301 if (getDistance(points1[0], points2[i]) <= tol) {
403
404 28049 result = true;
405
406 // check all other points
407
2/2
✓ Branch 0 taken 101639 times.
✓ Branch 1 taken 19701 times.
121340 for (unsigned j = 0; j < N; ++j) {
408
2/2
✓ Branch 3 taken 8348 times.
✓ Branch 4 taken 93291 times.
101639 if (getDistance(points1[j], points2[(i + j) % N]) > tol) {
409 8348 result = false;
410 8348 break;
411 }
412 }
413 }
414
415
2/2
✓ Branch 0 taken 19701 times.
✓ Branch 1 taken 369600 times.
389301 if (result) {
416 19701 return result;
417 }
418 }
419
420 89830 return result;
421 }
422
423 701489 Point3d getCombinedPoint(const Point3d& point3d, std::vector<Point3d>& allPoints, double tol) {
424
2/2
✓ Branch 5 taken 2675427 times.
✓ Branch 6 taken 487523 times.
3162950 for (const Point3d& otherPoint : allPoints) {
425
6/6
✓ Branch 1 taken 2675427 times.
✓ Branch 4 taken 2675427 times.
✓ Branch 8 taken 2675427 times.
✓ Branch 11 taken 2675427 times.
✓ Branch 15 taken 2675427 times.
✓ Branch 18 taken 2675427 times.
2675427 if (std::sqrt(std::pow(point3d.x() - otherPoint.x(), 2) + std::pow(point3d.y() - otherPoint.y(), 2) + std::pow(point3d.z() - otherPoint.z(), 2))
426
2/2
✓ Branch 0 taken 213966 times.
✓ Branch 1 taken 2461461 times.
2675427 < tol) {
427
1/1
✓ Branch 1 taken 213966 times.
213966 return otherPoint;
428 }
429 }
430 487523 allPoints.push_back(point3d);
431 487523 return point3d;
432 }
433
434 26022 std::vector<std::vector<Point3d>> computeTriangulation(const Point3dVector& vertices, const std::vector<std::vector<Point3d>>& holes, double tol) {
435 26022 std::vector<std::vector<Point3d>> result;
436
437 // check input
438
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 26022 times.
26022 if (vertices.size() < 3) {
439 ✗ return result;
440 }
441
442
1/1
✓ Branch 1 taken 26022 times.
26022 boost::optional<Vector3d> normal = getOutwardNormal(vertices);
443
7/8
✓ Branch 1 taken 26022 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26022 times.
✓ Branch 7 taken 26022 times.
✓ Branch 9 taken 5 times.
✓ Branch 10 taken 26017 times.
✓ Branch 11 taken 5 times.
✓ Branch 12 taken 26017 times.
26022 if (!normal || normal->z() > -0.999) {
444 5 return result;
445 }
446
447
2/2
✓ Branch 5 taken 2930 times.
✓ Branch 6 taken 26017 times.
28947 for (const auto& hole : holes) {
448
1/1
✓ Branch 1 taken 2930 times.
2930 normal = getOutwardNormal(hole);
449
5/8
✓ Branch 1 taken 2930 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2930 times.
✓ Branch 7 taken 2930 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2930 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2930 times.
2930 if (!normal || normal->z() > -0.999) {
450 ✗ return result;
451 }
452 }
453
454 // if holes have been triangulated, rejoin them here before subtraction
455
1/1
✓ Branch 1 taken 26017 times.
26017 const std::vector<std::vector<Point3d>> newHoles = joinAll(holes, tol);
456
457 26017 std::vector<Point3d> allPoints;
458
459 // PolyPartition does not support holes which intersect the polygon or share an edge
460 // if any hole is not fully contained we will use boost to remove all the holes
461 26017 bool polyPartitionHoles = true;
462
2/2
✓ Branch 5 taken 2731 times.
✓ Branch 6 taken 25668 times.
28399 for (const std::vector<Point3d>& hole : newHoles) {
463
3/3
✓ Branch 1 taken 2731 times.
✓ Branch 3 taken 349 times.
✓ Branch 4 taken 2382 times.
2731 if (!within(hole, vertices, tol)) {
464 // PolyPartition can't handle this
465 349 polyPartitionHoles = false;
466 349 break;
467 }
468 }
469
470
2/2
✓ Branch 0 taken 349 times.
✓ Branch 1 taken 25668 times.
26017 if (!polyPartitionHoles) {
471 // use boost to do all the intersections
472
1/1
✓ Branch 1 taken 349 times.
349 const std::vector<std::vector<Point3d>> allFaces = subtract(vertices, newHoles, tol);
473 349 const std::vector<std::vector<Point3d>> noHoles;
474
2/2
✓ Branch 5 taken 1964 times.
✓ Branch 6 taken 349 times.
2313 for (const std::vector<Point3d>& face : allFaces) {
475
1/1
✓ Branch 1 taken 1964 times.
1964 std::vector<std::vector<Point3d>> temp = computeTriangulation(face, noHoles);
476
1/1
✓ Branch 5 taken 1964 times.
1964 result.insert(result.end(), temp.begin(), temp.end());
477 1964 }
478 349 return result;
479 349 }
480
481 // convert input to vector of TPPLPoly
482 25668 std::list<TPPLPoly> polys;
483
484
1/1
✓ Branch 1 taken 25668 times.
25668 TPPLPoly outerPoly; // must be counter-clockwise, input vertices are clockwise
485
1/1
✓ Branch 2 taken 25668 times.
25668 outerPoly.Init(vertices.size());
486 25668 outerPoly.SetHole(false);
487 25668 const size_t n = vertices.size();
488
2/2
✓ Branch 0 taken 105365 times.
✓ Branch 1 taken 25668 times.
131033 for (size_t i = 0; i < n; ++i) {
489
490 // should all have zero z coordinate now
491
1/1
✓ Branch 2 taken 105365 times.
105365 const double z = vertices[n - i - 1].z();
492
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 105365 times.
105365 if (std::abs(z) > tol) {
493 ✗ LOG_FREE(Error, "utilities.geometry.computeTriangulation", "All points must be on z = 0 plane for triangulation methods");
494 ✗ return result;
495 }
496
497
1/1
✓ Branch 2 taken 105365 times.
105365 const Point3d point = getCombinedPoint(vertices[n - i - 1], allPoints, tol);
498
1/1
✓ Branch 1 taken 105365 times.
105365 outerPoly[i].x = point.x();
499
1/1
✓ Branch 1 taken 105365 times.
105365 outerPoly[i].y = point.y();
500 105365 }
501
1/1
✓ Branch 1 taken 25668 times.
25668 outerPoly.SetOrientation(TPPL_CCW);
502
1/1
✓ Branch 1 taken 25668 times.
25668 polys.push_back(outerPoly);
503
504
2/2
✓ Branch 5 taken 2370 times.
✓ Branch 6 taken 25668 times.
28038 for (const std::vector<Point3d>& holeVertices : newHoles) {
505
506
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2370 times.
2370 if (holeVertices.size() < 3) {
507 ✗ LOG_FREE(Error, "utilities.geometry.computeTriangulation", "Hole has fewer than 3 points, ignoring");
508 ✗ continue;
509 ✗ }
510
511
1/1
✓ Branch 1 taken 2370 times.
2370 TPPLPoly innerPoly; // must be clockwise, input vertices are clockwise
512
1/1
✓ Branch 2 taken 2370 times.
2370 innerPoly.Init(holeVertices.size());
513 2370 innerPoly.SetHole(true);
514 //std::cout << "inner :";
515
2/2
✓ Branch 1 taken 9488 times.
✓ Branch 2 taken 2370 times.
11858 for (unsigned i = 0; i < holeVertices.size(); ++i) {
516
517 // should all have zero z coordinate now
518
1/1
✓ Branch 2 taken 9488 times.
9488 const double z = holeVertices[i].z();
519
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9488 times.
9488 if (std::abs(z) > tol) {
520 ✗ LOG_FREE(Error, "utilities.geometry.computeTriangulation", "All points must be on z = 0 plane for triangulation methods");
521 ✗ return result;
522 }
523
524
1/1
✓ Branch 2 taken 9488 times.
9488 const Point3d point = getCombinedPoint(holeVertices[i], allPoints, tol);
525
1/1
✓ Branch 1 taken 9488 times.
9488 innerPoly[i].x = point.x();
526
1/1
✓ Branch 1 taken 9488 times.
9488 innerPoly[i].y = point.y();
527 9488 }
528
1/1
✓ Branch 1 taken 2370 times.
2370 innerPoly.SetOrientation(TPPL_CW);
529
1/1
✓ Branch 1 taken 2370 times.
2370 polys.push_back(innerPoly);
530 2370 }
531
532 // do partitioning
533 TPPLPartition pp;
534 25668 std::list<TPPLPoly> resultPolys;
535
1/1
✓ Branch 1 taken 25668 times.
25668 int test = pp.Triangulate_EC(&polys, &resultPolys);
536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25668 times.
25668 if (test == 0) {
537 ✗ test = pp.Triangulate_MONO(&polys, &resultPolys);
538 }
539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25668 times.
25668 if (test == 0) {
540 //std::stringstream ss;
541 //ss << "Vertices: " << vertices << '\n';
542 //for (const auto& hole : holes){ ss << "Hole:" << hole << '\n'; }
543 //std::string testStr = ss.str();
544 ✗ LOG_FREE(Error, "utilities.geometry.computeTriangulation", "Failed to partition polygon");
545 ✗ return result;
546 }
547
548 // convert back to vertices
549 25668 std::list<TPPLPoly>::iterator it;
550 25668 std::list<TPPLPoly>::iterator itend;
551 //std::cout << "Start" << '\n';
552
2/2
✓ Branch 4 taken 68257 times.
✓ Branch 5 taken 25668 times.
93925 for (it = resultPolys.begin(), itend = resultPolys.end(); it != itend; ++it) {
553
554
1/1
✓ Branch 2 taken 68257 times.
68257 it->SetOrientation(TPPL_CW);
555
556 68257 std::vector<Point3d> triangle;
557
2/2
✓ Branch 2 taken 204771 times.
✓ Branch 3 taken 68257 times.
273028 for (long i = 0; i < it->GetNumPoints(); ++i) {
558 204771 const TPPLPoint point = it->GetPoint(i);
559
1/1
✓ Branch 1 taken 204771 times.
204771 triangle.emplace_back(point.x, point.y, 0);
560 }
561 //std::cout << triangle << '\n';
562
1/1
✓ Branch 1 taken 68257 times.
68257 result.push_back(triangle);
563 68257 }
564 //std::cout << "End" << '\n';
565
566 25668 return result;
567 26022 }
568
569 48 std::vector<Point3d> moveVerticesTowardsPoint(const Point3dVector& vertices, const Point3d& point, double distance) {
570 48 Point3dVector result;
571
2/2
✓ Branch 5 taken 192 times.
✓ Branch 6 taken 48 times.
240 for (const Point3d& vertex : vertices) {
572
1/1
✓ Branch 1 taken 192 times.
192 Vector3d vector = point - vertex;
573
1/1
✓ Branch 1 taken 192 times.
192 vector.setLength(distance);
574
2/2
✓ Branch 1 taken 192 times.
✓ Branch 4 taken 192 times.
192 result.push_back(vertex + vector);
575 192 }
576 48 return result;
577 ✗ }
578
579 37305 std::vector<Point3d> reverse(const Point3dVector& vertices) {
580 37305 std::vector<Point3d> result(vertices);
581
1/1
✓ Branch 3 taken 37305 times.
37305 std::reverse(result.begin(), result.end());
582 37305 return result;
583 ✗ }
584
585 250 bool applyViewAndDaylightingGlassRatios(double viewGlassToWallRatio, double daylightingGlassToWallRatio, double desiredViewGlassSillHeight,
586 double desiredDaylightingGlassHeaderHeight, double exteriorShadingProjectionFactor,
587 double interiorShelfProjectionFactor, const Point3dVector& surfaceVertices, Point3dVector& viewVertices,
588 Point3dVector& daylightingVertices, Point3dVector& exteriorShadingVertices,
589 Point3dVector& interiorShelfVertices) {
590 // check inputs for reasonableness
591 250 const double totalWWR = viewGlassToWallRatio + daylightingGlassToWallRatio;
592
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 248 times.
250 if (totalWWR == 0) {
593 // requesting no glass? remove existing windows?
594 2 return false;
595
4/4
✓ Branch 0 taken 247 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 245 times.
248 } else if (totalWWR < 0.0 || totalWWR >= 1.0) {
596 3 return false;
597 }
598
599
1/1
✓ Branch 1 taken 245 times.
245 boost::optional<double> grossArea = getArea(surfaceVertices);
600
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 245 times.
245 if (!grossArea) {
601 ✗ return false;
602 }
603
604
1/1
✓ Branch 1 taken 245 times.
245 const Transformation transformation = Transformation::alignFace(surfaceVertices);
605
2/2
✓ Branch 1 taken 245 times.
✓ Branch 4 taken 245 times.
245 const Point3dVector faceVertices = transformation.inverse() * surfaceVertices;
606
607
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 245 times.
245 if (faceVertices.empty()) {
608 ✗ return false;
609 }
610
611 245 const bool doViewGlass = (viewGlassToWallRatio > 0);
612 245 const bool doDaylightGlass = (daylightingGlassToWallRatio > 0);
613
4/4
✓ Branch 0 taken 233 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 211 times.
245 const bool doExteriorShading = (doViewGlass && (exteriorShadingProjectionFactor > 0));
614
4/4
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 132 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 111 times.
245 const bool doInteriorShelf = (doDaylightGlass && (interiorShelfProjectionFactor > 0));
615
4/4
✓ Branch 0 taken 233 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 101 times.
✓ Branch 3 taken 132 times.
245 const bool doViewAndDaylightGlass = (doViewGlass && doDaylightGlass);
616
617 // ignore these user arguments?
618
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 233 times.
245 if (!doViewGlass) {
619 12 desiredViewGlassSillHeight = 0.0;
620 }
621
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 113 times.
245 if (!doDaylightGlass) {
622 132 desiredDaylightingGlassHeaderHeight = 0.0;
623 }
624
625 // new coordinate system has z' in direction of outward normal, y' is up
626 245 double xmin = std::numeric_limits<double>::max();
627 245 double xmax = std::numeric_limits<double>::min();
628 245 double ymin = std::numeric_limits<double>::max();
629 245 double ymax = std::numeric_limits<double>::min();
630
2/2
✓ Branch 4 taken 983 times.
✓ Branch 5 taken 245 times.
1228 for (const Point3d& faceVertex : faceVertices) {
631
1/1
✓ Branch 1 taken 983 times.
983 xmin = std::min(xmin, faceVertex.x());
632
1/1
✓ Branch 1 taken 983 times.
983 xmax = std::max(xmax, faceVertex.x());
633
1/1
✓ Branch 1 taken 983 times.
983 ymin = std::min(ymin, faceVertex.y());
634
1/1
✓ Branch 1 taken 983 times.
983 ymax = std::max(ymax, faceVertex.y());
635 }
636
2/4
✓ Branch 0 taken 245 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 245 times.
245 if ((xmin > xmax) || (ymin > ymax)) {
637 ✗ return false;
638 }
639
640 245 constexpr double oneInch = 0.0254;
641
642 // DLM: preserve a 1" gap between window and edge to keep SketchUp happy
643 245 constexpr double minGlassToEdgeDistance = oneInch;
644 245 double minViewToDaylightDistance = 0;
645
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 144 times.
245 if (doViewAndDaylightGlass) {
646 101 minViewToDaylightDistance = oneInch;
647 }
648
649 // wall parameters
650 245 const double wallWidth = xmax - xmin;
651 245 const double wallHeight = ymax - ymin;
652 245 const double wallArea = wallWidth * wallHeight;
653
654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 245 times.
245 if (wallWidth < 2 * minGlassToEdgeDistance) {
655 ✗ LOG_FREE(Warn, "utilities.geometry.applyViewAndDaylightingGlassRatios",
656 "Wall Width (" << wallWidth << "m) is too small to preserve 0.0254m (1 inch) on both sides.");
657 ✗ return false;
658 }
659
660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 245 times.
245 if (wallHeight < 2 * minGlassToEdgeDistance + minViewToDaylightDistance) {
661 ✗ LOG_FREE(Warn, "utilities.geometry.applyViewAndDaylightingGlassRatios",
662 "Wall Height (" << wallHeight << "m) is too small to preserve 0.0254m (1 inch) on both sides plus the minViewToDaylightDistance ("
663 << minViewToDaylightDistance << "m).");
664 ✗ return false;
665 }
666
667 // check against actual surface area to ensure this is a rectangle?
668
3/3
✓ Branch 1 taken 245 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 243 times.
245 if (std::abs(wallArea - grossArea.get()) > oneInch * oneInch) {
669 2 return false;
670 }
671
672 243 const double maxWindowArea = wallArea - 2 * wallHeight * minGlassToEdgeDistance
673 243 - (wallWidth - 2 * minGlassToEdgeDistance) * (2 * minGlassToEdgeDistance + minViewToDaylightDistance);
674 243 const double requestedViewArea = viewGlassToWallRatio * wallArea;
675 243 const double requestedDaylightingArea = daylightingGlassToWallRatio * wallArea;
676 243 const double requestedTotalWindowArea = totalWWR * wallArea;
677
678
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 242 times.
243 if (requestedTotalWindowArea > maxWindowArea) {
679
11/11
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
3 LOG_FREE(
680 Warn, "utilities.geometry.applyViewAndDaylightingGlassRatios",
681 "Requested WWR ("
682 << totalWWR << ") is greater than the Max WWR (" << maxWindowArea / wallArea
683 << "). This limit is meant to preserve mandatory space between window and wall: 0.0254m (1 inch) on all sides + minViewToDaylightDistance ("
684 << minViewToDaylightDistance << "m).");
685 1 return false;
686 }
687
688 // view glass parameters
689 242 double viewMinX = 0;
690 242 double viewMinY = 0;
691 242 double viewWidth = 0;
692 242 double viewHeight = 0;
693
694 // daylighting glass parameters
695 242 double daylightingWidth = 0;
696 242 double daylightingHeight = 0;
697 242 double daylightingMinX = 0;
698 242 double daylightingMinY = 0;
699
700 // initial free parameters
701 242 const double viewWidthInset = minGlassToEdgeDistance;
702 242 double viewSillHeight = std::max(desiredViewGlassSillHeight, minGlassToEdgeDistance);
703 242 const double daylightingWidthInset = minGlassToEdgeDistance;
704 242 double daylightingHeaderHeight = std::max(desiredDaylightingGlassHeaderHeight, minGlassToEdgeDistance);
705
706 242 bool converged = false;
707
1/2
✓ Branch 0 taken 1258 times.
✗ Branch 1 not taken.
1258 for (unsigned i = 0; i < 100; ++i) {
708
709 // view glass parameters
710 1258 viewMinX = viewWidthInset;
711 1258 viewMinY = viewSillHeight;
712 1258 viewWidth = wallWidth - 2 * viewWidthInset;
713 1258 viewHeight = requestedViewArea / viewWidth;
714
715 // daylighting glass parameters
716 1258 daylightingWidth = wallWidth - 2 * daylightingWidthInset;
717 1258 daylightingHeight = requestedDaylightingArea / daylightingWidth;
718 1258 daylightingMinX = viewWidthInset;
719 1258 daylightingMinY = wallHeight - daylightingHeaderHeight - daylightingHeight;
720
721
2/2
✓ Branch 0 taken 1016 times.
✓ Branch 1 taken 242 times.
1258 if (viewMinY + viewHeight + minViewToDaylightDistance > daylightingMinY) {
722 // windows overlap or exceed maximum size
723
724
2/2
✓ Branch 0 taken 1011 times.
✓ Branch 1 taken 5 times.
1016 if (doViewAndDaylightGlass) {
725
726 // try shrinking vertical offsets
727 1011 viewSillHeight = std::max(viewSillHeight - oneInch, minGlassToEdgeDistance);
728 1011 daylightingHeaderHeight = std::max(daylightingHeaderHeight - oneInch, minGlassToEdgeDistance);
729
730
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 } else if (doViewGlass) {
731
732 // solve directly
733 3 viewSillHeight = wallHeight - minGlassToEdgeDistance - viewHeight;
734
735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (viewSillHeight < minGlassToEdgeDistance) {
736 // cannot make window this large
737 ✗ return false;
738 }
739
740
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 } else if (doDaylightGlass) {
741
742 // solve directly
743 2 daylightingHeaderHeight = wallHeight - minGlassToEdgeDistance - daylightingHeight;
744
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (daylightingHeaderHeight < minGlassToEdgeDistance) {
746 // cannot make window this large
747 ✗ return false;
748 }
749 }
750
751 } else {
752
753 242 converged = true;
754 242 break;
755 }
756 }
757
758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 242 times.
242 if (!converged) {
759 ✗ return false;
760 }
761
762 242 Point3dVector surfacePolygon;
763
2/2
✓ Branch 4 taken 968 times.
✓ Branch 5 taken 242 times.
1210 for (const Point3d& point : faceVertices) {
764
2/3
✓ Branch 1 taken 968 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 968 times.
968 if (std::abs(point.z()) > 0.001) {
765 ✗ LOG_FREE(Warn, "utilities.geometry.applyViewAndDaylightingGlassRatios", "Surface point z not on plane, z =" << point.z());
766 }
767
4/4
✓ Branch 1 taken 968 times.
✓ Branch 4 taken 968 times.
✓ Branch 7 taken 968 times.
✓ Branch 10 taken 968 times.
968 surfacePolygon.push_back(Point3d(point.x(), point.y(), 0.0));
768 }
769
1/1
✓ Branch 3 taken 242 times.
242 std::reverse(surfacePolygon.begin(), surfacePolygon.end());
770
771
2/2
✓ Branch 0 taken 230 times.
✓ Branch 1 taken 12 times.
242 if (doViewGlass) {
772
2/2
✓ Branch 1 taken 230 times.
✓ Branch 4 taken 230 times.
230 viewVertices.push_back(Point3d(viewMinX, viewMinY + viewHeight, 0));
773
2/2
✓ Branch 1 taken 230 times.
✓ Branch 4 taken 230 times.
230 viewVertices.push_back(Point3d(viewMinX, viewMinY, 0));
774
2/2
✓ Branch 1 taken 230 times.
✓ Branch 4 taken 230 times.
230 viewVertices.push_back(Point3d(viewMinX + viewWidth, viewMinY, 0));
775
2/2
✓ Branch 1 taken 230 times.
✓ Branch 4 taken 230 times.
230 viewVertices.push_back(Point3d(viewMinX + viewWidth, viewMinY + viewHeight, 0));
776
777 230 Point3dVector windowPolygon;
778
2/2
✓ Branch 4 taken 920 times.
✓ Branch 5 taken 230 times.
1150 for (const Point3d& point : viewVertices) {
779
2/3
✓ Branch 1 taken 920 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 920 times.
920 if (std::abs(point.z()) > 0.001) {
780 ✗ LOG_FREE(Warn, "utilities.geometry.applyViewAndDaylightingGlassRatios", "Surface point z not on plane, z =" << point.z());
781 }
782
4/4
✓ Branch 1 taken 920 times.
✓ Branch 4 taken 920 times.
✓ Branch 7 taken 920 times.
✓ Branch 10 taken 920 times.
920 windowPolygon.push_back(Point3d(point.x(), point.y(), 0.0));
783 }
784
785 // sub surface must be fully contained by base surface
786
2/2
✓ Branch 5 taken 920 times.
✓ Branch 6 taken 230 times.
1150 for (const Point3d& point : windowPolygon) {
787
2/3
✓ Branch 1 taken 920 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 920 times.
920 if (!within(point, surfacePolygon, 0.001)) {
788 ✗ std::cout << "point: " << point << '\n';
789 ✗ std::cout << "surfacePolygon: " << surfacePolygon << '\n';
790 ✗ LOG_FREE(Debug, "utilities.geometry.applyViewAndDaylightingGlassRatios", "Surface does not fully contain SubSurface");
791 ✗ return false;
792 }
793 }
794 230 }
795
796
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 129 times.
242 if (doDaylightGlass) {
797
2/2
✓ Branch 1 taken 113 times.
✓ Branch 4 taken 113 times.
113 daylightingVertices.push_back(Point3d(daylightingMinX, daylightingMinY + daylightingHeight, 0));
798
2/2
✓ Branch 1 taken 113 times.
✓ Branch 4 taken 113 times.
113 daylightingVertices.push_back(Point3d(daylightingMinX, daylightingMinY, 0));
799
2/2
✓ Branch 1 taken 113 times.
✓ Branch 4 taken 113 times.
113 daylightingVertices.push_back(Point3d(daylightingMinX + daylightingWidth, daylightingMinY, 0));
800
2/2
✓ Branch 1 taken 113 times.
✓ Branch 4 taken 113 times.
113 daylightingVertices.push_back(Point3d(daylightingMinX + daylightingWidth, daylightingMinY + daylightingHeight, 0));
801
802 113 Point3dVector windowPolygon;
803
2/2
✓ Branch 4 taken 452 times.
✓ Branch 5 taken 113 times.
565 for (const Point3d& point : daylightingVertices) {
804
2/3
✓ Branch 1 taken 452 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 452 times.
452 if (std::abs(point.z()) > 0.001) {
805 ✗ LOG_FREE(Warn, "utilities.geometry.applyViewAndDaylightingGlassRatios", "Surface point z not on plane, z =" << point.z());
806 }
807
4/4
✓ Branch 1 taken 452 times.
✓ Branch 4 taken 452 times.
✓ Branch 7 taken 452 times.
✓ Branch 10 taken 452 times.
452 windowPolygon.push_back(Point3d(point.x(), point.y(), 0.0));
808 }
809
810 // sub surface must be fully contained by base surface
811
2/2
✓ Branch 5 taken 452 times.
✓ Branch 6 taken 113 times.
565 for (const Point3d& point : windowPolygon) {
812
2/3
✓ Branch 1 taken 452 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 452 times.
452 if (!within(point, surfacePolygon, 0.001)) {
813 ✗ LOG_FREE(Debug, "utilities.geometry.applyViewAndDaylightingGlassRatios", "Surface does not fully contain SubSurface");
814 ✗ return false;
815 }
816 }
817 113 }
818
819
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 220 times.
242 if (doExteriorShading) {
820
2/2
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
22 exteriorShadingVertices.push_back(Point3d(viewMinX, viewMinY + viewHeight, 0));
821
2/2
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
22 exteriorShadingVertices.push_back(Point3d(viewMinX, viewMinY + viewHeight, exteriorShadingProjectionFactor * viewHeight));
822
2/2
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
22 exteriorShadingVertices.push_back(Point3d(viewMinX + viewWidth, viewMinY + viewHeight, exteriorShadingProjectionFactor * viewHeight));
823
2/2
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
22 exteriorShadingVertices.push_back(Point3d(viewMinX + viewWidth, viewMinY + viewHeight, 0));
824 }
825
826
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 240 times.
242 if (doInteriorShelf) {
827
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 interiorShelfVertices.push_back(Point3d(daylightingMinX + daylightingWidth, daylightingMinY, 0));
828
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 interiorShelfVertices.push_back(Point3d(daylightingMinX + daylightingWidth, daylightingMinY, -interiorShelfProjectionFactor * daylightingHeight));
829
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 interiorShelfVertices.push_back(Point3d(daylightingMinX, daylightingMinY, -interiorShelfProjectionFactor * daylightingHeight));
830
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 interiorShelfVertices.push_back(Point3d(daylightingMinX, daylightingMinY, 0));
831 }
832
833 // put all vertices back into input coordinate system
834
1/1
✓ Branch 1 taken 242 times.
242 viewVertices = transformation * viewVertices;
835
1/1
✓ Branch 1 taken 242 times.
242 daylightingVertices = transformation * daylightingVertices;
836
1/1
✓ Branch 1 taken 242 times.
242 exteriorShadingVertices = transformation * exteriorShadingVertices;
837
1/1
✓ Branch 1 taken 242 times.
242 interiorShelfVertices = transformation * interiorShelfVertices;
838
839 242 return true;
840 245 }
841
842 2729532 bool isAlmostEqual3dPt(const Point3d& lhs, const Point3d& rhs, double tol) {
843 // TODO: this is what E+ does... I think I would prefer just calling getDistance...
844
6/6
✓ Branch 3 taken 656765 times.
✓ Branch 4 taken 2072767 times.
✓ Branch 8 taken 277316 times.
✓ Branch 9 taken 379449 times.
✓ Branch 13 taken 162483 times.
✓ Branch 14 taken 114833 times.
2729532 return ((std::abs(lhs.x() - rhs.x()) < tol) && (std::abs(lhs.y() - rhs.y()) < tol) && (std::abs(lhs.z() - rhs.z()) < tol));
845 // return getDistance(lhs, rhs) < tol;
846 }
847
848 391313 bool isPointOnLineBetweenPoints(const Point3d& start, const Point3d& end, const Point3d& test, double tol) {
849 // The tolerance has to be low enough. Take for eg a plenum that has an edge that's 30meters long, you risk adding point from the floor to
850 // the roof, cf E+ #7383
851 // compute the shortest distance from the point to the line first to avoid false positive
852
4/6
✓ Branch 1 taken 391313 times.
✓ Branch 4 taken 391313 times.
✓ Branch 7 taken 782626 times.
✓ Branch 8 taken 391313 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1565252 const double distance = getDistancePointToLineSegment(test, {start, end});
853
2/2
✓ Branch 0 taken 1181 times.
✓ Branch 1 taken 390132 times.
391313 if (distance < tol) { // getDistancePointToLineSegment always positive, it's calculated as norml_L2
854 1181 return (std::abs((getDistance(start, end) - (getDistance(start, test) + getDistance(test, end)))) < tol);
855 }
856 390132 return false;
857 391313 }
858
859 } // namespace openstudio
860