-
Notifications
You must be signed in to change notification settings - Fork 9
/
intersect.rb.erb
45 lines (35 loc) · 974 Bytes
/
intersect.rb.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'openstudio'
src_osm = '<%= src_osm %>'
in_osm = '<%= in_osm %>'
out_osm = '<%= out_osm %>'
vt = OpenStudio::OSVersion::VersionTranslator.new
model = vt.loadModel(src_osm)
fail "Cannot load model from #{src_osm}" if model.empty?
model = model.get
model.save(in_osm, true)
logSink = OpenStudio::StringStreamLogSink.new
logSink.setLogLevel(OpenStudio::Error)
spaces = model.getSpaces
n = spaces.size
boundingBoxes = OpenStudio::BoundingBoxVector.new
spaces.each do |space|
t = space.buildingTransformation
boundingBox = t*space.boundingBox
boundingBoxes << boundingBox
end
for i in 0...n
for j in i+1...n
if boundingBoxes[i].intersects(boundingBoxes[j])
spaces[i].intersectSurfaces(spaces[j])
spaces[i].matchSurfaces(spaces[j])
end
end
end
# check no errors
did_fail = false
logSink.logMessages().each do |msg|
puts msg.logMessage
did_fail = true
end
model.save(out_osm, true)
fail "Incorrect messages detected" if did_fail