Class: NSWTopo::Labels::Label

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nswtopo/layer/labels.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, barrier_count, 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, barrier_count, priority, hulls, attributes, elements, along, fixed
  @ordinal = [@barrier_count, @priority]
  @conflicts = Set.new
end

Instance Attribute Details

#alongObject (readonly)

Returns the value of attribute along.



308
309
310
# File 'lib/nswtopo/layer/labels.rb', line 308

def along
  @along
end

#barrier_countObject (readonly)

Returns the value of attribute barrier_count.



308
309
310
# File 'lib/nswtopo/layer/labels.rb', line 308

def barrier_count
  @barrier_count
end

#conflictsObject (readonly)

Returns the value of attribute conflicts.



308
309
310
# File 'lib/nswtopo/layer/labels.rb', line 308

def conflicts
  @conflicts
end

#elementsObject (readonly)

Returns the value of attribute elements.



308
309
310
# File 'lib/nswtopo/layer/labels.rb', line 308

def elements
  @elements
end

#feature_indexObject (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

#fixedObject (readonly)

Returns the value of attribute fixed.



308
309
310
# File 'lib/nswtopo/layer/labels.rb', line 308

def fixed
  @fixed
end

#hullsObject (readonly)

Returns the value of attribute hulls.



308
309
310
# File 'lib/nswtopo/layer/labels.rb', line 308

def hulls
  @hulls
end

#indicesObject (readonly)

Returns the value of attribute indices.



307
308
309
# File 'lib/nswtopo/layer/labels.rb', line 307

def indices
  @indices
end

#label_indexObject (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

#ordinalObject

Returns the value of attribute ordinal.



309
310
311
# File 'lib/nswtopo/layer/labels.rb', line 309

def ordinal
  @ordinal
end

#priorityObject

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

Returns:

  • (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

Returns:

  • (Boolean)


315
316
317
# File 'lib/nswtopo/layer/labels.rb', line 315

def barriers?
  @barrier_count > 0
end

#boundsObject



334
335
336
# File 'lib/nswtopo/layer/labels.rb', line 334

def bounds
  @hulls.flatten(1).transpose.map(&:minmax)
end

#coexists_with?(other) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


319
320
321
# File 'lib/nswtopo/layer/labels.rb', line 319

def optional?
  @attributes["optional"]
end

#point?Boolean

Returns:

  • (Boolean)


311
312
313
# File 'lib/nswtopo/layer/labels.rb', line 311

def point?
  @along.nil?
end