Class: VORuby::STC::V1_30::Curve2Type

Inherits:
Object
  • Object
show all
Includes:
SerializableToXml
Defined in:
lib/voruby/stc/1.30/stc.rb

Overview

A curve in 2-D space, defined by its end points and a shape attribute (default: line or great circle).

Direct Known Subclasses

Curve2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(p1, p2, curve_shape = 'line') ⇒ Curve2Type

Returns a new instance of Curve2Type.



1225
1226
1227
1228
1229
# File 'lib/voruby/stc/1.30/stc.rb', line 1225

def initialize(p1, p2, curve_shape='line')
  self.p1 = p1
  self.p2 = p2
  self.curve_shape = curve_shape || 'line'
end

Instance Attribute Details

#curve_shapeObject

Returns the value of attribute curve_shape.



1223
1224
1225
# File 'lib/voruby/stc/1.30/stc.rb', line 1223

def curve_shape
  @curve_shape
end

#p1Object

Returns the value of attribute p1.



1223
1224
1225
# File 'lib/voruby/stc/1.30/stc.rb', line 1223

def p1
  @p1
end

#p2Object

Returns the value of attribute p2.



1223
1224
1225
# File 'lib/voruby/stc/1.30/stc.rb', line 1223

def p2
  @p2
end

Class Method Details

.from_xml(xml) ⇒ Object



1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
# File 'lib/voruby/stc/1.30/stc.rb', line 1268

def self.from_xml(xml)
  root = element_from(xml)
  
  p1_el = REXML::XPath.first(root, 'x:P1', {'x' => obj_ns.uri})
  p2_el = REXML::XPath.first(root, 'x:P2', {'x' => obj_ns.uri})
  curve_shape = root.attributes.get_attribute_ns(obj_ns.uri, 'curve_shape')
  
  self.new(
    p1_el ? Double2Type.from_xml(p1_el) : nil,
    p2_el ? Double2Type.from_xml(p2_el) : nil,
    curve_shape ? curve_shape.value : nil
  )
end

Instance Method Details

#==(c) ⇒ Object



1251
1252
1253
1254
1255
# File 'lib/voruby/stc/1.30/stc.rb', line 1251

def ==(c)
  self.p1 == c.p1 and
  self.p2 == c.p2 and
  self.curve_shape == c.curve_shape
end

#to_xml(name = nil) ⇒ Object



1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'lib/voruby/stc/1.30/stc.rb', line 1257

def to_xml(name=nil)
  el = element(name)
  
  el.add_element(self.p1.to_xml('P1')) if self.p1
  el.add_element(self.p2.to_xml('P2')) if self.p2
  el.attributes["#{obj_ns.prefix}:curve_shape"] = self.curve_shape if self.curve_shape
  
  collapse_namespaces(el)
  el
end