Lots more implementation
* implement middle+/- * cells unit * samples for both * moved shorthands to the units/ field Note: cell_px is currently unconfigurable
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
require_relative '../constants'
|
||||
|
||||
|
||||
module Squib
|
||||
module Args
|
||||
module UnitConversion
|
||||
module_function def parse(arg, dpi=300)
|
||||
module_function def parse(arg, dpi=300, cell_px=75)
|
||||
case arg.to_s.rstrip
|
||||
when /in$/ # ends with "in"
|
||||
arg.rstrip[0..-2].to_f * dpi
|
||||
@@ -15,6 +16,8 @@ module Squib
|
||||
arg.rstrip[0..-2].to_f * dpi * INCHES_IN_CM / 10.0
|
||||
when /deg$/ # ends with "deg"
|
||||
arg.rstrip[0..-3].to_f * (Math::PI / 180.0)
|
||||
when /c(ell)?[s]?$/ # ends with 'c', 'cell', or 'cells'
|
||||
arg.rstrip[0..-2].to_f * cell_px
|
||||
else
|
||||
arg
|
||||
end
|
||||
|
||||
@@ -7,7 +7,11 @@ module Squib
|
||||
HEIGHT_MINUS_REGEX = /^height\s*\-\s*/
|
||||
WIDTH_DIV_REGEX = /^width\s*\/\s*/
|
||||
HEIGHT_DIV_REGEX = /^height\s*\/\s*/
|
||||
|
||||
CELL_REGEX = /^c[ell]?[s]?\s*/
|
||||
MIDDLE_PLUS_REGEX = /^middle\s*\+\s*/
|
||||
MIDDLE_MINUS_REGEX = /^middle\s*\-\s*/
|
||||
|
||||
|
||||
# dimension is usually either deck_width or deck_height
|
||||
def apply_shorthands(arg, deck, axis: :x)
|
||||
dimension = (axis == :x) ? deck.width : deck.height
|
||||
@@ -33,7 +37,15 @@ module Squib
|
||||
when HEIGHT_DIV_REGEX # e.g. height / 3
|
||||
n = (arg_s.sub HEIGHT_DIV_REGEX, '').to_f
|
||||
deck.height / n
|
||||
else
|
||||
when MIDDLE_PLUS_REGEX # e.g. middle + 1.5in
|
||||
n = arg_s.sub MIDDLE_PLUS_REGEX, ''
|
||||
n = UnitConversion.parse(n)
|
||||
dimension / 2.0 + n
|
||||
when MIDDLE_MINUS_REGEX # e.g. middle - 1.5in
|
||||
n = arg_s.sub MIDDLE_MINUS_REGEX, ''
|
||||
n = UnitConversion.parse(n)
|
||||
dimension / 2.0 - n
|
||||
else
|
||||
arg
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,5 +28,10 @@ module Squib
|
||||
n.to_f * (Math::PI / 180.0)
|
||||
end
|
||||
|
||||
# DSL method. See http://squib.readthedocs.io
|
||||
def cells(n)
|
||||
n.to_f * @cell_px
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user