Class: Legion::Extensions::Agentic::Attention::Telescope::Helpers::Telescope

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lens_type:, aperture: 0.5, magnification: 1.0, tracking: false) ⇒ Telescope

Returns a new instance of Telescope.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 13

def initialize(lens_type:, aperture: 0.5, magnification: 1.0, tracking: false)
  validate_lens_type!(lens_type)
  @id            = SecureRandom.uuid
  @lens_type     = lens_type.to_sym
  @aperture      = aperture.to_f.clamp(0.1, 1.0).round(10)
  @magnification = magnification.to_f.clamp(
    Constants::BASE_MAGNIFICATION, Constants::MAX_MAGNIFICATION
  ).round(10)
  @tracking = tracking
  @focal_distance = nil
  @created_at = Time.now.utc
end

Instance Attribute Details

#apertureObject (readonly)

Returns the value of attribute aperture.



10
11
12
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 10

def aperture
  @aperture
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 10

def created_at
  @created_at
end

#focal_distanceObject (readonly)

Returns the value of attribute focal_distance.



10
11
12
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 10

def focal_distance
  @focal_distance
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 10

def id
  @id
end

#lens_typeObject (readonly)

Returns the value of attribute lens_type.



10
11
12
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 10

def lens_type
  @lens_type
end

#magnificationObject (readonly)

Returns the value of attribute magnification.



10
11
12
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 10

def magnification
  @magnification
end

#trackingObject (readonly)

Returns the value of attribute tracking.



10
11
12
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 10

def tracking
  @tracking
end

Instance Method Details

#blurry?Boolean

True when clarity falls below 0.3

Returns:

  • (Boolean)


87
88
89
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 87

def blurry?
  clarity < 0.3
end

#clarityObject

Clarity based on aperture and atmospheric distortion modulated by magnification



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

def clarity
  distortion_factor = 1.0 - (Constants::ATMOSPHERIC_DISTORTION / @magnification.clamp(1.0, 10.0))
  (@aperture * distortion_factor).clamp(0.0, 1.0).round(10)
end

#clarity_labelObject



91
92
93
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 91

def clarity_label
  Helpers::Constants.label_for(Constants::CLARITY_LABELS, clarity)
end

#deep_field?Boolean

True when magnification >= 50 (deep-sky mode)

Returns:

  • (Boolean)


72
73
74
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 72

def deep_field?
  @magnification >= 50.0
end

#disable_tracking!Object



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

def disable_tracking!
  @tracking = false
  self
end

#enable_tracking!Object



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

def enable_tracking!
  @tracking = true
  self
end

#field_of_viewObject

Calculated field of view: wider aperture + lower magnification = wider field



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

def field_of_view
  (Constants::FIELD_OF_VIEW_BASE / @magnification * @aperture).round(10)
end

#focus!(target_distance) ⇒ Object

Focus on a target distance; focal alignment adjusts effective clarity



56
57
58
59
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 56

def focus!(target_distance)
  @focal_distance = target_distance.to_f.clamp(0.0, 1.0).round(10)
  self
end

#sharp?Boolean

True when clarity is at or above 0.8

Returns:

  • (Boolean)


82
83
84
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 82

def sharp?
  clarity >= 0.8
end

#to_hObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 95

def to_h
  {
    id:             @id,
    lens_type:      @lens_type,
    aperture:       @aperture,
    magnification:  @magnification,
    tracking:       @tracking,
    focal_distance: @focal_distance,
    field_of_view:  field_of_view,
    clarity:        clarity,
    clarity_label:  clarity_label,
    deep_field:     deep_field?,
    wide_field:     wide_field?,
    sharp:          sharp?,
    blurry:         blurry?,
    created_at:     @created_at
  }
end

#wide_field?Boolean

True when magnification <= 5 (wide-field survey mode)

Returns:

  • (Boolean)


77
78
79
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 77

def wide_field?
  @magnification <= 5.0
end

#zoom_in!(factor) ⇒ Object

Increase magnification by factor; field of view narrows inversely



27
28
29
30
31
32
33
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 27

def zoom_in!(factor)
  factor = factor.to_f.clamp(1.0, Constants::MAX_MAGNIFICATION)
  @magnification = (@magnification * factor).clamp(
    Constants::BASE_MAGNIFICATION, Constants::MAX_MAGNIFICATION
  ).round(10)
  self
end

#zoom_out!(factor) ⇒ Object

Decrease magnification by factor; field of view widens



36
37
38
39
40
41
42
# File 'lib/legion/extensions/agentic/attention/telescope/helpers/telescope.rb', line 36

def zoom_out!(factor)
  factor = [factor.to_f, 1.0].max
  @magnification = (@magnification / factor).clamp(
    Constants::BASE_MAGNIFICATION, Constants::MAX_MAGNIFICATION
  ).round(10)
  self
end