GraceFt v2.3
开源图形引擎 EGE(Easy Graphics Engine) 的高层封装库
 
载入中...
搜索中...
未找到
GFt::Point< T > 模板类 参考

泛型点类 更多...

#include <Point.hpp>

Public 成员函数

constexpr Point (const Point &p)=default
 
constexpr Point (Point &&p)=default
 
constexpr Point (T x=static_cast< T >(0), T y=static_cast< T >(0))
 构造函数
 
constexpr auto angle () const
 计算相角(弧度制)
 
constexpr auto norm () const
 计算模长
 
constexpr operator bool () const
 将点转换到 bool 值
 
template<typename U >
requires std::is_arithmetic_v<U>
constexpr operator Point< U > () const
 Point 类型转换函数
 
constexpr operator Vec2< T > () const
 Vec2<T> 类型转换函数
 
constexpr bool operator! () const
 逻辑非操作符重载
 
constexpr bool operator!= (const Point &p) const
 不等于判断操作符重载
 
constexpr T operator* (const Point &p) const
 乘法操作符重载(点积)
 
constexpr Point operator* (T k) const
 乘法操作符重载
 
constexpr Pointoperator*= (T k)
 乘且赋值操作符重载
 
constexpr Point operator+ (const Point &p) const
 加法操作符重载
 
constexpr Pointoperator+= (const Point &p)
 加且赋值操作符重载
 
constexpr Point operator- (const Point &p) const
 减法操作符重载
 
constexpr Pointoperator-= (const Point &p)
 减且赋值操作符重载
 
constexpr Point operator/ (T k) const
 除法操作符重载
 
constexpr Pointoperator/= (T k)
 除且赋值操作符重载
 
constexpr Pointoperator= (const Point &p)=default
 
constexpr Pointoperator= (Point &&p)=default
 
constexpr bool operator== (const Point &p) const
 等于判断操作符重载
 
constexpr Tx ()
 点的 x 坐标
 
constexpr const Tx () const
 函数 x() 的 const 版本
 
constexpr Ty ()
 点的 y 坐标
 
constexpr const Ty () const
 函数 y() 的 const 版本
 

友元

constexpr friend auto distance (const Point &p1, const Point &p2)
 计算点之间的距离
 
std::ostream & operator<< (std::ostream &os, const Point &p)
 流操作符重载
 

详细描述

template<typename T>
requires std::is_arithmetic_v<T>
class GFt::Point< T >

泛型点类

此类用于表示一个二维坐标点的几何信息,并提供了常用的几何操作

此类是 基础设施库 => 复合数据类型 的一部分

模板参数
T点的坐标类型,要求为算术类型

构造及析构函数说明

◆ Point() [1/3]

template<typename T >
GFt::Point< T >::Point ( T x = static_cast<T>(0),
T y = static_cast<T>(0) )
inlineexplicitconstexpr

构造函数

参数
xx 坐标
yy 坐标

◆ Point() [2/3]

template<typename T >
GFt::Point< T >::Point ( const Point< T > & p)
constexprdefault

◆ Point() [3/3]

template<typename T >
GFt::Point< T >::Point ( Point< T > && p)
constexprdefault

成员函数说明

◆ angle()

template<typename T >
auto GFt::Point< T >::angle ( ) const
inlineconstexpr

计算相角(弧度制)

这相当于复数 z=x+iy 的辐角主值 arg(z) (弧度制)

返回
点的相角(弧度制)

◆ norm()

template<typename T >
auto GFt::Point< T >::norm ( ) const
inlineconstexpr

计算模长

这相当于二维向量的模长(即|p|)

返回
点的模长

◆ operator bool()

template<typename T >
GFt::Point< T >::operator bool ( ) const
inlineexplicitconstexpr

将点转换到 bool 值

若 x 和 y 坐标不全为 0,则返回 true,否则返回 false

返回
转化后的 bool 值

◆ operator Point< U >()

template<typename T >
template<typename U >
requires std::is_arithmetic_v<U>
GFt::Point< T >::operator Point< U > ( ) const
inlineconstexpr

Point 类型转换函数

用于将 Point<T> 类型转换为 Point 类型

模板参数
U坐标转换的目标类型,要求为算术类型
返回
转换后的点对象

◆ operator Vec2< T >()

template<typename T >
GFt::Point< T >::operator Vec2< T > ( ) const
inlineconstexpr

Vec2<T> 类型转换函数

用于将 Point<T> 类型转换为 Vec2<T> 类型

模板参数
T坐标转换的目标类型,要求为算术类型
返回
转换后的 Vec2 对象

◆ operator!()

template<typename T >
bool GFt::Point< T >::operator! ( ) const
inlineconstexpr

逻辑非操作符重载

若 x 和 y 坐标不全为 0,则返回 false,否则返回 true

返回
逻辑非后的 bool 值

◆ operator!=()

template<typename T >
bool GFt::Point< T >::operator!= ( const Point< T > & p) const
inlineconstexpr

不等于判断操作符重载

此函数对于浮点数比较是安全的

参数
p另一个点对象
返回
两个点是否不相等

◆ operator*() [1/2]

template<typename T >
T GFt::Point< T >::operator* ( const Point< T > & p) const
inlineconstexpr

乘法操作符重载(点积)

这相当于两个二维向量的点积

参数
p另一个点对象
返回
两个点的点积

◆ operator*() [2/2]

template<typename T >
Point GFt::Point< T >::operator* ( T k) const
inlineconstexpr

乘法操作符重载

这相当于二维向量的数乘

参数
k一个标量
返回
数乘后的点

◆ operator*=()

template<typename T >
Point & GFt::Point< T >::operator*= ( T k)
inlineconstexpr

乘且赋值操作符重载

如同 this = this * k

参数
k一个标量
返回
自身

◆ operator+()

template<typename T >
Point GFt::Point< T >::operator+ ( const Point< T > & p) const
inlineconstexpr

加法操作符重载

这相当于两个二维向量的加法

参数
p另一个点对象
返回
两个点的和

◆ operator+=()

template<typename T >
Point & GFt::Point< T >::operator+= ( const Point< T > & p)
inlineconstexpr

加且赋值操作符重载

如同 this = this + p

参数
p另一个点对象
返回
自身

◆ operator-()

template<typename T >
Point GFt::Point< T >::operator- ( const Point< T > & p) const
inlineconstexpr

减法操作符重载

这相当于两个二维向量的减法

参数
p另一个点对象
返回
两个点的差

◆ operator-=()

template<typename T >
Point & GFt::Point< T >::operator-= ( const Point< T > & p)
inlineconstexpr

减且赋值操作符重载

如同 this = this - p

参数
p另一个点对象
返回
自身

◆ operator/()

template<typename T >
Point GFt::Point< T >::operator/ ( T k) const
inlineconstexpr

除法操作符重载

这相当于二维向量的数乘

参数
k一个标量
返回
数乘(1/k)后的点

◆ operator/=()

template<typename T >
Point & GFt::Point< T >::operator/= ( T k)
inlineconstexpr

除且赋值操作符重载

如同 this = this / k

参数
k一个标量
返回
自身

◆ operator=() [1/2]

template<typename T >
Point & GFt::Point< T >::operator= ( const Point< T > & p)
constexprdefault

◆ operator=() [2/2]

template<typename T >
Point & GFt::Point< T >::operator= ( Point< T > && p)
constexprdefault

◆ operator==()

template<typename T >
bool GFt::Point< T >::operator== ( const Point< T > & p) const
inlineconstexpr

等于判断操作符重载

此函数对于浮点数比较是安全的

参数
p另一个点对象
返回
两个点是否相等

◆ x() [1/2]

template<typename T >
T & GFt::Point< T >::x ( )
inlineconstexpr

点的 x 坐标

返回
x 坐标

◆ x() [2/2]

template<typename T >
const T & GFt::Point< T >::x ( ) const
inlineconstexpr

函数 x() 的 const 版本

返回
x 坐标
参见
x()

◆ y() [1/2]

template<typename T >
T & GFt::Point< T >::y ( )
inlineconstexpr

点的 y 坐标

返回
y 坐标

◆ y() [2/2]

template<typename T >
const T & GFt::Point< T >::y ( ) const
inlineconstexpr

函数 y() 的 const 版本

返回
y 坐标
参见
y()

友元及相关符号说明

◆ distance

template<typename T >
friend auto distance ( const Point< T > & p1,
const Point< T > & p2 )
friend

计算点之间的距离

此函数求得两个点之间的欧氏距离

参数
p1第一个点对象
p2第二个点对象
返回
两个点之间的距离

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream & os,
const Point< T > & p )
friend

流操作符重载

参数
os输出流
p点对象
返回
输出流 os