Method: Chem::Molecule::EpsParameter#calc_bounding_box_size

Defined in:
lib/chem/db/eps.rb

#calc_bounding_box_size(nodes) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/chem/db/eps.rb', line 133

def calc_bounding_box_size nodes
  # Shocking code :P
  min = Vector[ 1.0 / 0,  1.0 / 0]
  max = Vector[-1.0 / 0, -1.0 / 0]
  nodes.each do |atom|
    min[0] = min[0] > atom.x ? atom.x : min[0]
    max[0] = max[0] < atom.x ? atom.x : max[0]
    min[1] = min[1] > atom.y ? atom.y : min[1]
    max[1] = max[1] < atom.y ? atom.y : max[1]
  end

  diff = 1.0

  ratio = Vector[1.0, 1.0]

  if @fit_box
    if ((max[0] - min[0]) / (max[1] - min[1])) >
        (@size[0]  - @margin * 2)/ (@size[1] - @margin * 2)
      diff = (@size[0] - @margin * 2) / (max[0] - min[0])
      ratio[1] = @size[1] - @margin * 2 - (max[1] - min[1]) * diff
    else
      diff = (@size[1] - @margin * 2) / (max[1] - min[1])
      ratio[0] = @size[0] - @margin * 2 - (max[0] - min[1]) * diff
    end
  end
  [ratio, min]
end