Class: Legion::Extensions::Agentic::Integration::Tessellation::Helpers::Mosaic
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Tessellation::Helpers::Mosaic
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb
Constant Summary
Constants included
from Constants
Constants::COVERAGE_DECAY, Constants::COVERAGE_GROWTH, Constants::COVERAGE_LABELS, Constants::DEFAULT_COVERAGE, Constants::DENSITY_LABELS, Constants::DOMAINS, Constants::FIT_LABELS, Constants::FIT_TOLERANCE, Constants::FULL_COVERAGE_THRESHOLD, Constants::GAP_THRESHOLD, Constants::MAX_MOSAICS, Constants::MAX_TILES, Constants::OVERLAP_PENALTY, Constants::OVERLAP_THRESHOLD, Constants::TILE_SHAPES, Constants::TILE_TYPES
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Constants
label_for
Constructor Details
#initialize(domain:) ⇒ Mosaic
Returns a new instance of Mosaic.
14
15
16
17
18
19
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 14
def initialize(domain:)
@id = SecureRandom.uuid
@domain = domain.to_sym
@tiles = []
@created_at = Time.now.utc
end
|
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
12
13
14
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 12
def created_at
@created_at
end
|
#domain ⇒ Object
Returns the value of attribute domain.
12
13
14
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 12
def domain
@domain
end
|
#id ⇒ Object
Returns the value of attribute id.
12
13
14
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 12
def id
@id
end
|
#tiles ⇒ Object
Returns the value of attribute tiles.
12
13
14
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 12
def tiles
@tiles
end
|
Instance Method Details
#add_tile(tile) ⇒ Object
21
22
23
24
25
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 21
def add_tile(tile)
@tiles << tile
auto_connect(tile)
tile
end
|
#average_fit ⇒ Object
34
35
36
37
38
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 34
def average_fit
return 0.0 if @tiles.empty?
(@tiles.sum(&:fit_score) / @tiles.size).round(10)
end
|
#coherence ⇒ Object
45
46
47
48
49
50
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 45
def coherence
return 0.0 if @tiles.empty?
connected = @tiles.count(&:well_connected?)
(connected.to_f / @tiles.size).round(10)
end
|
#complete? ⇒ Boolean
43
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 43
def complete? = total_coverage >= FULL_COVERAGE_THRESHOLD
|
#gap_count ⇒ Object
40
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 40
def gap_count = @tiles.count(&:gapped?)
|
#isolated_count ⇒ Object
42
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 42
def isolated_count = @tiles.count(&:isolated?)
|
#seamless_count ⇒ Object
41
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 41
def seamless_count = @tiles.count(&:seamless?)
|
#to_h ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 61
def to_h
{
id: @id,
domain: @domain,
tile_count: @tiles.size,
total_coverage: total_coverage,
average_fit: average_fit,
coherence: coherence,
uniformity: uniformity,
gaps: gap_count,
seamless: seamless_count,
complete: complete?
}
end
|
#total_coverage ⇒ Object
27
28
29
30
31
32
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 27
def total_coverage
return 0.0 if @tiles.empty?
raw = @tiles.sum(&:effective_coverage) / @tiles.size
raw.clamp(0.0, 1.0).round(10)
end
|
52
53
54
55
56
57
58
59
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb', line 52
def uniformity
return 1.0 if @tiles.size <= 1
coverages = @tiles.map(&:coverage)
mean = coverages.sum / coverages.size
variance = coverages.sum { |c| (c - mean)**2 } / coverages.size
(1.0 - Math.sqrt(variance)).clamp(0.0, 1.0).round(10)
end
|