tbd 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +3 -0
  3. data/.github/workflows/pull_request.yml +72 -0
  4. data/.gitignore +23 -0
  5. data/.rspec +3 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.md +21 -0
  8. data/README.md +154 -0
  9. data/Rakefile +60 -0
  10. data/json/midrise.json +64 -0
  11. data/json/tbd_5ZoneNoHVAC.json +19 -0
  12. data/json/tbd_5ZoneNoHVAC_btap.json +91 -0
  13. data/json/tbd_seb_n2.json +41 -0
  14. data/json/tbd_seb_n4.json +57 -0
  15. data/json/tbd_warehouse10.json +24 -0
  16. data/json/tbd_warehouse5.json +37 -0
  17. data/lib/measures/tbd/LICENSE.md +21 -0
  18. data/lib/measures/tbd/README.md +136 -0
  19. data/lib/measures/tbd/README.md.erb +42 -0
  20. data/lib/measures/tbd/docs/.gitkeep +1 -0
  21. data/lib/measures/tbd/measure.rb +327 -0
  22. data/lib/measures/tbd/measure.xml +460 -0
  23. data/lib/measures/tbd/resources/geo.rb +714 -0
  24. data/lib/measures/tbd/resources/geometry.rb +351 -0
  25. data/lib/measures/tbd/resources/model.rb +1431 -0
  26. data/lib/measures/tbd/resources/oslog.rb +381 -0
  27. data/lib/measures/tbd/resources/psi.rb +2229 -0
  28. data/lib/measures/tbd/resources/tbd.rb +55 -0
  29. data/lib/measures/tbd/resources/transformation.rb +121 -0
  30. data/lib/measures/tbd/resources/ua.rb +986 -0
  31. data/lib/measures/tbd/resources/utils.rb +1636 -0
  32. data/lib/measures/tbd/resources/version.rb +3 -0
  33. data/lib/measures/tbd/tests/tbd_full_PSI.json +17 -0
  34. data/lib/measures/tbd/tests/tbd_tests.rb +222 -0
  35. data/lib/tbd/geo.rb +714 -0
  36. data/lib/tbd/psi.rb +2229 -0
  37. data/lib/tbd/ua.rb +986 -0
  38. data/lib/tbd/version.rb +25 -0
  39. data/lib/tbd.rb +93 -0
  40. data/sponsors/canada.png +0 -0
  41. data/sponsors/quebec.png +0 -0
  42. data/tbd.gemspec +43 -0
  43. data/tbd.schema.json +571 -0
  44. data/v291_MacOS.md +110 -0
  45. metadata +191 -0
@@ -0,0 +1,351 @@
1
+ module Topolys
2
+
3
+ # Point3D, Vector3D, and Plane3D represents the 3D position and orientation
4
+ # of geometry in Topolys. Geometry is separate from topology (connections).
5
+
6
+ class Point3D
7
+
8
+ # @return [Float] X, Y, or Z coordinate
9
+ attr_reader :x, :y, :z
10
+
11
+ ##
12
+ # Initializes a Point3D object
13
+ #
14
+ # @param [Float] X-coordinate
15
+ # @param [Float] Y-coordinate
16
+ # @param [Float] Z-coordinate
17
+ def initialize(x, y, z)
18
+ raise "Incorrect x argument for Point3D, expected Numeric but got #{x.class}" unless x.is_a?(Numeric)
19
+ raise "Incorrect y argument for Point3D, expected Numeric but got #{y.class}" unless y.is_a?(Numeric)
20
+ raise "Incorrect z argument for Point3D, expected Numeric but got #{z.class}" unless z.is_a?(Numeric)
21
+ @x = x
22
+ @y = y
23
+ @z = z
24
+ end
25
+
26
+ def to_s
27
+ "[#{@x}, #{@y}, #{@z}]"
28
+ end
29
+
30
+ ##
31
+ # Adds a 3D vector to self
32
+ #
33
+ # @param [Vector3D] vector A Vector3D
34
+ #
35
+ # @return [Point3D] Returns a new Point3D - nil if vector not a Vector3D
36
+ def +(vector)
37
+ return nil unless vector.is_a?(Topolys::Vector3D)
38
+ x = @x + vector.x
39
+ y = @y + vector.y
40
+ z = @z + vector.z
41
+ return Topolys::Point3D.new(x, y, z)
42
+ end
43
+
44
+ ##
45
+ # Generates a 3D vector which goes from other to self
46
+ #
47
+ # @param [Point3D] other Another 3D point
48
+ #
49
+ # @return [Vector3D] Returns a new Vector3D - nil if other not a Point3D
50
+ def -(other)
51
+ return nil unless other.is_a?(Topolys::Point3D)
52
+ x = @x - other.x
53
+ y = @y - other.y
54
+ z = @z - other.z
55
+ return Topolys::Vector3D.new(x, y, z)
56
+ end
57
+
58
+ end # Point3D
59
+
60
+ class Vector3D
61
+
62
+ # @return [Float] X, Y, or Z component
63
+ attr_reader :x, :y, :z
64
+
65
+ ##
66
+ # Initializes a Vector3D object
67
+ #
68
+ # @param [Float] X-coordinate
69
+ # @param [Float] Y-coordinate
70
+ # @param [Float] Z-coordinate
71
+ def initialize(x, y, z)
72
+ raise "Incorrect x argument for Vector3D, expected Numeric but got #{x.class}" unless x.is_a?(Numeric)
73
+ raise "Incorrect y argument for Vector3D, expected Numeric but got #{y.class}" unless y.is_a?(Numeric)
74
+ raise "Incorrect z argument for Vector3D, expected Numeric but got #{z.class}" unless z.is_a?(Numeric)
75
+ @x = x
76
+ @y = y
77
+ @z = z
78
+ end
79
+
80
+ def to_s
81
+ "[#{@x}, #{@y}, #{@z}]"
82
+ end
83
+
84
+ def Vector3D.x_axis
85
+ Vector3D.new(1,0,0)
86
+ end
87
+
88
+ def Vector3D.y_axis
89
+ Vector3D.new(0,1,0)
90
+ end
91
+
92
+ def Vector3D.z_axis
93
+ Vector3D.new(0,0,1)
94
+ end
95
+
96
+ ##
97
+ # Adds 2x 3D vectors - overrides '+' operator
98
+ #
99
+ # @param [Vector3D] other Another 3D vector
100
+ #
101
+ # @return [Vector3D] Returns a new 3D resultant vector - nil if not Vector3D objects
102
+ def +(other)
103
+ return nil unless other.is_a?(Topolys::Vector3D)
104
+ x = @x + other.x
105
+ y = @y + other.y
106
+ z = @z + other.z
107
+ return Topolys::Vector3D.new(x, y, z)
108
+ end
109
+
110
+ ##
111
+ # Subtracts a 3D vector from another 3D vector - overrides '-' operator.
112
+ # Leaves original 3D vector intact if other is not a Vector3D object
113
+ #
114
+ # @param [Vector3D] other Another 3D vector
115
+ #
116
+ # @return [Vector3D] Returns a new 3D resultant vector - nil if not Vector3D objects
117
+ def -(other)
118
+ return nil unless other.is_a?(Topolys::Vector3D)
119
+ x = @x - other.x
120
+ y = @y - other.y
121
+ z = @z - other.z
122
+ return Topolys::Vector3D.new(x, y, z)
123
+ end
124
+
125
+ ##
126
+ # Multiplies a 3D vector by a scalar
127
+ #
128
+ # @param [Float] scalar A scalar
129
+ #
130
+ # @return [Vector3D] Returns a new, scaled 3D vector - nil if not numeric
131
+ def *(scalar)
132
+ return nil unless scalar.is_a?(Numeric)
133
+ x = @x * scalar
134
+ y = @y * scalar
135
+ z = @z * scalar
136
+ return Topolys::Vector3D.new(x, y, z)
137
+ end
138
+
139
+ ##
140
+ # Divides a 3D vector by a non-zero scalar
141
+ #
142
+ # @param [Float] scalar A non-zero scalar
143
+ #
144
+ # @return [Vector3D] Returns a new, scaled 3D vector - nil if 0 or not numeric
145
+ def /(scalar)
146
+ return nil unless scalar.is_a?(Numeric)
147
+ return nil if scalar.zero?
148
+ x = @x / scalar
149
+ y = @y / scalar
150
+ z = @z / scalar
151
+ Topolys::Vector3D.new(x, y, z)
152
+ end
153
+
154
+ ##
155
+ # Gets 3D vector magnitude (or length)
156
+ #
157
+ # @return [Float] Returns magnitude of the 3D vector
158
+ def magnitude
159
+ Math.sqrt(@x**2 + @y**2 + @z**2)
160
+ end
161
+
162
+ ##
163
+ # Normalizes a 3D vector
164
+ def normalize!
165
+ n = magnitude
166
+ unless n.zero?
167
+ @x /= n
168
+ @y /= n
169
+ @z /= n
170
+ end
171
+ end
172
+
173
+ ##
174
+ # Gets the dot (or inner) product of self & another 3D vector
175
+ #
176
+ # @param [Vector3D] other Another 3D vector
177
+ #
178
+ # @return [Float] Returns dot product - nil if not Vector3D objects
179
+ def dot(other)
180
+ return nil unless other.is_a?(Topolys::Vector3D)
181
+ return @x * other.x + @y * other.y + @z * other.z
182
+ end
183
+
184
+ ##
185
+ # Gets the cross product between self & another 3D vector
186
+ #
187
+ # @param [Vector3D] other Another 3D vector
188
+ #
189
+ # @return [Vector3D] Returns cross product - nil if not Vector3D objects
190
+ def cross(other)
191
+ return nil unless other.is_a?(Topolys::Vector3D)
192
+ x = @y * other.z - @z * other.y
193
+ y = @z * other.x - @x * other.z
194
+ z = @x * other.y - @y * other.x
195
+ return Topolys::Vector3D.new(x, y, z)
196
+ end
197
+
198
+ ##
199
+ # Gets the outer product between self & another 3D vector
200
+ #
201
+ # @param [Vector3D] other Another 3D vector
202
+ #
203
+ # @return [Matrix] Returns outer product
204
+ def outer_product(other)
205
+ return nil unless other.is_a?(Topolys::Vector3D)
206
+ result = Matrix.zero(3,3)
207
+ result[0,0] = @x*other.x
208
+ result[0,1] = @x*other.y
209
+ result[0,2] = @x*other.z
210
+ result[1,0] = @y*other.x
211
+ result[1,1] = @y*other.y
212
+ result[1,2] = @y*other.z
213
+ result[2,0] = @z*other.x
214
+ result[2,1] = @z*other.y
215
+ result[2,2] = @z*other.z
216
+ return result
217
+ end
218
+
219
+ ##
220
+ # Gets angle [0,PI) between self & another 3D vector
221
+ #
222
+ # @param [Vector3D] other Another 3D vector
223
+ #
224
+ # @return [Float] Returns angle - nil if not Vector3D objects
225
+ def angle(other)
226
+ return nil unless other.is_a?(Topolys::Vector3D)
227
+ prod = magnitude * other.magnitude
228
+ return nil if prod.zero?
229
+ val = dot(other) / prod
230
+ val = [-1.0, val].max
231
+ val = [ val, 1.0].min
232
+ Math.acos(val)
233
+ end
234
+
235
+ end # Vector3D
236
+
237
+ class Plane3D
238
+
239
+ # @return [Point3D] arbitrary point on plane
240
+ attr_reader :point
241
+
242
+ # @return [Vector3D] normalized vector perpendicular to plane
243
+ attr_reader :normal
244
+
245
+ ##
246
+ # Initializes a Plane3D object from a point and an outward normal
247
+ #
248
+ # @param [Point3d] point
249
+ # @param [Vector3D] normal
250
+ def initialize(point, normal)
251
+ raise "Incorrect point argument for Plane3D, expected Point3D but got #{point.class}" unless point.is_a?(Topolys::Point3D)
252
+ raise "Incorrect normal argument for Plane3D, expected Vector3D but got #{normal.class}" unless normal.is_a?(Topolys::Vector3D)
253
+ raise "Incorrect normal argument for Plane3D, magnitude too small" unless normal.magnitude > Float::EPSILON
254
+
255
+ @point = Point3D.new(point.x, point.y, point.z)
256
+ @normal = Vector3D.new(normal.x, normal.y, normal.z)
257
+ @normal.normalize!
258
+
259
+ # coefficients for equation of a plane
260
+ @a = @normal.x
261
+ @b = @normal.y
262
+ @c = @normal.z
263
+ @d = -(@a*@point.x + @b*@point.y + @c*@point.z)
264
+ end
265
+
266
+ def to_s
267
+ "[#{@a}, #{@b}, #{@c}, #{@d}]"
268
+ end
269
+
270
+ ##
271
+ # Initializes a Plane3D object from three non-colinear points
272
+ #
273
+ # @param [Point3d] point1
274
+ # @param [Point3d] point2
275
+ # @param [Point3d] point3
276
+ def Plane3D.from_points(point1, point2, point3)
277
+ return nil unless point1.is_a?(Topolys::Point3D)
278
+ return nil unless point2.is_a?(Topolys::Point3D)
279
+ return nil unless point3.is_a?(Topolys::Point3D)
280
+
281
+ normal = (point2-point1).cross(point3-point1)
282
+ return nil unless normal.magnitude > Float::EPSILON
283
+
284
+ return Plane3D.new(point1, normal)
285
+ end
286
+
287
+ ##
288
+ # Initializes a Plane3D object from a point and two vectors
289
+ #
290
+ # @param [Point3d] point
291
+ # @param [Vector3D] xaxis
292
+ # @param [Vector3D] yaxis
293
+ def Plane3D.from_point_axes(point, xaxis, yaxis)
294
+ return nil unless point.is_a?(Topolys::Point3D)
295
+ return nil unless xaxis.is_a?(Topolys::Vector3D)
296
+ return nil unless yaxis.is_a?(Topolys::Vector3D)
297
+
298
+ normal = xaxis.cross(yaxis)
299
+ return nil unless normal.magnitude > Float::EPSILON
300
+
301
+ return Plane3D.new(point, normal)
302
+ end
303
+
304
+ # TODO: implement methods below
305
+
306
+ ##
307
+ # Project a Point3d to this plane
308
+ #
309
+ # @param [Point3d] point
310
+ #
311
+ # @return [Point3d] Returns point projected to this plane
312
+ def project(point)
313
+ dist = @normal.dot(point-@point)
314
+ return point + normal*(-dist)
315
+ end
316
+
317
+ end # Plane3D
318
+
319
+ class BoundingBox
320
+
321
+ attr_reader :minx, :maxx, :miny, :maxy, :minz, :maxz
322
+
323
+ def initialize(tol = 0.001)
324
+ @tol = tol
325
+ @minx = Float::INFINITY
326
+ @miny = Float::INFINITY
327
+ @minz = Float::INFINITY
328
+ @maxx = -Float::INFINITY
329
+ @maxy = -Float::INFINITY
330
+ @maxz = -Float::INFINITY
331
+ end
332
+
333
+ def add_point(point)
334
+ @minx = [point.x, @minx].min
335
+ @miny = [point.y, @miny].min
336
+ @minz = [point.z, @minz].min
337
+ @maxx = [point.x, @maxx].max
338
+ @maxy = [point.y, @maxy].max
339
+ @maxz = [point.z, @maxz].max
340
+ end
341
+
342
+ def include?(point)
343
+ result = ((point.x >= @minx - @tol) && (point.x <= @maxx + @tol)) &&
344
+ ((point.y >= @miny - @tol) && (point.y <= @maxy + @tol)) &&
345
+ ((point.z >= @minz - @tol) && (point.z <= @maxz + @tol))
346
+ return result
347
+ end
348
+
349
+ end # BoundingBox
350
+
351
+ end # TOPOLYS