summaryrefslogtreecommitdiff
path: root/dviware/dvisvgm/src/utility.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'dviware/dvisvgm/src/utility.hpp')
-rw-r--r--dviware/dvisvgm/src/utility.hpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/dviware/dvisvgm/src/utility.hpp b/dviware/dvisvgm/src/utility.hpp
index ca0b0873dc..7127280284 100644
--- a/dviware/dvisvgm/src/utility.hpp
+++ b/dviware/dvisvgm/src/utility.hpp
@@ -36,6 +36,13 @@ constexpr const double SQRT2 = 1.414213562373095048801688724209698079;
inline double deg2rad (double deg) {return PI*deg/180.0;}
inline double rad2deg (double rad) {return 180.0*rad/PI;}
+double normalize_angle (double angle, double mod);
+double normalize_0_2pi (double rad);
+std::vector<double> svd (const double (&m)[2][2]);
+
+/** Signum function (returns x/abs(x) if x != 0, and 0 otherwise). */
+template <typename T>
+inline int sgn (T x) {return (x > T(0)) - (x < T(0));}
} // namespace math
@@ -52,12 +59,31 @@ std::string trim (const std::string &str, const char *ws=" \t\n\r\f");
std::string normalize_space (std::string str, const char *ws=" \t\n\r\f");
std::string tolower (const std::string &str);
std::string replace (std::string str, const std::string &find, const std::string &repl);
+std::string to_string (double val);
std::vector<std::string> split (const std::string &str, const std::string &sep);
int ilog10 (int n);
std::string read_file_contents (const std::string &fname);
void write_file_contents (const std::string &fname, std::string::iterator start, std::string::iterator end);
+
+/** Returns a sequence of bytes of a given integral value.
+ * @param[in] val get bytes of this value
+ * @param[in] n number of bytes to extract (from LSB to MSB), all if n == 0
+ * @return vector of bytes in big-endian order */
+template <typename T>
+std::vector<uint8_t> bytes (T val, int n=0) {
+ if (n <= 0)
+ n = sizeof(T);
+ std::vector<uint8_t> ret(n);
+ for (int i=0; i < n; i++) {
+ ret[n-i-1] = val & 0xff;
+ val >>= 8;
+ }
+ return ret;
+}
+
+
/** Encodes the bytes in the half-open range [first,last) to Base64 and writes
* the result to the range starting at 'dest'.
* @param[in] first initial position of the range to be encoded
@@ -103,15 +129,6 @@ std::unique_ptr<T> static_unique_ptr_cast (std::unique_ptr<U> &&old){
return std::unique_ptr<T>{static_cast<T*>(old.release())};
}
-
-template <typename... T>
-constexpr auto make_array (T&&... values) ->
- std::array<typename std::decay<typename std::common_type<T...>::type>::type, sizeof...(T)> {
- return std::array<typename std::decay<typename std::common_type<T...>::type>::type, sizeof...(T)>{
- std::forward<T>(values)...
- };
- }
-
} // namespace util
#endif