Class: JennCad::RoundCorner
- Inherits:
-
Object
- Object
- JennCad::RoundCorner
- Defined in:
- lib/jenncad/features/path.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#ccw ⇒ Object
Returns the value of attribute ccw.
-
#current_angle ⇒ Object
Returns the value of attribute current_angle.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#end_point ⇒ Object
Returns the value of attribute end_point.
-
#from ⇒ Object
Returns the value of attribute from.
-
#id ⇒ Object
Returns the value of attribute id.
-
#input_a ⇒ Object
Returns the value of attribute input_a.
-
#l ⇒ Object
Returns the value of attribute l.
-
#od ⇒ Object
Returns the value of attribute od.
-
#output_a ⇒ Object
Returns the value of attribute output_a.
-
#start_point ⇒ Object
Returns the value of attribute start_point.
-
#thing ⇒ Object
Returns the value of attribute thing.
Instance Method Summary collapse
-
#initialize(args) ⇒ RoundCorner
constructor
A new instance of RoundCorner.
- #margin ⇒ Object
- #normalize(angle) ⇒ Object
- #part ⇒ Object
- #positions ⇒ Object
- #set_angles(cur, total, direction) ⇒ Object
Constructor Details
#initialize(args) ⇒ RoundCorner
Returns a new instance of RoundCorner.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jenncad/features/path.rb', line 4 def initialize(args) @start_point = args[:start_point] @end_point = args[:end_point] @a = args[:a] @ccw = args[:ccw] || false @l = args[:l] @od = args[:od] @id = args[:id] @input_a = args[:input_a] || 0 @output_a = args[:output_a] || 0 thing = Marshal.load(args[:thing]) @thing_dia = thing.d || thing.y unless @thing_dia $log.error "ERROR: cannot find diameter or y of thing #{thing.inspect}" return end @angle = args[:angle] @current_angle = args[:current_angle] @direction = args[:direction] @to = args[:to] @from = args[:from] if @a < 0 @from = case @from when :left :right when :right :left when :top, :up :bottom when :down, :bottom :up else # // unimplemented @from end end end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def a @a end |
#angle ⇒ Object
Returns the value of attribute angle.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def angle @angle end |
#ccw ⇒ Object
Returns the value of attribute ccw.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def ccw @ccw end |
#current_angle ⇒ Object
Returns the value of attribute current_angle.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def current_angle @current_angle end |
#direction ⇒ Object
Returns the value of attribute direction.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def direction @direction end |
#end_point ⇒ Object
Returns the value of attribute end_point.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def end_point @end_point end |
#from ⇒ Object
Returns the value of attribute from.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def from @from end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def id @id end |
#input_a ⇒ Object
Returns the value of attribute input_a.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def input_a @input_a end |
#l ⇒ Object
Returns the value of attribute l.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def l @l end |
#od ⇒ Object
Returns the value of attribute od.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def od @od end |
#output_a ⇒ Object
Returns the value of attribute output_a.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def output_a @output_a end |
#start_point ⇒ Object
Returns the value of attribute start_point.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def start_point @start_point end |
#thing ⇒ Object
Returns the value of attribute thing.
3 4 5 |
# File 'lib/jenncad/features/path.rb', line 3 def thing @thing end |
Instance Method Details
#margin ⇒ Object
61 62 63 |
# File 'lib/jenncad/features/path.rb', line 61 def margin return @od end |
#normalize(angle) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/jenncad/features/path.rb', line 51 def normalize(angle) if angle < 0 angle += 360 end if angle >= 360 angle -= 360 end angle end |
#part ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/jenncad/features/path.rb', line 105 def part d = @thing_dia len = d * 2 + @id x = Math::sin((@a/180.0)*Math::PI)*len y = Math::cos((@a/180.0)*Math::PI)*len res = circle(d: len) res -= circle(d: @id) points = [[0,0]] points << [0, len] points << [x, y] res *= polygon(points:points) r, ox, oy, x, y = positions res = res.rotate(z: r).move(x: ox, y: oy) res = res.auto_extrude#.color("red") #res += slot(d: 1.2, y: len/2.0, h: 10).rotate(z: r_midpoint).color("red") #res += cylinder(d: 1, h: 10).move(x: x+ox,y: y+oy) #res.moveh(x: thing.yield.d, y: -thing.yield.d) res.move(x: @start_point[:x], y: @start_point[:y]) #res += cylinder(d: 1, h: 15).color("red").move(x: @start_point[:x], y: @start_point[:y]).move(z:-1) res end |
#positions ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/jenncad/features/path.rb', line 65 def positions td = @thing_dia l = td + @id l2 = td / 2.0 + @id / 2.0 r = 0 ox = 0 oy = 0 cr = 180 case @from when :left r = 0 oy = -l when :top, :up r = -90 ox = -l cr = 0 when :right r = 180 oy = l when :bottom, :down cr = 0 r = 90 ox = l # TODO: so this doesn't work yet, # need to figure out the maths to translate this when 0..360 r = 180-@from cr = @a end r2 = cr + r + @a # 180+@a x = - l2 * Math::sin((r2/180.0)*Math::PI) y = - l2 * Math::cos((r2/180.0)*Math::PI) return r, ox/2.0, oy/2.0, x, y end |
#set_angles(cur, total, direction) ⇒ Object
45 46 47 48 49 |
# File 'lib/jenncad/features/path.rb', line 45 def set_angles(cur, total, direction) @current_angle = cur @angle = normalize(total) @direction = direction end |