Class: Sevgi::Sundries::Ruler
- Defined in:
- lib/sevgi/sundries/ruler.rb
Overview
Fits a repeated interval into a broader span with computed margins.
A ruler stores both the fitted major interval and the source subinterval.
The compact reader names mirror Interval: brut is the full available
span, sd/su/sn describe the subinterval, and waste is distributed as
equal margins.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#brut ⇒ Float
readonly
Full available span before fitting.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
Attributes inherited from Interval
Instance Method Summary collapse
-
#expand ⇒ Sevgi::Sundries::Ruler
Returns a ruler where the source subinterval is flattened into units.
-
#initialize(brut:, unit:, multiple:, margin: 0.0) ⇒ void
constructor
Creates a ruler fitted into the given span.
-
#margin ⇒ Float
Returns the computed margin after fitting.
-
#ms ⇒ Array<Float>
Returns minor tick distances across the fitted span.
-
#sd ⇒ Float
Returns the source subinterval distance.
-
#sn ⇒ Integer
Returns the source subinterval count.
-
#su ⇒ Float
Returns the source subinterval unit length.
-
#waste ⇒ Float
Returns the unfitted distance distributed outside the fitted span.
Methods inherited from Interval
[], #[], #count, #d, #ds, #h, #hs, #nds, #nhs
Constructor Details
#initialize(brut:, unit:, multiple:, margin: 0.0) ⇒ void
Creates a ruler fitted into the given span.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/sevgi/sundries/ruler.rb', line 122 def initialize(brut:, unit:, multiple:, margin: 0.0) ArgumentError.("Ruler unit must be positive") unless unit.to_f.positive? ArgumentError.("Ruler multiple must be positive") unless multiple.to_f.positive? ArgumentError.("Ruler margin must be non-negative") if margin.to_f.negative? @brut = brut.to_f margin = margin.to_f @sub = Interval.new(unit, multiple) n = divide(unit:, multiple:, brut: @brut, margin:) ArgumentError.("Ruler fitting span must not be negative") if n.negative? super(@sub, n) end |
Instance Attribute Details
#brut ⇒ Float (readonly)
Returns full available span before fitting.
111 112 113 |
# File 'lib/sevgi/sundries/ruler.rb', line 111 def brut @brut end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
111 |
# File 'lib/sevgi/sundries/ruler.rb', line 111 attr_reader :brut, :sub |
Instance Method Details
#expand ⇒ Sevgi::Sundries::Ruler
Returns a ruler where the source subinterval is flattened into units.
140 |
# File 'lib/sevgi/sundries/ruler.rb', line 140 def = self.class.new(unit: sub.u, multiple: 1, brut: d + waste, margin:) |
#margin ⇒ Float
Returns the computed margin after fitting.
144 |
# File 'lib/sevgi/sundries/ruler.rb', line 144 def margin = @margin ||= waste / 2.0 |
#ms ⇒ Array<Float>
Returns minor tick distances across the fitted span.
148 |
# File 'lib/sevgi/sundries/ruler.rb', line 148 def ms = @ms ||= .ds |
#sd ⇒ Float
Returns the source subinterval distance.
160 |
# File 'lib/sevgi/sundries/ruler.rb', line 160 def sd = @sub.d |
#sn ⇒ Integer
Returns the source subinterval count.
156 |
# File 'lib/sevgi/sundries/ruler.rb', line 156 def sn = @sub.n |
#su ⇒ Float
Returns the source subinterval unit length.
164 |
# File 'lib/sevgi/sundries/ruler.rb', line 164 def su = @sub.u |
#waste ⇒ Float
Returns the unfitted distance distributed outside the fitted span.
152 |
# File 'lib/sevgi/sundries/ruler.rb', line 152 def waste = @waste ||= brut - d |