标签:
unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TVerctor = record X,Y,Z:Pointer; VerctorType :(vtInteger,vtDouble); public class operator Equal(const Left,Right:TVerctor): Boolean; end; TForm2 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} { TVerctor } const verctor_offset_integer=0; verctor_offset_double=0.0001; class operator TVerctor.Equal(const Left, Right: TVerctor): Boolean; begin if (Left.VerctorType<>Right.VerctorType) then Exit(False); if (Left.VerctorType=vtInteger) then result := (abs(PInteger(Left.X)^-PInteger(Right.X)^)<=verctor_offset_integer) and (abs(PInteger(Left.Y)^-PInteger(Right.Y)^)<=verctor_offset_integer) and (abs(PInteger(Left.Z)^-PInteger(Right.Z)^)<=verctor_offset_integer) else if (Left.VerctorType=vtDouble) then Result := (abs(PDouble(Left.X)^-PDouble(Right.X)^)<=verctor_offset_double) and (abs(PDouble(Left.Y)^-PDouble(Right.Y)^)<=verctor_offset_double) and (abs(PDouble(Left.Z)^-PDouble(Right.Z)^)<=verctor_offset_double) end; procedure TForm2.Button1Click(Sender: TObject); var Verctor1,Verctor2:TVerctor; x,y,z:Double; x1,y1,z1:Double; begin x:=100.1; y:=200.2; z:=300.0001; Verctor1.X:=@x; Verctor1.Y:=@y; Verctor1.Z:=@z; Verctor1.VerctorType:=vtDouble; x1:=100.1; y1:=200.2; z1:=300.0002; Verctor2.X:=@x1; Verctor2.Y:=@y1; Verctor2.Z:=@z1; Verctor2.VerctorType:=vtDouble; if Verctor1=Verctor2 then ShowMessage(‘ok‘); end; end.
虽然可以实现,但不是我想要的
标签:
原文地址:http://www.cnblogs.com/ZhouXiHong/p/4385699.html