Class: DxfIO::Entity::Support::Point
- Inherits:
-
Object
- Object
- DxfIO::Entity::Support::Point
- Defined in:
- lib/dxf_io/entity/support/point.rb
Constant Summary collapse
- START_POINT_GROUP_NUMS =
DxfIO::Constants::START_POINT_GROUP_NUMS
- END_POINT_GROUP_NUMS =
DxfIO::Constants::END_POINT_GROUP_NUMS
- TYPES =
%i(start end).freeze
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #*(num) ⇒ Object
-
#+(point) ⇒ Object
binary.
- #-(point) ⇒ Object
-
#-@ ⇒ Object
unary.
- #/(num) ⇒ Object
-
#==(point) ⇒ Object
eq operations.
- #end? ⇒ Boolean
-
#initialize(x, y, options = {}) ⇒ Point
constructor
A new instance of Point.
- #rotate_180 ⇒ Object
-
#rotate_90 ⇒ Object
geometrical operation (supposed what point is a vector from zero).
- #start? ⇒ Boolean
- #to_a ⇒ Object
- #to_dxf_array ⇒ Object
- #to_h ⇒ Object
Constructor Details
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/dxf_io/entity/support/point.rb', line 10 def type @type end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
10 11 12 |
# File 'lib/dxf_io/entity/support/point.rb', line 10 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
10 11 12 |
# File 'lib/dxf_io/entity/support/point.rb', line 10 def y @y end |
Instance Method Details
#*(num) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/dxf_io/entity/support/point.rb', line 81 def *(num) if num.is_a? Numeric self.class.new(@x * num, @y * num, type: @type) else raise ArgumentError, 'argument must be Numeric' end end |
#+(point) ⇒ Object
binary
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dxf_io/entity/support/point.rb', line 57 def +(point) if point.is_a? self.class self.class.new(@x + point.x, @y + point.y, type: @type == point.type ? @type : :start) elsif point.is_a? Array self.class.new(@x + point[0], @y + point[1], type: @type) else raise ArgumentError, 'point must be an Array or a DxfIO::Entity::Support::Point' end end |
#-(point) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/dxf_io/entity/support/point.rb', line 71 def -(point) if point.is_a? self.class self - point elsif point.is_a? Array self + point.map(&:-@) else raise ArgumentError, 'point must be an Array or a DxfIO::Entity::Support::Point' end end |
#-@ ⇒ Object
unary
51 52 53 |
# File 'lib/dxf_io/entity/support/point.rb', line 51 def -@ self.class.new(-@x, -@y, type: @type) end |
#/(num) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/dxf_io/entity/support/point.rb', line 91 def /(num) if num.is_a? Numeric self.class.new(@x / num, @y / num, type: @type) else raise ArgumentError, 'argument must be Numeric' end end |
#==(point) ⇒ Object
eq operations
43 44 45 |
# File 'lib/dxf_io/entity/support/point.rb', line 43 def ==(point) to_a == point.to_a end |
#end? ⇒ Boolean
21 22 23 |
# File 'lib/dxf_io/entity/support/point.rb', line 21 def end? @type == :end end |
#rotate_180 ⇒ Object
107 108 109 |
# File 'lib/dxf_io/entity/support/point.rb', line 107 def rotate_180 -self end |
#rotate_90 ⇒ Object
geometrical operation (supposed what point is a vector from zero)
103 104 105 |
# File 'lib/dxf_io/entity/support/point.rb', line 103 def rotate_90 self.class.new(@y, -@x, type: @type) end |
#start? ⇒ Boolean
17 18 19 |
# File 'lib/dxf_io/entity/support/point.rb', line 17 def start? @type == :start end |
#to_a ⇒ Object
25 26 27 |
# File 'lib/dxf_io/entity/support/point.rb', line 25 def to_a [@x, @y] end |
#to_dxf_array ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/dxf_io/entity/support/point.rb', line 33 def to_dxf_array if start? [{START_POINT_GROUP_NUMS.first => @x}, {START_POINT_GROUP_NUMS.last => @y}] elsif end? [{END_POINT_GROUP_NUMS.first => @x}, {END_POINT_GROUP_NUMS.last => @y}] end end |
#to_h ⇒ Object
29 30 31 |
# File 'lib/dxf_io/entity/support/point.rb', line 29 def to_h {x: @x, y: @y} end |