Module PDF::Math
In: lib/pdf/math.rb
Transaction::Simple SimpleTable TechBook Complex Action Procset FontDescriptor FontEncoding Destination Info Catalog Encryption Contents Pages Outline Outlines Annotation Page Font ViewerPreferences Image Hash OHash QuickRef FontMetrics ARC4 StrokeStyle PolygonPoint ImageInfo StdDev lib/pdf/simpletable.rb lib/pdf/techbook.rb lib/pdf/writer.rb lib/pdf/quickref.rb Math lib/pdf/writer/fontmetrics.rb lib/pdf/writer/ohash.rb lib/pdf/writer/arc4.rb lib/pdf/writer/strokestyle.rb lib/pdf/writer/graphics.rb lib/pdf/writer/object.rb lib/pdf/writer/object/image.rb External EN Lang OffsetReader lib/pdf/writer/graphics/imageinfo.rb Graphics lib/pdf/writer/object/outlines.rb lib/pdf/writer/object/destination.rb lib/pdf/writer/object/viewerpreferences.rb lib/pdf/writer/object/fontencoding.rb lib/pdf/writer/object/page.rb lib/pdf/writer/object/contents.rb lib/pdf/writer/object/procset.rb lib/pdf/writer/object/pages.rb lib/pdf/writer/object/info.rb lib/pdf/writer/object/encryption.rb lib/pdf/writer/object/catalog.rb lib/pdf/writer/object/outline.rb lib/pdf/writer/object/fontdescriptor.rb lib/pdf/writer/object/action.rb lib/pdf/writer/object/font.rb lib/pdf/writer/object/annotation.rb Object Writer lib/pdf/charts/stddev.rb Charts PDF dot/m_33_0.png

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.

Methods

deg2deg   deg2grad   deg2rad   grad2deg   grad2grad   grad2rad   rad2deg   rad2grad   rad2rad   remt  

Constants

PI2 = ::Math::PI * 2.0
DR = PI2 / 360.0   One degree of arc measured in terms of radians.
RD = 360 / PI2   One radian of arc, measured in terms of degrees.
DG = 400 / 360.0   One degree of arc, measured in terms of gradians.
GD = 360 / 400.0   One gradian of arc, measured in terms of degrees.
RG = 400 / PI2   One radian of arc, measured in terms of gradians.
GR = PI2 / 400.0   One gradian of arc, measured in terms of radians.

Public Class methods

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

[Source]

    # File lib/pdf/math.rb, line 51
51:     def deg2deg(deg)
52:       remt(deg, 360)
53:     end

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

[Source]

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

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

[Source]

    # File lib/pdf/math.rb, line 62
62:     def deg2rad(deg, wrap = true)
63:       rad = DR * deg
64:       rad = rad2rad(rad) if wrap
65:       rad
66:     end

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

[Source]

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

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

[Source]

    # File lib/pdf/math.rb, line 56
56:     def grad2grad(grad)
57:       remt(grad, 400)
58:     end

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

[Source]

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

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

[Source]

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

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

[Source]

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

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

[Source]

    # File lib/pdf/math.rb, line 46
46:     def rad2rad(rad)
47:       remt(rad, PI2)
48:     end

Truncate the remainder.

[Source]

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

[Validate]