Class: When::Parts::GeometricComplex
- Inherits:
-
Range
- Object
- Range
- When::Parts::GeometricComplex
- Includes:
- Comparable
- Defined in:
- lib/when_exe/parts/geometric_complex.rb
Overview
任意個の端点から構成する [Range] の subclass
Instance Attribute Summary collapse
-
#node ⇒ Array<Array<Comparable, Boolean>>
readonly
When::Parts::GeometricComplex を構成する端点の Array.
-
#reverse ⇒ Boolean
readonly
範囲の反転.
Instance Method Summary collapse
-
#-@ ⇒ When::Parts::GeometricComplex
範囲を反転する.
-
#<=>(other) ⇒ Integer
最小の端点と other を比較する.
-
#_include?(other) ⇒ Boolean
Enumerator._exclude 専用.
-
#exclude_end?(index = -1)) ⇒ Boolean
端点が範囲に含まれるか?.
-
#first(default = nil) ⇒ Comparable
(also: #begin)
最小の端点.
-
#include?(other) ⇒ Boolean
(also: #===)
範囲に含まれるか?.
-
#initialize(*args) ⇒ GeometricComplex
constructor
オブジェクトの生成.
-
#last(default = nil) ⇒ Comparable
(also: #end)
最大の端点.
-
#precision ⇒ Integer
分解能.
-
#to_tm_object(options = {}) ⇒ When::TM::Node, ...
ISO19108 の TM オブジェクトに変換する.
-
#|(other) ⇒ When::Parts::GeometricComplex
和集合.
Constructor Details
#initialize(range, reverse = false) ⇒ GeometricComplex #initialize(point, reverse = false) ⇒ GeometricComplex #initialize(first, last, reverse = false) ⇒ GeometricComplex #initialize(first, duration, reverse = false) ⇒ GeometricComplex #initialize(other, reverse = false) ⇒ GeometricComplex #initialize(node, reverse = false) ⇒ GeometricComplex
すべての呼び出しパターンに共通の最終引数 reverse を付けることができる
reverse [Boolean]
true - 反転する
false - 反転しない
オブジェクトの生成
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 252 def initialize(*args) @reverse = (args[-1]==true || args[-1]==false) ? args.pop : false case args[0] when GeometricComplex @node = args[0].node @reverse ^= args[0].reverse super(self.first, self.last, exclude_end?) if self.first && self.last return when Array @node = args[0] super(self.first, self.last, exclude_end?) if self.first && self.last return when Range first = [args[0].first, true] last = [args[0].last, !args[0].exclude_end?] when Comparable first, last, rest = args raise ArgumentError, "Too many argument: #{rest}" if rest first = [first, true] case last when Comparable ; last = [last, false] when When::TM::Duration ; last = [first[0] + last, false] when nil ; last = first else ; raise TypeError, "Irregal GeometricComplex Type for last element: #{last.class}" end when nil ; else ; raise TypeError, "Irregal GeometricComplex Type: #{first.class}" end first, last = last, first if (first && last && first[0] > last[0]) @node = [] @node << first if first @node << last if last super(self.first, self.last, exclude_end?) if first && last end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
その他のメソッド
When::Parts::GeometricComplex で定義されていないメソッドは
処理を first (type: When::TM::(Temporal)Position) に委譲する
375 376 377 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 375 def method_missing(name, *args, &block) first.send(name.to_sym, *args, &block) end |
Instance Attribute Details
#node ⇒ Array<Array<Comparable, Boolean>> (readonly)
When::Parts::GeometricComplex を構成する端点の Array
45 46 47 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 45 def node @node end |
#reverse ⇒ Boolean (readonly)
無限の過去(-Infinity)を範囲に含むか否かと同値である
範囲の反転
28 29 30 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 28 def reverse @reverse end |
Instance Method Details
#-@ ⇒ When::Parts::GeometricComplex
範囲を反転する
115 116 117 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 115 def -@ GeometricComplex.new(self, true) end |
#<=>(other) ⇒ Integer
最小の端点と other を比較する
125 126 127 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 125 def <=>(other) first <=> other end |
#_include?(other) ⇒ Boolean
Enumerator._exclude 専用
203 204 205 206 207 208 209 210 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 203 def _include?(other) if (other.kind_of?(Comparable) && !other.kind_of?(GeometricComplex)) return _include_point?(other) else other = GeometricComplex.new(other) unless other.kind_of?(GeometricComplex) return _include_range?(other) && _include_point?(other.first) end end |
#exclude_end?(index = -1)) ⇒ Boolean
端点が範囲に含まれるか?
96 97 98 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 96 def exclude_end?(index=-1) (@node.length==0) ? nil : !@node[index][1] ^ @reverse end |
#first(default = nil) ⇒ Comparable Also known as: begin
含むか否かに関わらず、最小の端点を返す。 default が指定されているが有効な区間がない場合、nil を返す。
最小の端点
57 58 59 60 61 62 63 64 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 57 def first(default=nil) return (@node.length==0) ? nil : @node[0][0] unless default # 互換性 if reverse return default else (@node.length==0) ? nil : @node[0][0] end end |
#include?(other) ⇒ Boolean Also known as: ===
制限事項 When::TM::TopologicalComplex どうしの包含判定は、和集合がもとの範囲と等しいか で判断している。分解能が When::SYSTEM でない場合、論理的には等しいものが、 内部表現が異なるために等しくないとみなされる事があり、その場合 true であるべき ものを false と誤判断する。実行速度上の制約もあり、現時点では対策しない。
範囲に含まれるか?
191 192 193 194 195 196 197 198 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 191 def include?(other) if (other.kind_of?(Comparable) && !other.kind_of?(GeometricComplex)) return (_include_point?(other) != false) else other = GeometricComplex.new(other) unless other.kind_of?(GeometricComplex) return _include_range?(other) end end |
#last(default = nil) ⇒ Comparable Also known as: end
含むか否かに関わらず、最大の端点を返す default が指定されているが有効な区間がない場合、nil を返す
最大の端点
77 78 79 80 81 82 83 84 85 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 77 def last(default=nil) return (@node.length==0) ? nil : @node[-1][0] unless default # 互換性 if reverse return (@node.length[0]==0) ? default : @node[-1][0] else return nil if (@node.length==0) return (@node.length[0]==1) ? default : @node[-1][0] end end |
#precision ⇒ Integer
分解能がない場合は、When::SYSTEM を返す
分解能
107 108 109 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 107 def precision @node[0] && @node[0][0].respond_to?(:precision) ? @node[0][0].precision : Coordinates::SYSTEM end |
#to_tm_object(options = {}) ⇒ When::TM::Node, ...
ISO19108 の TM オブジェクトに変換する
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 160 def to_tm_object(={}) return nil unless !@reverse && @node.length>0 && @node.length[0]==0 objects = [] primitives = @node.dup while (primitives) do first, last, primitives = primitives if (first[0].eql?(last[0])) objects = When::TM::Node.new(When::TM::Instant.new(When.when?(first[0],))) else objects = When::TM::Edge.new(When::TM::Node.new(When::TM::Instant.new(When.when?(first[0],))), When::TM::Node.new(When::TM::Instant.new(When.when?(last[0],)))) end end return objects[0] if objects.length==1 return When::TM::TopologicalComplex.new(objects) end |
#|(other) ⇒ When::Parts::GeometricComplex
和集合
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/when_exe/parts/geometric_complex.rb', line 135 def |(other) other = GeometricComplex.new(other) unless other.kind_of?(GeometricComplex) return self if self.reverse && self.node.length==0 return other | self if !self.reverse && other.reverse copy = self.node.dup ref = other.node.dup max = _max(copy.shift.dup, ref.shift.dup) if (other.reverse) rev = max ? false : @reverse while (ref.length > 0) do first, last, *ref = ref updated = _upper(copy, first, rev) updated += _lower(copy, last, rev) if last copy = updated end copy = _lower(copy, max, true) if max return GeometricComplex.new(copy, self.reverse) end |