module PDF::Math

Encapsulate some of the mathematical calculations that need to be performed when working with PDF documents. All angles in PDF::Writer are measured in degrees, but all angles in PDF documents are in radians. The standard conversions between radians, degrees, and gradians are provided.

As with the Perl implementations of these conversions, they will be wrapped in the range of the target measurement (0..PI2 for radians, 0..360 for degrees, and 0..400 for gradians). To prevent this wrapping, provide a false value for the wrap parameter.

To wrap these values manually, use rad2rad, deg2deg, or grad2grad.

Constants

DG

One degree of arc, measured in terms of gradians.

DR

One degree of arc measured in terms of radians.

GD

One gradian of arc, measured in terms of degrees.

GR

One gradian of arc, measured in terms of radians.

PI2
RD

One radian of arc, measured in terms of degrees.

RG

One radian of arc, measured in terms of gradians.

Public Class Methods

deg2deg(deg) click to toggle source

Wrap degree values within the range of degrees (0..360).

   # File lib/pdf/math.rb
51 def deg2deg(deg)
52   remt(deg, 360)
53 end
deg2grad(deg, wrap = true) click to toggle source

Convert degrees to gradians. The value will be constrained to the range of gradians (0..400) unless wrap is false.

   # File lib/pdf/math.rb
70 def deg2grad(deg, wrap = true)
71   grad = DG * deg
72   grad = grad2grad(grad) if wrap
73   grad
74 end
deg2rad(deg, wrap = true) click to toggle source

Convert degrees to radians. The value will be constrained to the range of radians (0..PI2) unless wrap is false.

   # File lib/pdf/math.rb
62 def deg2rad(deg, wrap = true)
63   rad = DR * deg
64   rad = rad2rad(rad) if wrap
65   rad
66 end
grad2deg(grad, wrap = true) click to toggle source

Convert gradians to degrees. The value will be constrained to the range of degrees (0..360) unless wrap is false.

   # File lib/pdf/math.rb
94 def grad2deg(grad, wrap = true)
95   deg = GD * grad
96   deg = deg2deg(deg) if wrap
97   deg
98 end
grad2grad(grad) click to toggle source

Wrap gradian values within the range of gradians (0..400).

   # File lib/pdf/math.rb
56 def grad2grad(grad)
57   remt(grad, 400)
58 end
grad2rad(grad, wrap = true) click to toggle source

Convert gradians to radians. The value will be constrained to the range of radians (0..PI2) unless wrap is false.

    # File lib/pdf/math.rb
102 def grad2rad(grad, wrap = true)
103   rad = GR * grad
104   rad = rad2rad(rad) if wrap
105   rad
106 end
rad2deg(rad, wrap = true) click to toggle source

Convert radians to degrees. The value will be constrained to the range of degrees (0..360) unless wrap is false.

   # File lib/pdf/math.rb
78 def rad2deg(rad, wrap = true)
79   deg = RD * rad
80   deg = deg2deg(deg) if wrap
81   deg
82 end
rad2grad(rad, wrap = true) click to toggle source

Convert radians to gradians. The value will be constrained to the range of gradians (0..400) unless wrap is false.

   # File lib/pdf/math.rb
86 def rad2grad(rad, wrap = true)
87   grad = RG * rad
88   grad = grad2grad(grad) if wrap
89   grad
90 end
rad2rad(rad) click to toggle source

Wrap radian values within the range of radians (0..PI2).

   # File lib/pdf/math.rb
46 def rad2rad(rad)
47   remt(rad, PI2)
48 end
remt(num, den) click to toggle source

Truncate the remainder.

   # File lib/pdf/math.rb
41 def remt(num, den)
42   num - den * (num / den.to_f).to_i
43 end