File: angle.h

package info (click to toggle)
asymptote 3.05%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,420 kB
  • sloc: cpp: 172,663; ansic: 69,690; python: 14,957; sh: 5,605; javascript: 4,871; lisp: 1,507; perl: 1,417; makefile: 1,026; yacc: 610; lex: 449; xml: 182; asm: 8
file content (53 lines) | stat: -rw-r--r-- 886 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*****
 * angle.h
 * Andy Hammerlindl 2004/04/29
 *
 * For degree to radian conversion and visa versa.
 *****/

#ifndef ANGLE_H
#define ANGLE_H

#include <cmath>
#include "camperror.h"

namespace camp {

const double PI=acos(-1.0);

const double Cpiby180=PI/180.0;
const double C180bypi=180.0/PI;

inline double radians(double theta)
{
  return theta*Cpiby180;
}

inline double degrees(double theta)
{
  return theta*C180bypi;
}

// Wrapper for atan2 with sensible (lexical) argument order and (0,0) check
inline double angle(double x, double y, bool warn=true)
{
  if(x == 0.0 && y == 0.0) {
    if(warn)
      reportError("taking angle of (0,0)");
    else
      return 0;
  }
  return atan2(y,x);
}

// Return an angle in the interval [0,360).
inline double principalBranch(double deg)
{
  deg=fmod(deg,360.0);
  if(deg < 0) deg += 360.0;
  return deg;
}

} //namespace camp

#endif