# Direct2D (30) : 判断几何对象的关系 - ID2D1Geometry.CompareWithGeometry() 转

涂孟超

``````{相关常量}
//D2D1_GEOMETRY_RELATION = type Integer;
D2D1_GEOMETRY_RELATION_UNKNOWN      = 0;  //未知
D2D1_GEOMETRY_RELATION_DISJOINT     = 1;  //不相交
D2D1_GEOMETRY_RELATION_IS_CONTAINED = 2;  //属于
D2D1_GEOMETRY_RELATION_CONTAINS     = 3;  //包含
D2D1_GEOMETRY_RELATION_OVERLAP      = 4;  //重叠``````

``````uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
const
arr1: array[0..3] of string = ('红色', '黄色', '绿色', '蓝色');
arr2: array[1..4] of string = ('不相交于', '属于', '包含', '相交于');
arrColor: array[0..3] of TColor = (clRed, clYellow, clGreen, clBlue);
var
cvs: TDirect2DCanvas;
iEllipseGeometry: ID2D1EllipseGeometry;
iRectangleGeometrys: array[0..3] of ID2D1RectangleGeometry;
i,h: Integer;
x: D2D1_GEOMETRY_RELATION;
strArr: array[0..3] of string;
begin
D2DFactory.CreateEllipseGeometry(D2D1Ellipse(D2D1PointF(150, 150), 50, 50), iEllipseGeometry);
D2DFactory.CreateRectangleGeometry(D2D1RectF(90, 90, 210, 210), iRectangleGeometrys[0]);
D2DFactory.CreateRectangleGeometry(D2D1RectF(130, 130, 170, 170), iRectangleGeometrys[1]);
D2DFactory.CreateRectangleGeometry(D2D1RectF(70, 130, 110, 170), iRectangleGeometrys[2]);
D2DFactory.CreateRectangleGeometry(D2D1RectF(220, 130, 260, 170), iRectangleGeometrys[3]);

for i := 0 to 3 do
begin
iEllipseGeometry.CompareWithGeometry(iRectangleGeometrys[i], TD2DMatrix3x2F.Identity, 0, x);
strArr[i] := Format('圆 "%s"'#9'%s矩形', [arr2[x], arr1[i]]);
end;

cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
cvs.BeginDraw;
cvs.RenderTarget.Clear(D2D1ColorF(clWhite));

for i := 0 to 3 do
begin
cvs.Brush.Color := arrColor[i];
cvs.FillGeometry(iRectangleGeometrys[i]);
end;

cvs.Font.Size := 10;
cvs.Brush.Color := clWhite;
h := cvs.TextHeight(strArr[0]);
for i := 0 to 3 do cvs.TextOut(8, h*i+5, strArr[i]);

cvs.EndDraw;
cvs.Free;
end;``````

### 涂孟超

PostgreSQL+PostGIS 的使用

2017/11/07
0
0
postgis常用函数（99%转载 1%原创）

1,基本操作函数 AddGeometryColumn(<schemaname>, <tablename>, <columnname>, <srid>, <type>, <dimension>) 给一个已存在属性数据表增加一个几何字段(geomtry column)。schemaname 指表的模......

2013/01/07
0
0

Dy_
2014/01/16
8.2K
10
Data Lake Analytics的Geospatial分析函数

0. 简介 为满足部分客户在云上做Geometry数据的分析需求，阿里云Data Lake Analytics（以下简称：DLA）支持多种格式的地理空间数据处理函数，符合Open Geospatial Consortium’s (OGC) OpenG...

julian.zhou
11/14
0
0
Direct2D教程（十）绘制文本

2017/10/17
0
0

Spring异常之Druid – unregister mbean error

Spring异常之Druid – unregister mbean error 2017年04月19日 12:13:42 Dr.Zhu 阅读数：6688 版权声明：本文为博主原创文章，未经博主允许不得转载。 https://blog.csdn.net/zt_fucker/arti...

linjin200
15分钟前
1
0

18分钟前
1
0
Spark2.0操作Hbase

19分钟前
1
0
【转】你会用哪些JavaScript循环遍历

kaixin_code
21分钟前
1
0
mysql的锁

MySQL的锁 全局锁：对数据库实例加锁 MySQL提供了一个加全局读锁的方法：Flush tables with read lock(FTWRL) 使用场景：做全库逻辑备份。 官方自带的逻辑备份工具mysqldump，使用时带上参数...

25分钟前
2
0