StrokeCollection の HitTest メソッドを使用できます。ソリューションのパフォーマンスをこの実装と比較したところ、HitTest メソッドのパフォーマンスが優れていることがわかりました。あなたのマイレージなど
// get our position on our parent.
var ul = TranslatePoint(new Point(0, 0), this.Parent as UIElement);
// get our area rect
var controlArea = new Rect(ul, new Point(ul.X + ActualWidth, ul.Y + ActualHeight));
// hit test for any strokes that have at least 5% of their length in our area
var strokes = _formInkCanvas.Strokes.HitTest(controlArea, 5);
if (strokes.Any())
{
// do something with this new knowledge
}
ここでドキュメントを見つけることができます:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.ink.strokecollection.hittest?view=netframework-4.7.2
さらに、任意の点が rect 内にあるかどうかのみを気にする場合は、以下のコードを使用できます。StrokeCollection.HitTest よりも 1 桁高速です。これは、ストロークのパーセンテージを気にしないため、作業量が大幅に減るためです。
private bool StrokeHitTest(Rect bounds, StrokeCollection strokes)
{
for (int ix = 0; ix < strokes.Count; ix++)
{
var stroke = strokes[ix];
var stylusPoints = stroke.DrawingAttributes.FitToCurve ?
stroke.GetBezierStylusPoints() :
stroke.StylusPoints;
for (int i = 0; i < stylusPoints.Count; i++)
{
if (bounds.Contains((Point)stylusPoints[i]))
{
return true;
}
}
}
return false;
}