To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 01 / 01346eb099170b569ce9589ce5f15a834ff1b1a7.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2.4 KB)

1
# Various mathematical calculations extracted from the PDF::Writer for Ruby gem.
2
# - http://rubyforge.org/projects/ruby-pdf
3
# - Copyright 2003 - 2005 Austin Ziegler.
4
# - Licensed under a MIT-style licence.
5
#
6

    
7
module RFPDF::Math
8
  PI2   = ::Math::PI * 2.0
9

    
10
  # One degree of arc measured in terms of radians.
11
  DR  = PI2 / 360.0
12
  # One radian of arc, measured in terms of degrees.
13
  RD  = 360 / PI2
14
  # One degree of arc, measured in terms of gradians.
15
  DG  = 400 / 360.0
16
  # One gradian of arc, measured in terms of degrees.
17
  GD  = 360 / 400.0
18
  # One radian of arc, measured in terms of gradians.
19
  RG  = 400 / PI2
20
  # One gradian of arc, measured in terms of radians.
21
  GR  = PI2 / 400.0
22

    
23
  # Truncate the remainder.
24
  def remt(num, den)
25
    num - den * (num / den.to_f).to_i
26
  end
27

    
28
  # Wrap radian values within the range of radians (0..PI2).
29
  def rad2rad(rad)
30
    remt(rad, PI2)
31
  end
32

    
33
  # Wrap degree values within the range of degrees (0..360).
34
  def deg2deg(deg)
35
    remt(deg, 360)
36
  end
37

    
38
  # Wrap gradian values within the range of gradians (0..400).
39
  def grad2grad(grad)
40
    remt(grad, 400)
41
  end
42

    
43
  # Convert degrees to radians. The value will be constrained to the
44
  # range of radians (0..PI2) unless +wrap+ is false.
45
  def deg2rad(deg, wrap = true)
46
    rad = DR * deg
47
    rad = rad2rad(rad) if wrap
48
    rad
49
  end
50

    
51
  # Convert degrees to gradians. The value will be constrained to the
52
  # range of gradians (0..400) unless +wrap+ is false.
53
  def deg2grad(deg, wrap = true)
54
    grad = DG * deg
55
    grad = grad2grad(grad) if wrap
56
    grad
57
  end
58

    
59
  # Convert radians to degrees. The value will be constrained to the
60
  # range of degrees (0..360) unless +wrap+ is false.
61
  def rad2deg(rad, wrap = true)
62
    deg = RD * rad
63
    deg = deg2deg(deg) if wrap
64
    deg
65
  end
66

    
67
  # Convert radians to gradians. The value will be constrained to the
68
  # range of gradians (0..400) unless +wrap+ is false.
69
  def rad2grad(rad, wrap = true)
70
    grad = RG * rad
71
    grad = grad2grad(grad) if wrap
72
    grad
73
  end
74

    
75
  # Convert gradians to degrees. The value will be constrained to the
76
  # range of degrees (0..360) unless +wrap+ is false.
77
  def grad2deg(grad, wrap = true)
78
    deg = GD * grad
79
    deg = deg2deg(deg) if wrap
80
    deg
81
  end
82

    
83
  # Convert gradians to radians. The value will be constrained to the
84
  # range of radians (0..PI2) unless +wrap+ is false.
85
  def grad2rad(grad, wrap = true)
86
    rad = GR * grad
87
    rad = rad2rad(rad) if wrap
88
    rad
89
  end
90
end