Bug in geometry Hit-Testing

后端 未结 1 1162
情话喂你
情话喂你 2021-01-12 17:39

I have a DrawingVisual element that rappresents a path which geometry is described by this syntax:

\"m106,59.3c0-1.98,0,0-4.95,0.989-3.96,0.989-13.8,

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 18:32

    It seems like hit-testing considers the position of the shapes to which was applied a reverse order of transformations. This would explain why my path is intersected only and not fully inside the RectangleGeometry argument of MyCanvas.GetVisuals method.

    Waiting for a better response, i implemented the hit-test with a not hit-testing method, now part of MyCanvas class:

    public List GetVisuals(Rect Area)
    {
       this.Hits.Clear();
    
       foreach (DrawingVisual DVisual in this.Visuals) {
           if (Area.Contains(DVisual.DescendantBounds))
               this.Hits.Add(DVisual);
       }
    
       return this.Hits;
    }
    

    EDIT:

    As Mike Danes (moderator on MSDN forum) explains in this thread:

    "Is it really possible that this is a bug in geometry hit-testing?"

    I'm 99% sure this is a bug. Drawing and hit testing should use the same transform order. The reason it works correctly with TransformGroup is because this way you only push only one transform in the drawing context and this avoids the wrong multiplication order in the hit test drawing context. Note that this has nothing to do with the fact that the order used in TranformGroup is different from the push order.

    0 讨论(0)
提交回复
热议问题