• 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;
    


    效果图:



  • 相关阅读:
    java8之lambda表达式(默认方法)
    结合 CSS3 & Canvas 模拟人行走的效果
    使用 SVG 实现一个漂亮的页面预加载效果
    借助 CSS Colorguard 来避免使用重复的颜色
    网站制作素材:创意的404错误页面下载
    使用 CSS3 打造一组质感细腻丝滑的按钮
    经典!HTML5 Canvas 模拟可撕裂布料效果
    实用工具:检测过时的浏览器并提醒用户更新
    Hya.io – 基于 Web 的数字音频工作站
    SlidesJS
  • 原文地址:https://www.cnblogs.com/del/p/2008765.html
Copyright © 2020-2023  润新知