它们都是结构, TPointF、TRectF 属新增, 其它也都有升级; 现在都拥有丰富的方法和方便的运算符重载; 且有一组相关的公共函数.
这组内容重要的是它们都来自 System.Types 单元, 也就是不仅仅在 FM 中可用.
TPoint:
Create(); //
{运算符重载}
Equal; // =
NotEqual; // <>
Add; // +
Subtract; // -
Implicit; // 可从 TSmallPoint 隐身转换到 TPoint
Explicit; // 可显示转换到 TSmallPoint
{方法}
Distance(); // 计算两点之间的距离
SetLocation(); // 重定位
Offset(); // 偏移
Add(); // 加
Subtract(); // 减
IsZero(); // 是否在 [0,0] 点
{数据成员}
X,Y: Longint;
{ 测试 }
procedure TForm1.Button1Click(Sender: TObject);
var
p1,p2,p3: TPoint;
begin
p1 := TPoint.Create(11, 22);
p2.Create(11, 11);
p3 := p1 + p2;
ShowMessageFmt('%d,%d', [p3.X, p3.Y]); //22,33
p3.SetLocation(0, 0);
p3 := p1.Add(p2);
ShowMessageFmt('%d,%d', [p3.X, p3.Y]); //22,33
end;
TPointF: 比 TPoint 多出三个方法:
Ceiling(); //
Truncate(); //
Round(); //
procedure TForm1.Button1Click(Sender: TObject);
var
pf: TPointF;
p1,p2,p3: TPoint;
begin
pf.Create(1.4, 1.6);
p1 := pf.Ceiling;
p2 := pf.Truncate;
p3 := pf.Round;
ShowMessageFmt('%d,%d %d,%d %d,%d', [p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y]); //2,2 1,1 1,2
end;
TSmallPoint: 用得少, 成员也少.
Create(); //
{运算符重载}
Equal; // =
NotEqual; // <>
Add; // +
Subtract; // -
{方法}
Add(); // 加
Subtract(); // 减
Distance(); // 计算两点间距
IsZero(); // 是否是 [0,0] 点
{数据成员}
X,Y: SmallInt;
TSize:
Create(); //
{运算符重载}
Equal; // =
NotEqual; // <>
Add; // +
Subtract; // -
{方法}
Add(); // 加
Subtract(); // 减
Distance(); // 计算两点间距
IsZero(); // 是否是 [0,0] 点
{属性}
Width; //
Height; //
{数据成员}
cx,cy: Single;
TRect:
Create(); //建立时和可同时规格化矩形; 参见 NormalizeRect() 方法
{运算符重载}
Equal; // =
NotEqual; // <>
Add; // + (并集)
Multiply; // * (交集)
{类方法}
Empty; //获取一个空的 TRect 对象; 内联
Intersect; //获取两个矩形的交集矩形
Union; //获取两个矩形的并集矩形
{方法}
NormalizeRect(); //规格化矩形; 当 Top > Bottom 或 Left > Right 时, 会置换数据使之合理.
IsEmpty(); //是否为空
Contains(); //是否包含指定点或指定矩形
IntersectsWith(); //判断和指定矩形是否交叉
Intersect(); //和指定矩形进行交集运算
Union(); //和指定矩形进行并集运算
Offset(); //偏移
SetLocation(); //设置新原点
Inflate(); //放大矩形(保持中心点)
CenterPoint(); //获取中心点
SplitRect(); //切除, TSplitRectType 枚举(Left、Top、Right、Bottom)指示要留住的一边
{属性}
Width: Integer; //有这些属性很方便
Height: Integer; //
Size: TSize; //
Location: TPoint; //
{数据结构, 这同前}
(Left, Top, Right, Bottom: Longint) 或 (TopLeft, BottomRight: TPoint)
TRectF: 只比 TRect 多出了转换到 TRect 时关于小数取舍的三个方法.
Ceiling(); //
Truncate(); //
Round(); //
相关的公共函数与过程:
{ function }
EqualRect(); //判断 TRect 或 TRectF 是否相等
Rect(); //构建 TRect
RectF(); //构建 TRectF
NormalizeRectF(); //从 TPointF 数组规格化出一个 TRectF
NormalizeRect(); //规格化 TRectF
RectWidth(); //获取矩形宽度
RectHeight(); //获取矩形高度
RectCenter(); //让矩形在另一指定矩形中居中
Bounds(); //根据原点、宽、高构建矩形
Point(); //构建 TPoint
PointF(); //构建 TPointF
MinPoint(); //比对两个点返回小的(优先判断了 Y)
ScalePoint(); //按指定比例移动点
SmallPoint(); //构建 TSmallPoint
PtInRect(); //判断点是否在指定矩形中
PtInCircle(); //判断点是否在指定了中心与半径的圆中
IntersectRect(); //判断两矩形是否相交
UnionRect(); //结合两矩形
IsRectEmpty(); //判断矩形是否为空
OffsetRect(); //偏移矩形
CenterPoint(); //获取矩形中心点
SplitRect(); //矩形切除
CenteredRect(); //算出两个矩形的中间过渡矩形; 应该是用于动画的
IntersectRectF(); //输出两矩形的交集
UnionRectF(); //输出两矩形的并集
{ procedure }
MultiplyRect(); //按比放缩矩形
InflateRect(); //按量放缩矩形