cryph utilities [subset]  2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
Inline.h
Go to the documentation of this file.
1 
7 #ifndef INLINE_H
8 #define INLINE_H
9 
10 #include <iostream>
11 #include <math.h>
12 #include <stdlib.h>
13 #include <string>
14 
15 namespace cryph
16 {
17 
23 inline std::string closeStr(char openStr)
24 {
25  if (openStr == '(')
26  return ")";
27  if (openStr == '[')
28  return "]";
29  if (openStr == '{')
30  return "}";
31  if (openStr == '<')
32  return ">";
33  if (openStr == ' ')
34  return " ";
35  return "???";
36 }
37 
42 inline double degreesToRadians(double angleInDegrees)
43 {
44  return angleInDegrees*M_PI/180.0;
45 }
46 
53 inline bool equalScalars(double s1, double s2, double tol)
54 {
55  return (fabs(s1-s2) < tol);
56 }
57 
62 inline double radiansToDegrees(double angleInRadians)
63 {
64  return angleInRadians*180.0/M_PI;
65 }
66 
70 inline double random0To1_next()
71 {
72  return drand48();
73 }
74 
78 inline void random0To1_seed(long seedVal)
79 {
80  srand48(seedVal);
81 }
82 
87 inline int roundR2I(double val)
88 {
89  return (int) (val + 0.5);
90 }
91 
96 inline void skipNonblankChars(std::istream& is, int nNonBlankChars)
97 {
98  char ch;
99  for (int i=0 ; i<nNonBlankChars ; i++)
100  is >> ch;
101 }
102 
107 inline double square(double s)
108 {
109  return s * s;
110 }
111 
112 // Templates
113 
114 
120 template <typename T>
121 inline T maximum(T s1, T s2)
122 {
123  return (s1 >= s2) ? s1 : s2;
124 }
125 
131 template <typename T>
132 inline T minimum(T s1, T s2)
133 {
134  return (s1 >= s2) ? s2 : s1;
135 }
136 
141 template <typename T> inline void swap2(T& t1, T& t2)
142 {
143  T temp = t1;
144  t1 = t2;
145  t2 = temp;
146 }
147 
148 }
149 
150 #endif
Definition: AffPoint.c++:12
double radiansToDegrees(double angleInRadians)
Definition: Inline.h:62
double square(double s)
Definition: Inline.h:107
void skipNonblankChars(std::istream &is, int nNonBlankChars)
Definition: Inline.h:96
void random0To1_seed(long seedVal)
Definition: Inline.h:78
void swap2(T &t1, T &t2)
Definition: Inline.h:141
int roundR2I(double val)
Definition: Inline.h:87
T minimum(T s1, T s2)
Definition: Inline.h:132
double random0To1_next()
Definition: Inline.h:70
std::string closeStr(char openStr)
Definition: Inline.h:23
bool equalScalars(double s1, double s2, double tol)
Definition: Inline.h:53
T maximum(T s1, T s2)
Definition: Inline.h:121
double degreesToRadians(double angleInDegrees)
Definition: Inline.h:42