Class: NSWTopo::Labels::Label
- Inherits:
-
Object
- Object
- NSWTopo::Labels::Label
- Extended by:
- Forwardable
- Defined in:
- lib/nswtopo/layer/labels.rb
Instance Attribute Summary collapse
-
#along ⇒ Object
readonly
Returns the value of attribute along.
-
#barrier_count ⇒ Object
readonly
Returns the value of attribute barrier_count.
-
#conflicts ⇒ Object
readonly
Returns the value of attribute conflicts.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#feature_index ⇒ Object
readonly
Returns the value of attribute feature_index.
-
#fixed ⇒ Object
readonly
Returns the value of attribute fixed.
-
#hulls ⇒ Object
readonly
Returns the value of attribute hulls.
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
-
#label_index ⇒ Object
readonly
Returns the value of attribute label_index.
-
#ordinal ⇒ Object
Returns the value of attribute ordinal.
-
#priority ⇒ Object
Returns the value of attribute priority.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #barriers? ⇒ Boolean
- #bounds ⇒ Object
- #coexists_with?(other) ⇒ Boolean
-
#initialize(collection, label_index, feature_index, barrier_count, priority, hulls, attributes, elements, along = nil, fixed = nil) ⇒ Label
constructor
A new instance of Label.
- #optional? ⇒ Boolean
- #point? ⇒ Boolean
Constructor Details
#initialize(collection, label_index, feature_index, barrier_count, priority, hulls, attributes, elements, along = nil, fixed = nil) ⇒ Label
Returns a new instance of Label.
296 297 298 299 300 301 |
# File 'lib/nswtopo/layer/labels.rb', line 296 def initialize(collection, label_index, feature_index, , priority, hulls, attributes, elements, along = nil, fixed = nil) @label_index, @feature_index, @indices = label_index, feature_index, [label_index, feature_index] @collection, @barrier_count, @priority, @hulls, @attributes, @elements, @along, @fixed = collection, , priority, hulls, attributes, elements, along, fixed @ordinal = [@barrier_count, @priority] @conflicts = Set.new end |
Instance Attribute Details
#along ⇒ Object (readonly)
Returns the value of attribute along.
308 309 310 |
# File 'lib/nswtopo/layer/labels.rb', line 308 def along @along end |
#barrier_count ⇒ Object (readonly)
Returns the value of attribute barrier_count.
308 309 310 |
# File 'lib/nswtopo/layer/labels.rb', line 308 def @barrier_count end |
#conflicts ⇒ Object (readonly)
Returns the value of attribute conflicts.
308 309 310 |
# File 'lib/nswtopo/layer/labels.rb', line 308 def conflicts @conflicts end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
308 309 310 |
# File 'lib/nswtopo/layer/labels.rb', line 308 def elements @elements end |
#feature_index ⇒ Object (readonly)
Returns the value of attribute feature_index.
307 308 309 |
# File 'lib/nswtopo/layer/labels.rb', line 307 def feature_index @feature_index end |
#fixed ⇒ Object (readonly)
Returns the value of attribute fixed.
308 309 310 |
# File 'lib/nswtopo/layer/labels.rb', line 308 def fixed @fixed end |
#hulls ⇒ Object (readonly)
Returns the value of attribute hulls.
308 309 310 |
# File 'lib/nswtopo/layer/labels.rb', line 308 def hulls @hulls end |
#indices ⇒ Object (readonly)
Returns the value of attribute indices.
307 308 309 |
# File 'lib/nswtopo/layer/labels.rb', line 307 def indices @indices end |
#label_index ⇒ Object (readonly)
Returns the value of attribute label_index.
307 308 309 |
# File 'lib/nswtopo/layer/labels.rb', line 307 def label_index @label_index end |
#ordinal ⇒ Object
Returns the value of attribute ordinal.
309 310 311 |
# File 'lib/nswtopo/layer/labels.rb', line 309 def ordinal @ordinal end |
#priority ⇒ Object
Returns the value of attribute priority.
309 310 311 |
# File 'lib/nswtopo/layer/labels.rb', line 309 def priority @priority end |
Class Method Details
.overlaps(labels, &block) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/nswtopo/layer/labels.rb', line 345 def self.overlaps(labels, &block) Enumerator.new do |yielder| next unless labels.any?(&block) index = RTree.load(labels, &:bounds) index.each do |bounds, label| next unless buffer = yield(label) index.search(bounds, buffer: buffer).with_object(label).select do |other, label| overlaps? label, other, buffer: buffer end.inject(yielder, &:<<) end end end |
.overlaps?(label1, label2, buffer:) ⇒ Boolean
338 339 340 341 342 343 |
# File 'lib/nswtopo/layer/labels.rb', line 338 def self.overlaps?(label1, label2, buffer:) return false if label1 == label2 [label1, label2].map(&:hulls).inject(&:product).any? do |hulls| hulls.overlap?(buffer) end end |
Instance Method Details
#<=>(other) ⇒ Object
327 328 329 |
# File 'lib/nswtopo/layer/labels.rb', line 327 def <=>(other) self.ordinal <=> other.ordinal end |
#barriers? ⇒ Boolean
315 316 317 |
# File 'lib/nswtopo/layer/labels.rb', line 315 def @barrier_count > 0 end |
#bounds ⇒ Object
334 335 336 |
# File 'lib/nswtopo/layer/labels.rb', line 334 def bounds @hulls.flatten(1).transpose.map(&:minmax) end |
#coexists_with?(other) ⇒ Boolean
323 324 325 |
# File 'lib/nswtopo/layer/labels.rb', line 323 def coexists_with?(other) Array(@attributes["coexist"]).include? other.layer_name end |
#optional? ⇒ Boolean
319 320 321 |
# File 'lib/nswtopo/layer/labels.rb', line 319 def optional? @attributes["optional"] end |
#point? ⇒ Boolean
311 312 313 |
# File 'lib/nswtopo/layer/labels.rb', line 311 def point? @along.nil? end |