dl
函数 | 变量
dl::Math 命名空间参考

2维装箱算法 更多...

函数

template<typename T >
constexpr T Limit (const T &v, const T &v_min, const T &v_max)
 限制数值到 闭区间 更多...
 
template<typename T , size_t N>
std::array< unsigned, N > CastU (const std::array< T, N > &a, bool show_log=true)
 有符号转无符号,并且判断负数 更多...
 
template<typename T , size_t N>
std::array< unsigned, N > CastUDefault (const std::array< T, N > &a)
 有符号转无符号,直接转换,负数会直接转为大正数 更多...
 
template<typename T >
constexpr bool IsOutRange (T x, T a, T b)
 判断数值是否越界(前闭后开) 更多...
 
constexpr uint64_t Pow (uint64_t x, uint8_t n)
 返回x的n次方 更多...
 
constexpr uint32_t Pow32 (uint32_t x, uint8_t n)
 
constexpr uint64_t CeilToPow2 (uint64_t &&x)
 
constexpr uint32_t CeilToPow2 (uint32_t &&x)
 
template<typename T >
T CeilToPow2 (const T &x)
 向上取2的幂次 更多...
 
float RSqrt (float x)
 返回平方根的倒数 更多...
 
template<size_t N>
void NormalizeFast (std::array< float, N > &v)
 向量单位化,精度低速度快 更多...
 
template<IsSigned T>
T DisPow2 (const std::array< T, 2 > &a)
 返回 向量 距离的平方 更多...
 
template<IsSigned T>
T DisPow2 (const std::array< T, 3 > &a)
 
template<IsSigned T>
T DisPow2 (const std::array< T, 4 > &a)
 
template<IsSigned T>
T DisPow2 (const std::array< T, 2 > &a, const std::array< T, 2 > &b)
 返回 距离的平方 更多...
 
template<IsUnsigned T>
T DisU (T a, T b)
 返回无符号类型的差值 更多...
 
template<IsUnsigned T0, IsSigned T1>
T0 AddU (T0 a, T1 b)
 无符号 加 有符号,防止小于0 更多...
 
template<IsUnsigned T>
T DisPow2U (const std::array< T, 2 > &a, const std::array< T, 2 > &b)
 返回 距离的平方 更多...
 
template<IsSigned T, size_t N>
void Normalize (std::array< T, N > &v)
 向量单位化 更多...
 
template<IsSigned T, size_t N>
std::array< T, N > Normalize (const std::array< T, N > &v)
 
std::vector< PointU > getCircle (const Size &size, const PointU &xy, unsigned rad)
 返回圆形范围的节点,考虑越界 更多...
 
std::vector< Point > getCircle (const Point &xy, unsigned rad)
 返回圆形范围的节点,不考虑越界 更多...
 
constexpr double PI (unsigned n, unsigned d=1)
 返回PI的分数 更多...
 
template<IsReal T>
constexpr T AlignF (T x, T align)
 RGP资源下标转方向 更多...
 
template<IsUnsigned T>
constexpr T Align (T x, T align)
 对齐align的倍数 更多...
 
constexpr unsigned AlignPow2 (unsigned x, unsigned align)
 对齐align的倍数 更多...
 
constexpr unsigned div_found (unsigned n, unsigned d)
 无符号除法,返回四舍五入结果 更多...
 
constexpr unsigned div_found_fast (unsigned n, unsigned d)
 无符号除法,返回四舍五入结果 更多...
 
constexpr float OffsetOrder (float order, int u=1, int v=0, int w=0)
 偏移order 更多...
 
constexpr Float CrossProduct (const Position2 &a, const Position2 &b)
 叉乘 更多...
 
constexpr Position3 CrossProduct (const Position3 &a, const Position3 &b)
 
template<typename T , size_t N>
constexpr T DotProduct (const std::array< T, N > &a, const std::array< T, N > &b)
 点乘 更多...
 
Position4 Slerp (const Position4 &q0, const Position4 &q1, const Float &t)
 球面线性插值 更多...
 
template<typename C >
constexpr auto DistanceDiagonal (const C &p0, const C &p1)
 纹理区域转uv 更多...
 
std::vector< Point > DrawLineLerp (const Point &p0, const Point &p1)
 线性插值 画线算法 更多...
 
std::vector< Point > DrawLineBresenham (const Point &p0, const Point &p1)
 bresenham 画线算法 更多...
 
std::vector< Point > DrawLineOrth (const Point &p0, const Point &p1)
 正交 画线算法 更多...
 
std::vector< Point > DrawLineCover (const Point &p0, const Point &p1)
 覆盖 画线算法 更多...
 
void MergePath (std::list< Point > &list_pos)
 路径合并(网格路径) 更多...
 
template<typename F >
void MergePathDirect (std::list< Point > &list_pos, F func_pass)
 路径合并(网格路径) 更多...
 
template<typename T >
constexpr bool IsValidRect (const std::array< T, 4 > &rect)
 ‍** 更多...
 
template<typename T >
constexpr bool IsRectInSize (const std::array< T, 4 > &rect, const Size &size)
 判断 矩形 在 大小 内,首先它必须是有效的矩形 更多...
 
constexpr bool IsXyInSize (const Point &xy, const Size &size)
 判断 点是否在大小内 更多...
 
constexpr bool IsXyInRect (const Point &xy, const Rect &rect)
 判断 点是否在矩形内 更多...
 
constexpr bool IsDotInTriangle (const Position &dot, const Triangle &triangle)
 判断点是否在三角形内 更多...
 

变量

constexpr uint64_t ARRAY_POW2 []
 2的整数次幂列表 更多...
 
constexpr uint32_t ARRAY_POW2_32 []
 

详细描述

2维装箱算法

参数
[in]size箱子大小
map_size传入矩形的数组,失败返回剩余的矩形
[out]map_fet返回装入的矩形信息

函数说明

◆ AddU()

template<IsUnsigned T0, IsSigned T1>
T0 dl::Math::AddU ( T0  a,
T1  b 
)

无符号 加 有符号,防止小于0

在文件 dl_math.h 第 308 行定义.

◆ Align()

template<IsUnsigned T>
constexpr T dl::Math::Align ( T  x,
T  align 
)
constexpr

对齐align的倍数

注解
注意,现在如果x为0,则返回align

在文件 dl_math.h 第 465 行定义.

◆ AlignF()

template<IsReal T>
constexpr T dl::Math::AlignF ( T  x,
T  align 
)
constexpr

RGP资源下标转方向

向量 转 掩码

对齐align的倍数,并且x考虑负数

注解
注意,现在如果x为0,则返回align
负数向右对齐

在文件 dl_math.h 第 436 行定义.

◆ AlignPow2()

constexpr unsigned dl::Math::AlignPow2 ( unsigned  x,
unsigned  align 
)
constexpr

对齐align的倍数

注解
align必须是2的幂,否则返回0

在文件 dl_math.h 第 481 行定义.

◆ CastU()

template<typename T , size_t N>
std::array< unsigned, N > dl::Math::CastU ( const std::array< T, N > &  a,
bool  show_log = true 
)

有符号转无符号,并且判断负数

注解
当出现负数时转为0,且输出日志(log为真时才输出日志)

在文件 dl_math.h 第 89 行定义.

◆ CastUDefault()

template<typename T , size_t N>
std::array< unsigned, N > dl::Math::CastUDefault ( const std::array< T, N > &  a)

有符号转无符号,直接转换,负数会直接转为大正数

在文件 dl_math.h 第 111 行定义.

◆ CeilToPow2() [1/3]

template<typename T >
T dl::Math::CeilToPow2 ( const T &  x)
inline

向上取2的幂次

注解
bit_ceil很难触发常量表达式,但在计算变量时最快

在文件 dl_math.h 第 208 行定义.

◆ CeilToPow2() [2/3]

constexpr uint32_t dl::Math::CeilToPow2 ( uint32_t &&  x)
constexpr

在文件 dl_math.h 第 192 行定义.

◆ CeilToPow2() [3/3]

constexpr uint64_t dl::Math::CeilToPow2 ( uint64_t &&  x)
constexpr

在文件 dl_math.h 第 177 行定义.

◆ CrossProduct() [1/2]

constexpr Float dl::Math::CrossProduct ( const Position2 &  a,
const Position2 &  b 
)
constexpr

叉乘

在文件 dl_math.h 第 540 行定义.

◆ CrossProduct() [2/2]

constexpr Position3 dl::Math::CrossProduct ( const Position3 &  a,
const Position3 &  b 
)
constexpr

在文件 dl_math.h 第 545 行定义.

◆ DisPow2() [1/4]

template<IsSigned T>
T dl::Math::DisPow2 ( const std::array< T, 2 > &  a)

返回 向量 距离的平方

注解
有符号版本

在文件 dl_math.h 第 265 行定义.

◆ DisPow2() [2/4]

template<IsSigned T>
T dl::Math::DisPow2 ( const std::array< T, 2 > &  a,
const std::array< T, 2 > &  b 
)

返回 距离的平方

注解
有符号版本

在文件 dl_math.h 第 287 行定义.

◆ DisPow2() [3/4]

template<IsSigned T>
T dl::Math::DisPow2 ( const std::array< T, 3 > &  a)

在文件 dl_math.h 第 271 行定义.

◆ DisPow2() [4/4]

template<IsSigned T>
T dl::Math::DisPow2 ( const std::array< T, 4 > &  a)

在文件 dl_math.h 第 277 行定义.

◆ DisPow2U()

template<IsUnsigned T>
T dl::Math::DisPow2U ( const std::array< T, 2 > &  a,
const std::array< T, 2 > &  b 
)

返回 距离的平方

注解
无符号版本

在文件 dl_math.h 第 322 行定义.

◆ DistanceDiagonal()

template<typename C >
constexpr auto dl::Math::DistanceDiagonal ( const C &  p0,
const C &  p1 
)
constexpr

纹理区域转uv

对角线距离(注意不是真的对角线,而是取宽高较大者)

在文件 dl_math.h 第 594 行定义.

◆ DisU()

template<IsUnsigned T>
T dl::Math::DisU ( T  a,
T  b 
)

返回无符号类型的差值

在文件 dl_math.h 第 298 行定义.

◆ div_found()

constexpr unsigned dl::Math::div_found ( unsigned  n,
unsigned  d 
)
constexpr

无符号除法,返回四舍五入结果

参数
[in]n分子
[in]d分母

在文件 dl_math.h 第 496 行定义.

◆ div_found_fast()

constexpr unsigned dl::Math::div_found_fast ( unsigned  n,
unsigned  d 
)
constexpr

无符号除法,返回四舍五入结果

注解
分子n过大会溢出,但效率更高
参数
[in]n分子
[in]d分母

在文件 dl_math.h 第 509 行定义.

◆ DotProduct()

template<typename T , size_t N>
constexpr T dl::Math::DotProduct ( const std::array< T, N > &  a,
const std::array< T, N > &  b 
)
constexpr

点乘

在文件 dl_math.h 第 558 行定义.

◆ DrawLineBresenham()

std::vector< Point > dl::Math::DrawLineBresenham ( const Point &  p0,
const Point &  p1 
)

bresenham 画线算法

◆ DrawLineCover()

std::vector< Point > dl::Math::DrawLineCover ( const Point &  p0,
const Point &  p1 
)

覆盖 画线算法

注解
直线经过的网格都包含(会穿过对角线)

◆ DrawLineLerp()

std::vector< Point > dl::Math::DrawLineLerp ( const Point &  p0,
const Point &  p1 
)

线性插值 画线算法

◆ DrawLineOrth()

std::vector< Point > dl::Math::DrawLineOrth ( const Point &  p0,
const Point &  p1 
)

正交 画线算法

注解
只能竖着或横着走

◆ getCircle() [1/2]

std::vector< Point > dl::Math::getCircle ( const Point &  xy,
unsigned  rad 
)

返回圆形范围的节点,不考虑越界

参数
[in]rad传入0返回1个节点、传入1返回4个节点、传入2返回13个节点,依次类推

◆ getCircle() [2/2]

std::vector< PointU > dl::Math::getCircle ( const Size &  size,
const PointU &  xy,
unsigned  rad 
)

返回圆形范围的节点,考虑越界

参数
[in]rad传入0返回1个节点、传入1返回4个节点、传入2返回13个节点,依次类推
待办事项:
暂未测试

◆ IsDotInTriangle()

constexpr bool dl::Math::IsDotInTriangle ( const Position &  dot,
const Triangle &  triangle 
)
constexpr

判断点是否在三角形内

参数
[in]dot点
[in]triangle三角形

在文件 dl_math.h 第 750 行定义.

◆ IsOutRange()

template<typename T >
constexpr bool dl::Math::IsOutRange ( T  x,
T  a,
T  b 
)
constexpr

判断数值是否越界(前闭后开)

在文件 dl_math.h 第 123 行定义.

◆ IsRectInSize()

template<typename T >
constexpr bool dl::Math::IsRectInSize ( const std::array< T, 4 > &  rect,
const Size &  size 
)
constexpr

判断 矩形 在 大小 内,首先它必须是有效的矩形

参数
[in]rect矩形

在文件 dl_math.h 第 712 行定义.

◆ IsValidRect()

template<typename T >
constexpr bool dl::Math::IsValidRect ( const std::array< T, 4 > &  rect)
constexpr

‍**

----------------------------—隐藏含义获取-----------------------------— ** ‍**

判断 矩形 是否有效

参数
[in]rect矩形
注解
空矩形也是有效的

在文件 dl_math.h 第 701 行定义.

◆ IsXyInRect()

constexpr bool dl::Math::IsXyInRect ( const Point &  xy,
const Rect &  rect 
)
constexpr

判断 点是否在矩形内

参数
[in]rect矩形

在文件 dl_math.h 第 737 行定义.

◆ IsXyInSize()

constexpr bool dl::Math::IsXyInSize ( const Point &  xy,
const Size &  size 
)
constexpr

判断 点是否在大小内

在文件 dl_math.h 第 725 行定义.

◆ Limit()

template<typename T >
constexpr T dl::Math::Limit ( const T &  v,
const T &  v_min,
const T &  v_max 
)
constexpr

限制数值到 闭区间

注解
注意无符号误区
请使用Every::Clamp

在文件 dl_math.h 第 74 行定义.

◆ MergePath()

void dl::Math::MergePath ( std::list< Point > &  list_pos)

路径合并(网格路径)

注解
方向相同且相邻的节点合并(最终路径不变)

◆ MergePathDirect()

template<typename F >
void dl::Math::MergePathDirect ( std::list< Point > &  list_pos,
F  func_pass 
)

路径合并(网格路径)

注解
两点之间没有障碍物,则删除之间的(路径会发生变化)

在文件 dl_math.h 第 635 行定义.

◆ Normalize() [1/2]

template<IsSigned T, size_t N>
std::array< T, N > dl::Math::Normalize ( const std::array< T, N > &  v)

在文件 dl_math.h 第 343 行定义.

◆ Normalize() [2/2]

template<IsSigned T, size_t N>
void dl::Math::Normalize ( std::array< T, N > &  v)

向量单位化

在文件 dl_math.h 第 333 行定义.

◆ NormalizeFast()

template<size_t N>
void dl::Math::NormalizeFast ( std::array< float, N > &  v)

向量单位化,精度低速度快

在文件 dl_math.h 第 244 行定义.

◆ OffsetOrder()

constexpr float dl::Math::OffsetOrder ( float  order,
int  u = 1,
int  v = 0,
int  w = 0 
)
constexpr

偏移order

参数
[in]order原本order
[in]u偏移大小,用户使用
[in]v偏移大小,多个组使用
[in]w偏移大小,单个元素内使用
注解
正数使order变大,更远离屏幕
如果偏移出 [0, 1]的范围,则限制到范围,并输出警告
在一组内,优先使用负数靠近屏幕

在文件 dl_math.h 第 525 行定义.

◆ PI()

constexpr double dl::Math::PI ( unsigned  n,
unsigned  d = 1 
)
constexpr

返回PI的分数

参数
[in]n分子
[in]d分母

在文件 dl_math.h 第 369 行定义.

◆ Pow()

constexpr uint64_t dl::Math::Pow ( uint64_t  x,
uint8_t  n 
)
constexpr

返回x的n次方

参数
[in]x底数,n64
[in]n指数,n8[0, 255]

在文件 dl_math.h 第 134 行定义.

◆ Pow32()

constexpr uint32_t dl::Math::Pow32 ( uint32_t  x,
uint8_t  n 
)
constexpr

在文件 dl_math.h 第 143 行定义.

◆ RSqrt()

float dl::Math::RSqrt ( float  x)
inline

返回平方根的倒数

注解
经测试,此方法并比1.0f / sqrt快那么一点
类型转换也需要时间,如果是非内联函数也会变慢许多。

在文件 dl_math.h 第 224 行定义.

◆ Slerp()

Position4 dl::Math::Slerp ( const Position4 &  q0,
const Position4 &  q1,
const Float &  t 
)

球面线性插值

注解
普通线性插值存在于std::lerp

变量说明

◆ ARRAY_POW2

constexpr uint64_t dl::Math::ARRAY_POW2[]
constexpr
初始值:
= {
Pow(2,0),Pow(2,1),Pow(2,2),Pow(2,3),Pow(2,4),Pow(2,5),Pow(2,6),Pow(2,7),
Pow(2,8),Pow(2,9),Pow(2,10),Pow(2,11),Pow(2,12),Pow(2,13),Pow(2,14),Pow(2,15),
Pow(2,16),Pow(2,17),Pow(2,18),Pow(2,19),Pow(2,20),Pow(2,21),Pow(2,22),Pow(2,23),
Pow(2,24),Pow(2,25),Pow(2,26),Pow(2,27),Pow(2,28),Pow(2,29),Pow(2,30),Pow(2,31),
Pow(2,32),Pow(2,33),Pow(2,34),Pow(2,35),Pow(2,36),Pow(2,37),Pow(2,38),Pow(2,39),
Pow(2,40),Pow(2,41),Pow(2,42),Pow(2,43),Pow(2,44),Pow(2,45),Pow(2,46),Pow(2,47),
Pow(2,48),Pow(2,49),Pow(2,50),Pow(2,51),Pow(2,52),Pow(2,53),Pow(2,54),Pow(2,55),
Pow(2,56),Pow(2,57),Pow(2,58),Pow(2,59),Pow(2,60),Pow(2,61),Pow(2,62),Pow(2,63) }
constexpr uint64_t Pow(uint64_t x, uint8_t n)
返回x的n次方
Definition: dl_math.h:134

2的整数次幂列表

在文件 dl_math.h 第 156 行定义.

◆ ARRAY_POW2_32

constexpr uint32_t dl::Math::ARRAY_POW2_32[]
constexpr
初始值:
= {
Pow32(2,0),Pow32(2,1),Pow32(2,2),Pow32(2,3),Pow32(2,4),Pow32(2,5),Pow32(2,6),Pow32(2,7),
Pow32(2,8),Pow32(2,9),Pow32(2,10),Pow32(2,11),Pow32(2,12),Pow32(2,13),Pow32(2,14),Pow32(2,15),
Pow32(2,16),Pow32(2,17),Pow32(2,18),Pow32(2,19),Pow32(2,20),Pow32(2,21),Pow32(2,22),Pow32(2,23),
Pow32(2,24),Pow32(2,25),Pow32(2,26),Pow32(2,27),Pow32(2,28),Pow32(2,29),Pow32(2,30),Pow32(2,31) }
constexpr uint32_t Pow32(uint32_t x, uint8_t n)
Definition: dl_math.h:143

在文件 dl_math.h 第 165 行定义.