Class: VORuby::STC::V1_10::Region::Constraint

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

Overview

An area on the unit sphere defined by the intersection with a plane

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ Constraint

Returns a new instance of Constraint.



559
560
561
562
563
# File 'lib/voruby/stc/1.10/region.rb', line 559

def initialize(options={})
  raise_argument_required_error('vector') if !options.has_key?(:vector)
  raise_argument_required_error('offset') if !options.has_key?(:offset)
  options.each { |key, value| send("#{key}=", value) }
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



557
558
559
# File 'lib/voruby/stc/1.10/region.rb', line 557

def offset
  @offset
end

#vectorObject

Returns the value of attribute vector.



557
558
559
# File 'lib/voruby/stc/1.10/region.rb', line 557

def vector
  @vector
end

Class Method Details

.from_xml(xml) ⇒ Object



607
608
609
610
611
612
613
614
615
616
# File 'lib/voruby/stc/1.10/region.rb', line 607

def self.from_xml(xml)
  root = element_from(xml)
  
  options = {
    :vector => Double3.from_xml(REXML::XPath.first(root, 'x:Vector', {'x' => obj_ns.uri})),
    :offset => Float(REXML::XPath.first(root, 'x:Offset', {'x' => obj_ns.uri}).text)
  }
  
  Constraint.new(options)
end

Instance Method Details

#==(c) ⇒ Object



584
585
586
587
# File 'lib/voruby/stc/1.10/region.rb', line 584

def ==(c)
  self.vector == c.vector and
  self.offset == c.offset
end

#to_sObject



603
604
605
# File 'lib/voruby/stc/1.10/region.rb', line 603

def to_s
  "#{self.vector} #{self.offset}"
end

#to_xml(name = nil) ⇒ Object



589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/voruby/stc/1.10/region.rb', line 589

def to_xml(name=nil)
  el = element(name)
  
  el.add_element(self.vector.to_xml('Vector', obj_ns))
  
  offset = REXML::Element.new("#{obj_ns.prefix}:Offset")
  offset.text = self.offset.to_s
  el.add_element(offset)
  
  collapse_namespaces(el)
  
  el
end