Direct2D (30) : 判断几何对象的关系 - ID2D1Geometry.CompareWithGeometry()
Direct2D (30) : 判断几何对象的关系 - ID2D1Geometry.CompareWithGeometry()
涂孟超 发表于3年前
Direct2D (30) : 判断几何对象的关系 - ID2D1Geometry.CompareWithGeometry()
  • 发表于 3年前
  • 阅读 4
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   


{相关常量}
//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;


效果图:



共有 人打赏支持
粉丝 13
博文 2004
码字总数 14107
×
涂孟超
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: