Class: Emfsvg::Translation::Scaler::Fixed
- Inherits:
-
Object
- Object
- Emfsvg::Translation::Scaler::Fixed
- Defined in:
- lib/emfsvg/translation/scaler/fixed.rb
Overview
Fixed-factor scaler: multiplies SVG decimal coords by
FACTOR (default 10_000) so 4 decimal places are preserved
as integer fractions in EMF int32 fields. emfsvg's renderer
computes sf_x = viewport_ext / window_ext = 1 / FACTOR and
divides back to recover the decimal.
Choice of 10_000 matches emfsvg's %.4f formatting exactly.
Larger factors risk int32 overflow on big coords (max safe
SVG coord ~ 214_000 with FACTOR=10_000).
Constant Summary collapse
- FACTOR =
10_000- MAX_SAFE_INPUT =
(2**31 - 1) / FACTOR, with margin
214_748
Instance Attribute Summary collapse
-
#factor ⇒ Object
readonly
Returns the value of attribute factor.
Instance Method Summary collapse
-
#initialize(factor = FACTOR) ⇒ Fixed
constructor
A new instance of Fixed.
- #scaled? ⇒ Boolean
- #to_int(decimal) ⇒ Object
-
#unsafe?(value) ⇒ Boolean
True if
valuewould overflow int32 when scaled.
Constructor Details
Instance Attribute Details
#factor ⇒ Object (readonly)
Returns the value of attribute factor.
19 20 21 |
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 19 def factor @factor end |
Instance Method Details
#scaled? ⇒ Boolean
29 30 31 |
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 29 def scaled? true end |
#to_int(decimal) ⇒ Object
25 26 27 |
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 25 def to_int(decimal) (decimal.to_f * factor).round end |
#unsafe?(value) ⇒ Boolean
True if value would overflow int32 when scaled. The
renderer falls back to Identity when ANY coord is unsafe.
35 36 37 |
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 35 def unsafe?(value) value.to_f.abs > MAX_SAFE_INPUT end |