Class: EagleCAD::Geometry::Line

Inherits:
Geometry::TwoPointLine
  • Object
show all
Defined in:
lib/eaglecad/geometry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
		@cap = options.delete :cap
		@curve = options.delete :curve
		@line_width = options.delete(:line_width)
		super options[:from], options[:to]
end

Instance Attribute Details

#capObject

Returns the value of attribute cap.



41
42
43
# File 'lib/eaglecad/geometry.rb', line 41

def cap
  @cap
end

#curveObject

Returns the value of attribute curve.



41
42
43
# File 'lib/eaglecad/geometry.rb', line 41

def curve
  @curve
end

#line_widthObject

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

Parameters:

  • element (Element)

    The REXML::Element to parse



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_xmlREXML::Element

Returns:

  • (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