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
# 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.



52
53
54
# File 'lib/urbanopt/geojson/scale_area.rb', line 52

def eps
  @eps
end

#new_verticesObject (readonly)

Returns the value of attribute new_vertices.



67
68
69
# File 'lib/urbanopt/geojson/scale_area.rb', line 67

def new_vertices
  @new_vertices
end

#oneObject (readonly)

Returns the value of attribute one.



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

def one
  @one
end

#tenObject (readonly)

Returns the value of attribute ten.



50
51
52
# File 'lib/urbanopt/geojson/scale_area.rb', line 50

def ten
  @ten
end

#twoObject (readonly)

Returns the value of attribute two.



48
49
50
# File 'lib/urbanopt/geojson/scale_area.rb', line 48

def two
  @two
end

#zeroObject (readonly)

Returns the value of attribute zero.



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

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.



58
59
60
61
62
63
64
65
# File 'lib/urbanopt/geojson/scale_area.rb', line 58

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