`
- 浏览:
935683 次
-
/**//////////////////////////////////////////////////////////////////////////////////tpoint2.h
//Sunny:2007-2-7
//Author:cheungmine-cheungmine@gmail.com
//Copyrightbycheungmine
/**////////////////////////////////////////////////////////////////////////////////#ifndef_tpoint2_h_
#define_tpoint2_h_
#include"geomdef.h"
//Tmustbefloatordouble
template<typenameT>
structGEOM_EXPt_point2
...{
union...{
struct
...{
Tx,y;
};
Tv[2];
};
//Defaultconstructor,definedfortemplateclasses
t_point2()
...{}
//Constructapointwith3giveninputs
t_point2(T_x,T_y):x(_x),y(_y)
...{}
t_point2(constt_point2&in)
...{
x=in.x;
y=in.y;
}
//Reassignapointwithoutmakingatemporarystructure
voidassign(T_x,T_y)
...{
x=_x;y=_y;
}
//Returnthemagnitudeofapoint
Tmag()const
...{
return(T)sqrt(x*x+y*y);
}
//Thelengthofthevectorsquared(toavoidthesqrt())
Tmagsq()const
...{
return(T)(x*x+y*y);
}
//Normalizesavector(makesit'slengthone)
voidnorm()
...{
TinvMag=1.f/mag();
(*this)*=invMag;
}
//Computesthedistancebetweentwovectors
staticTdist(constt_point2&a,constt_point2&b)
...{
//can'tusethesubtractionoperator(it'snotdefinedyet!)
t_point2vec(b.x-a.x,b.y-a.y);
returnvec.mag();
}
//Computesthedistancesquarebetweentwovectors
staticTdistsq(constt_point2&a,constt_point2&b)
...{
//can'tusethesubtractionoperator(it'snotdefinedyet!)
t_point2vec(b.x-a.x,b.y-a.y);
returnvec.magsq();
}
//
//operatorsoverload:
//
//Accumulativeadditionoftwovectors
t_point2&operator+=(constt_point2&in)
...{
x+=in.x;
y+=in.y;
return*this;
}
//Accumulativesubtractionoftwovectors
t_point2&operator-=(constt_point2&in)
...{
x-=in.x;
y-=in.y;
return*this;
}
//Accumulativemultiplicationofavectorbyascalar
t_point2&operator*=(constT&s)
...{
x*=s;
y*=s;
return*this;
}
//Accumulativedivisionofavectorbyascalar
t_point2&operator/=(constT&s)
...{
Tinv=1.f/s;
x*=inv;
y*=inv;
return*this;
}
t_point2operator-()
...{
returnt_point2(-x,-y);
}
//
//Constantvectors
//
staticconstt_point2<T>Zero;
staticconstt_point2<T>i;
staticconstt_point2<T>j;
};
//Addstwopointstogether:ret=a+b
template<typenameT>
inlineconstt_point2<T>operator+(constt_point2<T>&a,constt_point2<T>&b)
...{
returnt_point2<T>(a.x+b.x,a.y+b.y);
}
//Subtractstopoints:ret=a-b
template<typenameT>
inlineconstt_point2<T>operator-(constt_point2<T>&a,constt_point2<T>&b)
...{
returnt_point2<T>(a.x-b.x,a.y-b.y);
}
//Scalesavectorbyascalar:ret=a*s
template<typenameT>
inlineconstt_point2<T>operator*(constt_point2<T>&a,constT&s)
...{
returnt_point2<T>(a.x*s,a.y*s);
}
//Scalesavectorbyascalar:ret=s*b
template<typenameT>
inlineconstt_point2<T>operator*(constT&s,constt_point2<T>&b)
...{
returnt_point2<T>(s*b.x,s*b.y);
}
//Dividesavectorbyascalar:ret=a/f
template<typenameT>
inlineconstt_point2<T>operator/(constt_point2<T>&a,constT&s)
...{
Tinv=1.f/s;
returnt_point2<T>(a.x*inv,a.y*inv);
}
//Performsavectordotproduct:ret=adotb
template<typenameT>
inlineconstToperator*(constt_point2<T>&a,constt_point2<T>&b)
...{
returna.x*b.x+a.y*b.y;
}
//VectorEquality,epsilonusedduetonumericalimprecision
template<typenameT>
inlinebooloperator==(constt_point2<T>&a,constt_point2<T>&b)
...{
if(fabs(a.x-b.x)<EPSILON&&fabs(a.y-b.y)<EPSILON&&fabs(a.z-b.z)<EPSILON)
returntrue;
returnfalse;
}
#endif//_tpoint2_h_
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
Delphi贪吃蛇双人对战版【附代码】, tingdun1,tingdun2:boolean; //停顿标志 nandu:1..12;//子界难度类型 jiemian,shiwu,baowu:tjiemian;//基本界面数据,食物,宝物位置数据 fangxian1:char;//运动方向,...
const AMousePos: TPoint; var AHintText: TCaption; var AIsHintMultiLine: Boolean; var AHintTextRect: TRect); { Public declarations } published property Hide: Boolean read FHide write FHide; ...
BeginPosition:TPoint; //用户拖动Images组件时的起始位置 Procedure ImagesMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Procedure ImagesMouseUp(Sender: T...
MousePos: TPoint): Boolean; override; { Published declarations } end; procedure Register; implementation function TDBGrid3D.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: ...
Pos: TPoint): THintWindow 显示自定义的提示窗口,提示窗口不会自动隐藏,用THintWindow可实现隐藏。 事件 TsFrameBar.OnFrameShow 和 TsFrameBar.OnFrameClose frame在显示或关闭后会触发 TsAlphaHints....
Point: TPoint; // 雪点位置 Color: Integer; // 先前颜色 Speed: Integer; // 下落速率 nMove: Integer; // 下落距离 Stick: Integer; // '粘连'度 SnowNodes: array[0..SnowNumber] of SnowNode;...
PosPoint:TPoint; begin PosPoint.x:=X; PosPoint.y:=Y; (Source As TListView).Selected.SetPosition(PosPoint); end; 释放鼠标后,通过设置OnDragOver事件中的Accept参数来决定是否接受拖动操作。在...
mousepos: TPoint; begin GetCursorPos(mousepos); //获取鼠标位置 case msg.LParam of WM_LBUTTONUP: // 在托盘区点击左键后 begin Form1.Visible := not Form1.Visible; // 显示主窗体与否 Shell_...
xpbutton控件 unit XPButton; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ActnList, StdCtrls, ImgList, XPButtonClass, ... GlyphPos: TPoint; TextBounds: TRect;
Label2: TLabel; xpWindow1: TxpWindow; AAFadeText1: TAAFadeText; private { Private declarations } public { Public declarations } end; var Form3: TForm3; implementation {$R *.dfm} end. unit...
Result := IfThen(RandomRange(0, 36635) mod 2 = 0, -1, 1); end; begin Randomize; for I := Max_PTCount - 1 downto 0 do begin FPTArray[i].X := Sign()*RandomRange(0, 36635) mod FXStrength*i div ...
zTouch * Zepto.js v1.0.1 touch extend (Zepto.js v1.0.1 swipe/touch扩展) Zepto.js v1.0.1版本的touch.js模块引入...提供内部属性设置接口,可在内部tPoint中加入用户自定义属性; 支持手势横向滑动,同时保证浏览
窗口中的弹出式右键菜单-delphi PopupMenu源码, ... Poin:TPoint; begin Poin := Point(Button1.Left,Button1.Top Button1.Height); Poin := ClientToScreen(Poin); PopupMenu1.Popup(Poin.X,Poin.Y); end;
pointnum:array [1..2] of integer; begin //四边形顶点坐标,首末点封闭 thepoint[1]:=point(135,99); thepoint[2]:=point(105,183); thepoint[3]:=point(129,201); thepoint[4]:=point(188,92); ...
2、 列说明: Columns设计时编辑,支持设置数据类型:TDatatype; Checkbox支持,自行设置是否值; EditStye:esSimple esEllipsis esPickList3种类型,只有esSimple支持Checkbox; esPickList 类型需要...
function GetCoord(const S: string): TPoint; public function LoadFile(FileName SheetName: String): boolean; overload; function LoadFile(FileName: String; SheetNum: integer): boolean; overload; end;
pt: TPoint; / /消息创建时的鼠标位置 。end; 。消息中有什么? 。是否觉得一个消息记录中的信息像希腊语一样?如果是这样,那么看一看下面的解释: 。hwnd 32位的窗口句柄。窗口可以是任何类型的屏幕对象,因为...
消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了。例如,单击鼠标、改变窗口尺寸、按下键盘上的一个键...由于W P a r a m、l P a r a m和P o i n t e r都是3 2位的, 因此,它们之间可以相互转换。
function DaysBetween(Date1, Date2: TDateTime): integer; {//得到两个日期相隔的天数} //▎============================================================▎// //▎===================③ 扩展的位操作函数 ====...