Поделиться через


Stroke.GetRectangleIntersections - метод

Обновлен: Ноябрь 2007

Returns an array of StrokeIntersection structures that indicate where a Stroke object intersects a given Rectangle.

Пространство имен:  Microsoft.Ink
Сборка:  Microsoft.Ink (в Microsoft.Ink.dll)

Синтаксис

'Декларация
Public Function GetRectangleIntersections ( _
    intersectRectangle As Rectangle _
) As StrokeIntersection()
'Применение
Dim instance As Stroke
Dim intersectRectangle As Rectangle
Dim returnValue As StrokeIntersection()

returnValue = instance.GetRectangleIntersections(intersectRectangle)
public StrokeIntersection[] GetRectangleIntersections(
    Rectangle intersectRectangle
)
public:
array<StrokeIntersection>^ GetRectangleIntersections(
    Rectangle intersectRectangle
)
public StrokeIntersection[] GetRectangleIntersections(
    Rectangle intersectRectangle
)
public function GetRectangleIntersections(
    intersectRectangle : Rectangle
) : StrokeIntersection[]

Параметры

Возвращаемое значение

Тип: array<Microsoft.Ink.StrokeIntersection[]
Returns an array of StrokeIntersection structures that indicate where a Stroke object intersects the intersectRectangle parameter.

Заметки

This method returns zero or multiple sets of indices that represent the beginning and the end of the segments of the stroke that intersect the rectangle. If a stroke passes straight through a rectangle, interecting the boundary in two places, the set of indices are made of the floating point index values for each intersection. If a stroke intersects a rectangle more than two times, the number of indices is increased by the number of intersections.

If the stroke begins within the test rectangle, the BeginIndex property of the first StrokeIntersection element is set to -1. If the stroke ends within the test rectangle, the EndIndex property of the last StrokeIntersection element is set to -1. If the stroke is wholly contained within the rectangle, the returned array will have a single StrokeIntersection structure with both the BeginIndex property and the EndIndex property set to -1. If the stroke is wholly outside the test rectangle, an empty StrokeIntersection array is returned.

As an example, if a stroke begins inside the test rectangle, leaves the boundaries of the rectangle, returns inside, and leaves again, then the GetRectangleIntersections method might return {{-1, 1.4}, {5.5, 10.1}} to describe the two segments of the stroke falling within the rectangle.

The StrokeIntersection structures that this method returns contain paired floating point index values that indicate the locations where the intersections occur. A floating point index is a float value that represents a location somewhere between two points in the Stroke object. As examples, if 0.0 is the first point in the stroke and 1.0 is the second point in the stroke, 0.5 is halfway between the first and second points. Similarly, a floating point index value of 37.25 represents a location that is 25 percent along the line between points 37 and 38 of the stroke.

Примеры

In this example, all segments of a passed Stroke object that are inside the specified Rectangle structure are deleted. This is acomplished by examining the StrokeIntersection structures to determine where to split the passed Stroke object, and which segments to delete.

Private Sub DeleteInsideRectangle(ByVal S As Stroke, ByVal R As Rectangle)
    ' get the StrokeIntersection array
    Dim SI() As StrokeIntersection = S.GetRectangleIntersections(R)
    ' examine each StrokeIntersection
    ' must work backwards through the array so that when splitting, 
    ' the remaining intersections are still valid for S
    For k As Integer = SI.Length - 1 To 0 Step -1

        Dim enterRect As Single = SI(k).BeginIndex
        Dim exitRect As Single = SI(k).EndIndex

        ' check if the whole stroke is inside the rectangle
        ' if so, delete the stroke
        If enterRect = -1 And exitRect = -1 Then
            S.Ink.DeleteStroke(S)
            Continue For
        End If

        ' check if a segment enters and exits the rectangle
        ' if so, split and delete the segment inside the rectangle
        If enterRect > 0 And exitRect > 0 Then
            ' the stroke resulting from split() is outside, keep it
            S.Split(exitRect)
            ' the stroke from this split() is inside, delete it
            Dim temp As Stroke = S.Split(enterRect)
            temp.Ink.DeleteStroke(temp)
            Continue For
        End If

        ' check if stroke starts inside the rectangle and goes outside
        ' if so, split and delete the segment inside the rectangle
        If enterRect = -1 And exitRect > 0 Then
            ' the stroke resulting from split() is outside, keep it
            S.Split(exitRect)
            ' delete the remaining segment of the stroke
            S.Ink.DeleteStroke(S)
            Continue For
        End If

        ' check if stroke starts outside the rectangle and ends inside
        ' if so, split and delete the segment inside the rectangle
        If enterRect > 0 And exitRect = -1 Then
            Dim temp2 As Stroke = S.Split(enterRect)
            temp2.Ink.DeleteStroke(temp2)
        End If
    Next
End Sub
private void DeleteInsideRectangle(Stroke S, Rectangle R)
{
    // get the StrokeIntersection array
    StrokeIntersection[] SI = S.GetRectangleIntersections(R);

    // examine each StrokeIntersection
    // must work backwards through the array so that when splitting, 
    // the remaining intersections are still valid for S
    for (int k = SI.Length - 1; k >= 0; k--)
    {
        float enterRect = SI[k].BeginIndex;
        float exitRect = SI[k].EndIndex;

        // check if the whole stroke is inside the rectangle
        // if so, delete the stroke
        if (enterRect == -1 && exitRect == -1)
        {
            S.Ink.DeleteStroke(S);
            continue;
        }

        // check if a segment enters and exits the rectangle
        // if so, split and delete the segment inside the rectangle
        if (enterRect > 0 && exitRect > 0)
        {
            // the stroke resulting from split() is outside, keep it
            S.Split(exitRect);
            // the stroke from this split() is inside, delete it
            Stroke temp = S.Split(enterRect);
            temp.Ink.DeleteStroke(temp);
            continue;
        }

        // check if stroke starts inside the rectangle and goes outside
        // if so, split and delete the segment inside the rectangle
        if (enterRect == -1 && exitRect > 0)
        {
            // the stroke resulting from split() is outside, keep it
            S.Split(exitRect);
            // delete the remaining segment of the stroke
            S.Ink.DeleteStroke(S);
            continue;
        }

        // check if stroke starts outside the rectangle and ends inside
        // if so, split and delete the segment inside the rectangle
        if (enterRect > 0 && exitRect == -1)
        {
            Stroke temp2 = S.Split(enterRect);
            temp2.Ink.DeleteStroke(temp2);
        }
    }
}

Платформы

Windows Vista

Среды .NET Framework и .NET Compact Framework поддерживают не все версии каждой платформы. Поддерживаемые версии перечислены в разделе Требования к системе для .NET Framework.

Сведения о версии

.NET Framework

Поддерживается в версии: 3.0

См. также

Ссылки

Stroke Класс

Stroke - члены

Microsoft.Ink - пространство имен

Stroke.FindIntersections

StrokeIntersection