Module: SolidRuby::Primitives

Included in:
SolidRuby
Defined in:
lib/solidruby/primitives/cube.rb,
lib/solidruby/primitives/text.rb,
lib/solidruby/primitives/circle.rb,
lib/solidruby/primitives/import.rb,
lib/solidruby/primitives/render.rb,
lib/solidruby/primitives/sphere.rb,
lib/solidruby/primitives/square.rb,
lib/solidruby/primitives/polygon.rb,
lib/solidruby/primitives/surface.rb,
lib/solidruby/primitives/cylinder.rb,
lib/solidruby/primitives/primitive.rb,
lib/solidruby/primitives/polyhedron.rb

Overview

This file is part of SolidRuby.

SolidRuby is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SolidRuby is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SolidRuby.  If not, see <http://www.gnu.org/licenses/>.

Defined Under Namespace

Classes: Circle, Cube, Cylinder, Import, Polygon, Polyhedron, Primitive, Render, Sphere, Square, Surface, Text

Instance Method Summary collapse

Instance Method Details

#circle(args) ⇒ Object



23
24
25
# File 'lib/solidruby/primitives/circle.rb', line 23

def circle(args)
  Circle.new(args)
end

#cube(args = {}, y = nil, z = nil) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/solidruby/primitives/cube.rb', line 125

def cube(args = {}, y = nil, z = nil)
  if args.is_a? Numeric
    args = {x: args}
    args[:y] = y if y
    args[:z] = z if z
  end
  Cube.new(args)
end

#cylinder(args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/solidruby/primitives/cylinder.rb', line 45

def cylinder(args)
  # inner diameter handling
  if args[:id]
    id = args.delete(:id)
    args2 = args.dup
    args2[:d] = id

    if args[:ih]
      # if it has an inner height, add a tiny bit to the bottom
      ih = args.delete(:ih)
      args2[:h] = ih + 0.01
    else
      # otherwise add to both bottom and top to make a clear cut in OpenSCAD
      args2[:h] += 0.02
    end

    # if we have a ifn value, change the fn value of the inner cut
    if args[:ifn]
      ifn = args.delete(:ifn)
      args2[:fn] = ifn
    end

    return cylinder(args) - cylinder(args2).translate(z: -0.01)
  end

  Cylinder.new(args)
end

#import(args) ⇒ Object



38
39
40
# File 'lib/solidruby/primitives/import.rb', line 38

def import(args)
  Import.new(args)
end

#polygon(args) ⇒ Object



23
24
25
# File 'lib/solidruby/primitives/polygon.rb', line 23

def polygon(args)
  Polygon.new(args)
end

#polyhedron(args) ⇒ Object



27
28
29
# File 'lib/solidruby/primitives/polyhedron.rb', line 27

def polyhedron(args)
  Polyhedron.new(args)
end

#render(args = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/solidruby/primitives/render.rb', line 41

def render(args = {})
  if args.is_a? SolidRubyObject
    Render.new(args)
  else
    Render.new(self, args)
  end
end

#sphere(args) ⇒ Object



43
44
45
46
47
48
# File 'lib/solidruby/primitives/sphere.rb', line 43

def sphere(args)
  if args.is_a? Numeric
    args = {r: args}
  end
  Sphere.new(args)
end

#square(args, y = nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/solidruby/primitives/square.rb', line 80

def square(args, y = nil)
  if args.is_a?(Numeric) && !!y == y
    args = { size: args, center: y}
  elsif args.is_a?(Numeric) && y.is_a?(Numeric)
    args = { size: [args, y] }
  end
  Square.new(args)
end

#surface(args) ⇒ Object



41
42
43
# File 'lib/solidruby/primitives/surface.rb', line 41

def surface(args)
  Surface.new(args)
end

#text(args = {}) ⇒ Object



40
41
42
# File 'lib/solidruby/primitives/text.rb', line 40

def text(args = {})
  Text.new(args)
end