base.h
资源名称:package.rar [点击查看]
上传用户:chinasdcnc
上传日期:2022-07-02
资源大小:2702k
文件大小:1k
源码类别:
分形几何
开发平台:
Visual C++
- //
- // Delaunay Triangulation
- //
- // Homework of CG lesson (Fall 2009) in Tsinghua University.
- // All rights reserved.
- //
- #pragma once
- #include <ctime>
- #include <cassert>
- /**
- * The error tolerance used in global scope.
- */
- const double TOLERANCE = 1e-10;
- /**
- * The max random number.
- */
- const double INV_RAND_MAX = 1.0 / (RAND_MAX + 1.0);
- /**
- * Returns the absolute value of @c val.
- */
- template<typename T>
- inline T fabs(T val)
- {
- if (val < 0)
- return -val;
- else
- return val;
- }
- /**
- * Returns the max value of @c val.
- */
- template<typename T>
- inline T getMax(T a, T b)
- {
- if (a > b)
- return a;
- else
- return b;
- }
- /**
- * Returns the min value of @c val.
- */
- template<typename T>
- inline T getMin(T a, T b)
- {
- if (a > b)
- return b;
- else
- return a;
- }
- /**
- * Returns a random integer between @c start(inclusive) and @c end(exclusive).
- */
- inline int random(int start, int end)
- {
- assert(end > start);
- return start + rand() % (end - start);
- }
- /**
- * Returns a random double double number between 0(inclusive) and 1(exclusive).
- */
- inline double random(void)
- {
- return rand() * INV_RAND_MAX;
- }