Module: RFPDF::Math
- Included in:
- TCPDF
- Defined in:
- lib/plugins/rfpdf/lib/rfpdf/math.rb
Overview
Various mathematical calculations extracted from the PDF::Writer for Ruby gem.
-
Copyright 2003 - 2005 Austin Ziegler.
-
Licensed under a MIT-style licence.
Constant Summary
- PI2 =
::Math::PI * 2.0
- DR =
One degree of arc measured in terms of radians.
PI2 / 360.0
- RD =
One radian of arc, measured in terms of degrees.
360 / PI2
- DG =
One degree of arc, measured in terms of gradians.
400 / 360.0
- GD =
One gradian of arc, measured in terms of degrees.
360 / 400.0
- RG =
One radian of arc, measured in terms of gradians.
400 / PI2
- GR =
One gradian of arc, measured in terms of radians.
PI2 / 400.0
Instance Method Summary (collapse)
-
- (Object) deg2deg(deg)
Wrap degree values within the range of degrees (0..360).
-
- (Object) deg2grad(deg, wrap = true)
Convert degrees to gradians.
-
- (Object) deg2rad(deg, wrap = true)
Convert degrees to radians.
-
- (Object) grad2deg(grad, wrap = true)
Convert gradians to degrees.
-
- (Object) grad2grad(grad)
Wrap gradian values within the range of gradians (0..400).
-
- (Object) grad2rad(grad, wrap = true)
Convert gradians to radians.
-
- (Object) rad2deg(rad, wrap = true)
Convert radians to degrees.
-
- (Object) rad2grad(rad, wrap = true)
Convert radians to gradians.
-
- (Object) rad2rad(rad)
Wrap radian values within the range of radians (0..PI2).
-
- (Object) remt(num, den)
Truncate the remainder.
Instance Method Details
- (Object) deg2deg(deg)
Wrap degree values within the range of degrees (0..360).
34 35 36 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 34 def deg2deg(deg) remt(deg, 360) end |
- (Object) deg2grad(deg, wrap = true)
Convert degrees to gradians. The value will be constrained to the range of
gradians (0..400) unless wrap
is false.
53 54 55 56 57 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 53 def deg2grad(deg, wrap = true) grad = DG * deg grad = grad2grad(grad) if wrap grad end |
- (Object) deg2rad(deg, wrap = true)
Convert degrees to radians. The value will be constrained to the range of
radians (0..PI2) unless wrap
is false.
45 46 47 48 49 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 45 def deg2rad(deg, wrap = true) rad = DR * deg rad = rad2rad(rad) if wrap rad end |
- (Object) grad2deg(grad, wrap = true)
Convert gradians to degrees. The value will be constrained to the range of
degrees (0..360) unless wrap
is false.
77 78 79 80 81 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 77 def grad2deg(grad, wrap = true) deg = GD * grad deg = deg2deg(deg) if wrap deg end |
- (Object) grad2grad(grad)
Wrap gradian values within the range of gradians (0..400).
39 40 41 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 39 def grad2grad(grad) remt(grad, 400) end |
- (Object) grad2rad(grad, wrap = true)
Convert gradians to radians. The value will be constrained to the range of
radians (0..PI2) unless wrap
is false.
85 86 87 88 89 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 85 def grad2rad(grad, wrap = true) rad = GR * grad rad = rad2rad(rad) if wrap rad end |
- (Object) rad2deg(rad, wrap = true)
Convert radians to degrees. The value will be constrained to the range of
degrees (0..360) unless wrap
is false.
61 62 63 64 65 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 61 def rad2deg(rad, wrap = true) deg = RD * rad deg = deg2deg(deg) if wrap deg end |
- (Object) rad2grad(rad, wrap = true)
Convert radians to gradians. The value will be constrained to the range of
gradians (0..400) unless wrap
is false.
69 70 71 72 73 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 69 def rad2grad(rad, wrap = true) grad = RG * rad grad = grad2grad(grad) if wrap grad end |
- (Object) rad2rad(rad)
Wrap radian values within the range of radians (0..PI2).
29 30 31 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 29 def rad2rad(rad) remt(rad, PI2) end |
- (Object) remt(num, den)
Truncate the remainder.
24 25 26 |
# File 'lib/plugins/rfpdf/lib/rfpdf/math.rb', line 24 def remt(num, den) num - den * (num / den.to_f).to_i end |