Class: VORuby::STC::V1_10::Region::ConvexType

Inherits:
Shape show all
Defined in:
lib/voruby/stc/1.10/region.rb

Overview

A convex polygon defined by one or more Constraints

Direct Known Subclasses

Convex

Instance Attribute Summary collapse

Attributes inherited from Shape

#coord_system_id, #unit

Attributes inherited from RegionType

#note

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Methods inherited from RegionType

#fill_factor, #fill_factor=

Constructor Details

#initialize(options = {}) ⇒ ConvexType

Returns a new instance of ConvexType.



630
631
632
633
# File 'lib/voruby/stc/1.10/region.rb', line 630

def initialize(options={})
  raise_argument_required_error('list of constraints') if !options.has_key?(:constraints)
  super(options)
end

Instance Attribute Details

#constraintsObject

Returns the value of attribute constraints.



626
627
628
# File 'lib/voruby/stc/1.10/region.rb', line 626

def constraints
  @constraints
end

Class Method Details

.from_xml(xml) ⇒ Object



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/voruby/stc/1.10/region.rb', line 660

def self.from_xml(xml)
  root = element_from(xml)
  
  fill_factor = root.attributes.get_attribute_ns(obj_ns.uri, 'fill_factor')
  note = root.attributes.get_attribute_ns(obj_ns.uri, 'note')
  options = {
    :fill_factor => fill_factor ? Float(fill_factor.value) : nil,
    :note => note ? note.value : nil,
    :coord_system_id => IdRef.new(root.attributes.get_attribute_ns(obj_ns.uri, 'coord_system_id').value),
    :constraints => REXML::XPath.match(root, 'x:Constraint', {'x' => obj_ns.uri}).collect{ |c| Constraint.from_xml(c) }
  }
  unit = root.attributes.get_attribute_ns(obj_ns.uri, 'unit')
  options[:unit] = PosUnit.new(unit.value) if unit
  
  self.new(options)
end

.xml_typeObject



628
# File 'lib/voruby/stc/1.10/region.rb', line 628

def self.xml_type; 'convexType' end

Instance Method Details

#==(c) ⇒ Object



644
645
646
647
# File 'lib/voruby/stc/1.10/region.rb', line 644

def ==(c)
  super(c) and
  self.constraints == c.constraints
end

#to_sObject



656
657
658
# File 'lib/voruby/stc/1.10/region.rb', line 656

def to_s
  "CONVEX #{self.coord_system_id} #{self.constraints.collect{ |c| c.to_s }.join(' ') }"
end

#to_xml(name = nil) ⇒ Object



649
650
651
652
653
654
# File 'lib/voruby/stc/1.10/region.rb', line 649

def to_xml(name=nil)
  el = super(name)
  self.constraints.each { |c| el.add_element(c.to_xml('Constraint')) }
  collapse_namespaces(el)
  el
end