Class: Legion::Extensions::Agentic::Attention::Lens::Helpers::Lens

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/attention/lens/helpers/lens.rb

Constant Summary

Constants included from Constants

Constants::CLARITY_BLURRY_THRESHOLD, Constants::CLARITY_LABELS, Constants::CLARITY_SHARP_THRESHOLD, Constants::CLEAN_BOOST_DEFAULT, Constants::DISTORTION_TYPES, Constants::LENS_DEFAULTS, Constants::LENS_TYPES, Constants::MAGNIFICATION_LABELS, Constants::MAX_LENSES, Constants::SMUDGE_RATE_DEFAULT, Constants::STACK_CLARITY_DECAY, Constants::STACK_DISTORTION_BLEND, Constants::STACK_MAGNIFICATION_EXPONENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lens_type:, magnification: nil, clarity: 1.0, distortion: nil, aperture: nil) ⇒ Lens

Returns a new instance of Lens.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 15

def initialize(lens_type:, magnification: nil, clarity: 1.0, distortion: nil, aperture: nil)
  raise ArgumentError, "unknown lens_type: #{lens_type}" unless Constants::LENS_TYPES.include?(lens_type)

  defaults = Constants::LENS_DEFAULTS.fetch(lens_type)

  @id            = SecureRandom.uuid
  @lens_type     = lens_type
  @magnification = (magnification || defaults[:magnification]).clamp(0.1, 10.0).round(10)
  @clarity       = clarity.clamp(0.0, 1.0).round(10)
  @distortion    = (distortion || defaults[:distortion]).clamp(0.0, 1.0).round(10)
  @aperture      = (aperture || defaults[:aperture]).clamp(0.0, 1.0).round(10)
  @focus_target  = nil
  @created_at    = Time.now.utc
end

Instance Attribute Details

#apertureObject (readonly)

Returns the value of attribute aperture.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def aperture
  @aperture
end

#clarityObject (readonly)

Returns the value of attribute clarity.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def clarity
  @clarity
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def created_at
  @created_at
end

#distortionObject (readonly)

Returns the value of attribute distortion.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def distortion
  @distortion
end

#focus_targetObject (readonly)

Returns the value of attribute focus_target.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def focus_target
  @focus_target
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def id
  @id
end

#lens_typeObject (readonly)

Returns the value of attribute lens_type.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def lens_type
  @lens_type
end

#magnificationObject (readonly)

Returns the value of attribute magnification.



12
13
14
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 12

def magnification
  @magnification
end

Instance Method Details

#blurry?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 54

def blurry?
  @clarity <= Constants::CLARITY_BLURRY_THRESHOLD
end

#clarity_labelObject



58
59
60
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 58

def clarity_label
  Constants::CLARITY_LABELS.find { |range, _| range.cover?(@clarity) }&.last || :crystal
end

#clean!(boost = Constants::CLEAN_BOOST_DEFAULT) ⇒ Object



45
46
47
48
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 45

def clean!(boost = Constants::CLEAN_BOOST_DEFAULT)
  @clarity = (@clarity + boost.clamp(0.0, 1.0)).clamp(0.0, 1.0).round(10)
  self
end

#defocus!Object



35
36
37
38
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 35

def defocus!
  @focus_target = nil
  self
end

#depth_of_fieldObject



70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 70

def depth_of_field
  # Larger aperture = shallower depth of field; higher magnification = shallower
  base = 1.0 - @aperture
  mag_factor = 1.0 / [magnification, 0.1].max
  ((base * 0.6) + (mag_factor * 0.4)).clamp(0.0, 1.0).round(10)
end

#focus!(target) ⇒ Object



30
31
32
33
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 30

def focus!(target)
  @focus_target = target
  self
end

#focused?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 66

def focused?
  !@focus_target.nil?
end

#magnification_labelObject



62
63
64
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 62

def magnification_label
  Constants::MAGNIFICATION_LABELS.find { |range, _| range.cover?(@magnification) }&.last || :extreme
end

#sharp?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 50

def sharp?
  @clarity >= Constants::CLARITY_SHARP_THRESHOLD
end

#smudge!(rate = Constants::SMUDGE_RATE_DEFAULT) ⇒ Object



40
41
42
43
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 40

def smudge!(rate = Constants::SMUDGE_RATE_DEFAULT)
  @clarity = (@clarity - rate.clamp(0.0, 1.0)).clamp(0.0, 1.0).round(10)
  self
end

#to_hObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens.rb', line 77

def to_h
  {
    id:                  @id,
    lens_type:           @lens_type,
    magnification:       @magnification,
    clarity:             @clarity,
    distortion:          @distortion,
    aperture:            @aperture,
    focus_target:        @focus_target,
    sharp:               sharp?,
    blurry:              blurry?,
    clarity_label:       clarity_label,
    magnification_label: magnification_label,
    depth_of_field:      depth_of_field
  }
end