class Mlr::Strategy::Python

Constants

SCRIPT

Public Class Methods

get_point(options) click to toggle source
# File lib/mlr/strategy/python.rb, line 15
def self.get_point(options)
  new(options).run
end
new(points:, mode: Mlr::MODE2D, solver: Mlr::SOLVER_LSE) click to toggle source
# File lib/mlr/strategy/python.rb, line 19
def initialize(points:, mode: Mlr::MODE2D, solver: Mlr::SOLVER_LSE)
  @points = points
  @mode = mode
  @solver = solver
end

Public Instance Methods

options() click to toggle source
# File lib/mlr/strategy/python.rb, line 33
def options
  {
    anchors: get_anchors,
    measures: get_measures,
    mode: get_mode,
    solver: get_solver
  }
end
run() click to toggle source
# File lib/mlr/strategy/python.rb, line 25
def run
  # run python script
  PyCall.exec(SCRIPT % options)

  # get result from python
  make_point(PyCall.eval('t.loc'))
end

Private Instance Methods

get_anchors() click to toggle source
# File lib/mlr/strategy/python.rb, line 81
def get_anchors
  @points.map.with_index do |point, index|
    "P.add_anchor('point_#{index}',(#{point.x},#{point.y},#{point.z}))"
  end.join(';')
end
get_measures() click to toggle source
# File lib/mlr/strategy/python.rb, line 87
def get_measures
  @points.map.with_index do |point, index|
    "t.add_measure('point_#{index}',#{point.distance})"
  end.join(';')
end
get_mode() click to toggle source
# File lib/mlr/strategy/python.rb, line 64
def get_mode
  case @mode
  when Mlr::MODE2D then '2D'
  when Mlr::MODE3D then '3D'
  else
    raise 'incompatible mode'
  end
end
get_solver() click to toggle source
# File lib/mlr/strategy/python.rb, line 73
def get_solver
  case @solver
  when Mlr::SOLVER_LSE then "LSE"
  else
    raise 'incompatible solver'
  end
end
make_point(point) click to toggle source
# File lib/mlr/strategy/python.rb, line 44
def make_point(point)
  case @mode
  when Mlr::MODE2D
    Mlr::ResultPoint2D.new(point.x, point.y)
  when Mlr::MODE3D
    Mlr::ResultPoint3D.new(point.x, point.y, point.z)
  else
    raise 'incompatible mode'
  end
end
result_point() click to toggle source
# File lib/mlr/strategy/python.rb, line 55
def result_point
  case @mode
  when Mlr::MODE2D then Mlr::ResultPoint2D
  when Mlr::MODE3D then Mlr::ResultPoint3D
  else
    raise 'incompatible mode'
  end
end