Module: PDF::Math

### Home Classes Methods

### In Files

- lib/pdf/math.rb

### Methods

- ::deg2deg
- ::deg2grad
- ::deg2rad
- ::grad2deg
- ::grad2grad
- ::grad2rad
- ::rad2deg
- ::rad2grad
- ::rad2rad
- ::remt

### Files

- ChangeLog

### Class/Module Index

Quicksearch

- PDF
- PDF::Charts
- PDF::Charts::StdDev
- PDF::Charts::StdDev::Label
- PDF::Charts::StdDev::Marker
- PDF::Charts::StdDev::Scale
- PDF::Math
- PDF::QuickRef
- PDF::SimpleTable
- PDF::SimpleTable::Column
- PDF::SimpleTable::Column::Heading
- PDF::TechBook
- PDF::TechBook::TagTocDots
- PDF::TechBook::TagXref
- PDF::Writer
- PDF::Writer::ARC4
- PDF::Writer::Complex
- PDF::Writer::External
- PDF::Writer::FontMetrics
- PDF::Writer::Graphics
- PDF::Writer::Graphics::ImageInfo
- PDF::Writer::Graphics::ImageInfo::Formats
- PDF::Writer::Graphics::ImageInfo::Type
- PDF::Writer::Lang
- PDF::Writer::Lang::EN
- PDF::Writer::OHash
- PDF::Writer::Object
- PDF::Writer::Object::Action
- PDF::Writer::Object::Annotation
- PDF::Writer::Object::Catalog
- PDF::Writer::Object::Contents
- PDF::Writer::Object::Destination
- PDF::Writer::Object::Encryption
- PDF::Writer::Object::Font
- PDF::Writer::Object::FontDescriptor
- PDF::Writer::Object::FontEncoding
- PDF::Writer::Object::Info
- PDF::Writer::Object::Outline
- PDF::Writer::Object::Outlines
- PDF::Writer::Object::Pages
- PDF::Writer::Object::Procset
- PDF::Writer::Object::ViewerPreferences
- PDF::Writer::OffsetReader
- PDF::Writer::PolygonPoint
- PDF::Writer::State
- PDF::Writer::StateStack
- PDF::Writer::StrokeStyle

No matching classes.

# 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, line 51
    def deg2deg(deg)
      remt(deg, 360)
    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, line 70
    def deg2grad(deg, wrap = true)
      grad = DG * deg
      grad = grad2grad(grad) if wrap
      grad
    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, line 62
    def deg2rad(deg, wrap = true)
      rad = DR * deg
      rad = rad2rad(rad) if wrap
      rad
    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, line 94
    def grad2deg(grad, wrap = true)
      deg = GD * grad
      deg = deg2deg(deg) if wrap
      deg
    end

grad2grad(grad) click to toggle source

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

    # File lib/pdf/math.rb, line 56
    def grad2grad(grad)
      remt(grad, 400)
    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, line 102
    def grad2rad(grad, wrap = true)
      rad = GR * grad
      rad = rad2rad(rad) if wrap
      rad
    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, line 78
    def rad2deg(rad, wrap = true)
      deg = RD * rad
      deg = deg2deg(deg) if wrap
      deg
    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, line 86
    def rad2grad(rad, wrap = true)
      grad = RG * rad
      grad = grad2grad(grad) if wrap
      grad
    end

rad2rad(rad) click to toggle source

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

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

remt(num, den) click to toggle source

Truncate the remainder.

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.