Class: Autocad::Point3d
- Inherits:
-
Object
- Object
- Autocad::Point3d
- Defined in:
- lib/autocad/point3d.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Class Method Summary collapse
- .array_to_ole(ar) ⇒ Object
- .cartesian_to_polar(x, y) ⇒ Object
- .from_ole(ole) ⇒ Object
- .from_polar_degrees(r, a) ⇒ Object
- .polar_to_cartesian(r, a) ⇒ Object
-
.pts_to_array(pts) ⇒ Object
convert array of points to array of x,y coordinates array can be [ Point3d, Point3d, ..] array can be [ [x,y,z], [x,y,z], [x,y,z] ..] array can be [x,y, x1, y1, x2,y2, x3,y3] array can be [[x,y], [x2,y2], [x3,y3]] all coordinates are converted to float z coordinates are ignored.
- .zero ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #deconstruct ⇒ Object
- #deconstruct_keys ⇒ Object
- #distance_to(other) ⇒ Object
-
#initialize(_x = nil, _y = nil, _z = nil, x: _x, y: _y, z: _z) ⇒ Point3d
constructor
A new instance of Point3d.
- #to_a ⇒ Object
-
#to_acad_point(model_space = true) ⇒ Object
Autocad::Point.
- #to_ary ⇒ Object
- #to_cartesian ⇒ Object
- #to_ole ⇒ Object
- #to_s ⇒ Object
- #to_xy ⇒ Object
- #xy_bounds(other) ⇒ Object
Constructor Details
#initialize(_x = nil, _y = nil, _z = nil, x: _x, y: _y, z: _z) ⇒ Point3d
Returns a new instance of Point3d.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/autocad/point3d.rb', line 53 def initialize(_x = nil, _y = nil, _z = nil, x: _x, y: _y, z: _z) case [x, y, z] in [Point3d, y, z] @x = x.x @y = x.y @z = x.z in [Array, nil, nil] @x = x[0].to_f @y = x[1].to_f @z = x[2].to_f in [Float, Float, Float] @x = x @y = y @z = z else @x = x.to_f || 0.0 @y = y.to_f || 0.0 @z = z.to_f || 0.0 end end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
51 52 53 |
# File 'lib/autocad/point3d.rb', line 51 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
51 52 53 |
# File 'lib/autocad/point3d.rb', line 51 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
51 52 53 |
# File 'lib/autocad/point3d.rb', line 51 def z @z end |
Class Method Details
.array_to_ole(ar) ⇒ Object
46 47 48 |
# File 'lib/autocad/point3d.rb', line 46 def array_to_ole(ar) WIN32OLE::Variant.new(ar, WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8) end |
.cartesian_to_polar(x, y) ⇒ Object
11 12 13 14 15 |
# File 'lib/autocad/point3d.rb', line 11 def cartesian_to_polar(x, y) r = Math.sqrt(x * x + y * y) angle = Angle.radians(Math.atan2(y, x)) [r, angle] end |
.from_ole(ole) ⇒ Object
20 21 22 |
# File 'lib/autocad/point3d.rb', line 20 def from_ole(ole) new(ole.X, ole.Y, ole.Z) end |
.from_polar_degrees(r, a) ⇒ Object
17 18 |
# File 'lib/autocad/point3d.rb', line 17 def from_polar_degrees(r, a) end |
.polar_to_cartesian(r, a) ⇒ Object
24 25 |
# File 'lib/autocad/point3d.rb', line 24 def polar_to_cartesian(r, a) end |
.pts_to_array(pts) ⇒ Object
convert array of points to array of x,y coordinates array can be [ Point3d, Point3d, ..] array can be [ [x,y,z], [x,y,z], [x,y,z] ..] array can be [x,y, x1, y1, x2,y2, x3,y3] array can be [[x,y], [x2,y2], [x3,y3]] all coordinates are converted to float z coordinates are ignored
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/autocad/point3d.rb', line 35 def pts_to_array(pts) case pts.first when Point3d pts.flat_map(&:to_xy) when Array pts.flat_map { |pt| [pt[0].to_f, pt[1].to_f] } when Numeric pts.each_slice(2).flat_map { |x, y| [x.to_f, y.to_f] } end end |
.zero ⇒ Object
7 8 9 |
# File 'lib/autocad/point3d.rb', line 7 def zero new(0.0, 0.0, 0, 0) end |
Instance Method Details
#+(other) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/autocad/point3d.rb', line 75 def +(other) # : Point3d case other when Point3d self.class.new(x + other.x, y + other.y, z + other.z) when Array self.class.new(x + other[0], y + other[1]) end end |
#-(other) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/autocad/point3d.rb', line 105 def -(other) # : Point3d case other when Point3d self.class.new(x - other.x, y - other.y, z - other.z) when Array self.class.new(x - other[0], y - other[1]) end end |
#deconstruct ⇒ Object
90 91 92 |
# File 'lib/autocad/point3d.rb', line 90 def deconstruct [@x, @y, @z] end |
#deconstruct_keys ⇒ Object
95 96 97 |
# File 'lib/autocad/point3d.rb', line 95 def deconstruct_keys {x: @x, y: @y, z: @z} end |
#distance_to(other) ⇒ Object
84 85 86 87 |
# File 'lib/autocad/point3d.rb', line 84 def distance_to(other) pt2 = Point3d.new(other) Math.sqrt((x - pt2.x)**2 + (y - pt2.y)**2 + (z - pt2.z)**2) end |
#to_a ⇒ Object
139 140 141 |
# File 'lib/autocad/point3d.rb', line 139 def to_a [x, y, z] end |
#to_acad_point(model_space = true) ⇒ Object
Returns Autocad::Point.
120 121 122 123 124 125 126 127 |
# File 'lib/autocad/point3d.rb', line 120 def to_acad_point(model_space = true) ole = if model_space drawing.ModelSpace.AddPoint(x, y, z) else drawing.PaperSpace.AddPoint(x, y, z) end app.wrap(ole) end |
#to_ary ⇒ Object
100 101 102 |
# File 'lib/autocad/point3d.rb', line 100 def to_ary [x, y, z] end |
#to_cartesian ⇒ Object
143 144 |
# File 'lib/autocad/point3d.rb', line 143 def to_cartesian end |
#to_ole ⇒ Object
146 147 148 |
# File 'lib/autocad/point3d.rb', line 146 def to_ole WIN32OLE::Variant.new([x, y, z], WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8) end |
#to_s ⇒ Object
134 135 136 |
# File 'lib/autocad/point3d.rb', line 134 def to_s "Point3d(#{x}, #{y}, #{z})" end |
#to_xy ⇒ Object
114 115 116 |
# File 'lib/autocad/point3d.rb', line 114 def to_xy [x, y] end |
#xy_bounds(other) ⇒ Object
129 130 131 132 |
# File 'lib/autocad/point3d.rb', line 129 def xy_bounds(other) x2, y2 = Points3d.new(other).to_xy [x, y, x2, y, x2, y2, x, y2, x, y] end |