Sha256: e52eda289dd7154aac0412cab7f9466460fe08ed6e4c4d58bfa0095f242a6e13

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

# *********************************************************************************
# URBANopt (tm), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://github.com/urbanopt/urbanopt-geojson-gem/blob/develop/LICENSE.md
# *********************************************************************************

require 'json'
require 'net/http'
require 'uri'
require 'openssl'
require 'bigdecimal/newton'

module Newton
  def self.jacobian(f, fx, x)
    Jacobian.jacobian(f, fx, x)
  end

  def self.ludecomp(a, n, zero = 0, one = 1)
    LUSolve.ludecomp(a, n, zero, one)
  end

  def self.lusolve(a, b, ps, zero = 0.0)
    LUSolve.lusolve(a, b, ps, zero)
  end
end

module URBANopt
  module GeoJSON
    class ScaleArea
      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

      attr_reader :zero, :one, :two, :ten, :eps, :new_vertices

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
urbanopt-geojson-0.11.2 lib/urbanopt/geojson/scale_area.rb