Class: URBANopt::GeoJSON::ScaleArea

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/geojson/scale_area.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vertices, desired_area, runner, eps) ⇒ ScaleArea

Returns a new instance of ScaleArea.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/urbanopt/geojson/scale_area.rb', line 29

def initialize(vertices, desired_area, runner, eps)
  @vertices = vertices
  @centroid = OpenStudio.getCentroid(vertices)
  raise "Cannot compute centroid for '#{vertices}'" if @centroid.empty?

  @centroid = @centroid.get
  @desired_area = desired_area
  @new_vertices = vertices
  @runner = runner
  @zero = BigDecimal('0.0')
  @one  = BigDecimal('1.0')
  @two  = BigDecimal('2.0')
  @ten  = BigDecimal('10.0')
  @eps  = eps
end

Instance Attribute Details

#epsObject (readonly)

Returns the value of attribute eps.



45
46
47
# File 'lib/urbanopt/geojson/scale_area.rb', line 45

def eps
  @eps
end

#new_verticesObject (readonly)

Returns the value of attribute new_vertices.



45
46
47
# File 'lib/urbanopt/geojson/scale_area.rb', line 45

def new_vertices
  @new_vertices
end

#oneObject (readonly)

Returns the value of attribute one.



45
46
47
# File 'lib/urbanopt/geojson/scale_area.rb', line 45

def one
  @one
end

#tenObject (readonly)

Returns the value of attribute ten.



45
46
47
# File 'lib/urbanopt/geojson/scale_area.rb', line 45

def ten
  @ten
end

#twoObject (readonly)

Returns the value of attribute two.



45
46
47
# File 'lib/urbanopt/geojson/scale_area.rb', line 45

def two
  @two
end

#zeroObject (readonly)

Returns the value of attribute zero.



45
46
47
# File 'lib/urbanopt/geojson/scale_area.rb', line 45

def zero
  @zero
end

Instance Method Details

#values(x) ⇒ Object

Used to determine new scaled vertices, by iteratively passing in the perimeter distance to minimise the difference of the new and scaled area. Returns the difference of the new area and desired area.



51
52
53
54
55
56
57
58
59
# File 'lib/urbanopt/geojson/scale_area.rb', line 51

def values(x)
  @new_vertices = URBANopt::GeoJSON::Zoning.divide_floor_print(@vertices, x[0].to_f, @runner, scale = true)
  new_area = OpenStudio.getArea(@new_vertices)
  raise "Cannot compute area for '#{@new_vertices}'" if new_area.empty?

  new_area = new_area.get

  return [new_area - @desired_area]
end