Class: EagleCAD::Geometry::Line
- Inherits:
-
Geometry::TwoPointLine
- Object
- Geometry::TwoPointLine
- EagleCAD::Geometry::Line
- Defined in:
- lib/eaglecad/geometry.rb
Instance Attribute Summary collapse
-
#cap ⇒ Object
Returns the value of attribute cap.
-
#curve ⇒ Object
Returns the value of attribute curve.
-
#line_width ⇒ Object
Returns the value of attribute line_width.
Class Method Summary collapse
-
.from_xml(element) ⇒ Object
Create a Line from an REXML::Element.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Line
constructor
A new instance of Line.
- #to_xml ⇒ REXML::Element
Constructor Details
#initialize(options = {}) ⇒ Line
Returns a new instance of Line.
49 50 51 52 53 54 |
# File 'lib/eaglecad/geometry.rb', line 49 def initialize(={}) @cap = .delete :cap @curve = .delete :curve @line_width = .delete(:line_width) super [:from], [:to] end |
Instance Attribute Details
#cap ⇒ Object
Returns the value of attribute cap.
41 42 43 |
# File 'lib/eaglecad/geometry.rb', line 41 def cap @cap end |
#curve ⇒ Object
Returns the value of attribute curve.
41 42 43 |
# File 'lib/eaglecad/geometry.rb', line 41 def curve @curve end |
#line_width ⇒ Object
Returns the value of attribute line_width.
41 42 43 |
# File 'lib/eaglecad/geometry.rb', line 41 def line_width @line_width end |
Class Method Details
.from_xml(element) ⇒ Object
Create a EagleCAD::Geometry::Line from an REXML::Element
45 46 47 |
# File 'lib/eaglecad/geometry.rb', line 45 def self.from_xml(element) self.new(from:Geometry.point_from(element, 'x1', 'y1'), to:Geometry::point_from(element, 'x2', 'y2'), line_width:element.attributes['width'].to_f, cap: element.attributes['cap'], curve: element.attributes['curve'].to_f) end |
Instance Method Details
#to_xml ⇒ REXML::Element
57 58 59 60 61 62 63 |
# File 'lib/eaglecad/geometry.rb', line 57 def to_xml REXML::Element.new('wire').tap do |element| element.add_attributes({'x1' => Geometry.format(first.x), 'y1' => Geometry.format(first.y), 'x2' => Geometry.format(last.x), 'y2' => Geometry.format(last.y), 'width' => line_width}) element.add_attribute('cap', cap) unless 'round' == cap element.add_attribute('curve', curve) unless 0 == curve end end |