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.
176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/sevgi/sundries/ruler.rb', line 176 def initialize(brut:, unit:, multiple:, margin: 0.0) @brut = non_negative_number(brut, "Ruler brut") unit = positive_number(unit, "Ruler unit") multiple = positive_integer(multiple, "Ruler multiple") margin = non_negative_number(margin, "Ruler margin") @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.
157 158 159 |
# File 'lib/sevgi/sundries/ruler.rb', line 157 def brut @brut end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
157 |
# File 'lib/sevgi/sundries/ruler.rb', line 157 attr_reader :brut, :sub |
Instance Method Details
#expand ⇒ Sevgi::Sundries::Ruler
Returns a ruler where the source subinterval is flattened into units.
192 |
# File 'lib/sevgi/sundries/ruler.rb', line 192 def = self.class.new(unit: sub.u, multiple: 1, brut: d + waste, margin:) |
#margin ⇒ Float
Returns the computed margin after fitting.
196 |
# File 'lib/sevgi/sundries/ruler.rb', line 196 def margin = @margin ||= waste / 2.0 |
#ms ⇒ Array<Float>
Returns minor tick distances across the fitted span.
200 |
# File 'lib/sevgi/sundries/ruler.rb', line 200 def ms = @ms ||= .ds |
#sd ⇒ Float
Returns the source subinterval distance.
212 |
# File 'lib/sevgi/sundries/ruler.rb', line 212 def sd = @sub.d |
#sn ⇒ Integer
Returns the source subinterval count.
208 |
# File 'lib/sevgi/sundries/ruler.rb', line 208 def sn = @sub.n |
#su ⇒ Float
Returns the source subinterval unit length.
216 |
# File 'lib/sevgi/sundries/ruler.rb', line 216 def su = @sub.u |
#waste ⇒ Float
Returns the unfitted distance distributed outside the fitted span.
204 |
# File 'lib/sevgi/sundries/ruler.rb', line 204 def waste = @waste ||= brut - d |