class SolidRuby::Primitives::Cube

Attributes

x[RW]
y[RW]
z[RW]

Public Class Methods

new(args={}, y = nil, z = nil) click to toggle source
Calls superclass method
# File lib/solidruby/primitives/cube.rb, line 20
def initialize(args={}, y = nil, z = nil)
  if args.is_a? Array
    args = { x: args[0], y: args[1], z: args[2] }
  elsif args.is_a?(Hash) && args[:size]
    args[:x] ||= args[:size][0] || 0
    args[:y] ||= args[:size][1] || 0
    args[:z] ||= args[:size][2] || 0
  elsif args.is_a? Numeric
    x = args
    y ||= x
    z ||= y# = x if y.nil? && z.nil?
    args = { x: x, y: y, z: z }
  end
  @centered = args.delete(:center) || args.delete(:c)

  @x = args[:x]
  @y = args[:y] || @x
  @z = args[:z] || @y
  super(args)
end

Public Instance Methods

center() click to toggle source
# File lib/solidruby/primitives/cube.rb, line 61
def center
  @centered = true
  self
end
center_x() click to toggle source
# File lib/solidruby/primitives/cube.rb, line 46
def center_x
  @transformations << Translate.new(x: -@x / 2.0)
  self
end
center_xy() click to toggle source
# File lib/solidruby/primitives/cube.rb, line 41
def center_xy
  @transformations << Translate.new(x: -@x / 2.0, y: -@y / 2.0)
  self
end
center_y() click to toggle source
# File lib/solidruby/primitives/cube.rb, line 51
def center_y
  @transformations << Translate.new(y: -@y / 2.0)
  self
end
center_z() click to toggle source
# File lib/solidruby/primitives/cube.rb, line 56
def center_z
  @transformations << Translate.new(z: -@z / 2.0)
  self
end
centered?() click to toggle source
# File lib/solidruby/primitives/cube.rb, line 66
def centered?
  @centered
end
chamfer(args = {}) click to toggle source
# File lib/solidruby/primitives/cube.rb, line 70
def chamfer(args = {})
  faces = normalise_edges(args)
  height = args[:h] || args[:height]
  trans = translations_for_edge(onto: self, faces: faces, x: @x, y: @y, z: @z)
  res = self
  trans.each do |t|
    res -= Helpers::chamfer(l: t[:length] + 0.02, h: height)
      .rotate(z: (t[:z_rot] - 180))
      .rotate(x: t[:x_rot], y: t[:y_rot])
      .translate(x: t[:x_trans], y: t[:y_trans], z: t[:z_trans])
  end
  res
end
fillet(args = {}) click to toggle source
# File lib/solidruby/primitives/cube.rb, line 94
def fillet(args = {})
  faces = normalise_edges(args)
  radius = args[:r] || args[:radiusg]
  trans = translations_for_edge(onto: self, faces: faces, x: @x, y: @y, z: @z, tolerance: 0)
  res = self
  trans.each do |t|
    res -= Helpers::fillet(h: t[:length], r: radius)
      .rotate(z: t[:z_rot])
      .rotate(x: t[:x_rot], y: t[:y_rot])
      .translate(x: t[:x_trans], y: t[:y_trans], z: t[:z_trans])
  end
  res
end
get_point_on(args = {}) click to toggle source
# File lib/solidruby/primitives/cube.rb, line 84
def get_point_on(args = {})
  args[:x] = @x
  args[:y] = @y
  args[:z] = @z
  args[:centered] = @centered
  args[:centered_z] = @centered
  args[:transformations] = @transformations
  calculate_point_on(args)
end
to_rubyscad() click to toggle source
# File lib/solidruby/primitives/cube.rb, line 108
def to_rubyscad
  args = { size: [@x, @y, @z] }
  args[:center] = @centered if @centered
  RubyScadBridge.new.cube(args)
end