zoukankan      html  css  js  c++  java
  • 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;
    


    效果图:



  • 相关阅读:
    函数Sort()
    数据窗口中数值型对象的显示格式
    函数IsValid()
    20130109显示器无反应
    DropDownPictureListBox设置默认项
    大数据
    字符串函数Mid()
    Jquery获取当前元素所在表格的行列数
    关于模式窗口中treeView问题
    格式化字符串长度 超出指定长度用....代替
  • 原文地址:https://www.cnblogs.com/del/p/2008765.html
Copyright © 2011-2022 走看看