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.
brut is the full available span. unit * multiple becomes the major
interval, and sd/su/sn describe that source subinterval. Requested
margins are minimums: leftover space is split between them while their
start/end difference is preserved. The fitted d excludes those margins;
waste includes them and any remainder.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#brut ⇒ Float
readonly
Returns the full available span before fitting.
-
#finish ⇒ Float
readonly
Returns the fitted margin after the interval.
-
#start ⇒ Float
readonly
Returns the fitted margin before the interval.
-
#sub ⇒ Sevgi::Sundries::Interval
readonly
Returns the source subinterval.
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:, margins: [0.0]) ⇒ void
constructor
Creates a ruler fitted into the given span.
-
#margins ⇒ Array<Float>
Returns fitted start and finish margins.
-
#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:, margins: [0.0]) ⇒ void
Creates a ruler fitted into the given span.
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/sevgi/sundries/ruler.rb', line 215 def initialize(brut:, unit:, multiple:, margins: [0.0]) @brut = non_negative_number(brut, "Ruler brut") unit = positive_number(unit, "Ruler unit") multiple = positive_integer(multiple, "Ruler multiple") @sub = Interval.new(unit, multiple) span, start, finish = fitting_span(margins) n = divide(unit:, multiple:, span:) super(@sub, n) @start, @finish = fitted_margins(start, finish, span) end |
Instance Attribute Details
#brut ⇒ Float (readonly)
Returns the full available span before fitting.
183 184 185 |
# File 'lib/sevgi/sundries/ruler.rb', line 183 def brut @brut end |
#finish ⇒ Float (readonly)
Returns the fitted margin after the interval.
187 188 189 |
# File 'lib/sevgi/sundries/ruler.rb', line 187 def finish @finish end |
#start ⇒ Float (readonly)
Returns the fitted margin before the interval.
191 192 193 |
# File 'lib/sevgi/sundries/ruler.rb', line 191 def start @start end |
#sub ⇒ Sevgi::Sundries::Interval (readonly)
Returns the source subinterval.
195 196 197 |
# File 'lib/sevgi/sundries/ruler.rb', line 195 def sub @sub end |
Instance Method Details
#expand ⇒ Sevgi::Sundries::Ruler
Returns a ruler where the source subinterval is flattened into units.
234 |
# File 'lib/sevgi/sundries/ruler.rb', line 234 def = self.class.new(unit: sub.u, multiple: 1, brut: d + waste, margins:) |
#margins ⇒ Array<Float>
Returns fitted start and finish margins.
238 |
# File 'lib/sevgi/sundries/ruler.rb', line 238 def margins = @margins ||= [start, finish].freeze |
#ms ⇒ Array<Float>
Returns minor tick distances across the fitted span. The memoized collection is frozen and must be treated as immutable.
243 |
# File 'lib/sevgi/sundries/ruler.rb', line 243 def ms = @ms ||= .ds |
#sd ⇒ Float
Returns the source subinterval distance.
255 |
# File 'lib/sevgi/sundries/ruler.rb', line 255 def sd = @sub.d |
#sn ⇒ Integer
Returns the source subinterval count.
251 |
# File 'lib/sevgi/sundries/ruler.rb', line 251 def sn = @sub.n |
#su ⇒ Float
Returns the source subinterval unit length.
259 |
# File 'lib/sevgi/sundries/ruler.rb', line 259 def su = @sub.u |
#waste ⇒ Float
Returns the unfitted distance distributed outside the fitted span.
247 |
# File 'lib/sevgi/sundries/ruler.rb', line 247 def waste = @waste ||= brut - d |