次の方法で共有


Stroke.GetRectangleIntersections メソッド

指定された RectangleStroke オブジェクトが交差する場所を示す StrokeIntersection 構造体の配列を返します。

名前空間 :  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[]
Stroke オブジェクトが intersectRectangle パラメータと交差する場所を示す StrokeIntersection 構造体の配列を返します。

解説

このメソッドは、0、または四角形と交差するストロークのセグメントの始点と終点を表す複数のインデックスのセットを返します。ストロークが、境界と 2 か所で交差して、四角形を直線状に通過する場合、インデックスのセットは各交差部分の浮動小数点インデックス値で構成されます。ストロークが 3 回以上四角形と交差する場合、インデックスの数は交差部分の数ごとに増加します。

ストロークがテスト用四角形の内部で開始されている場合、最初の StrokeIntersection 要素の BeginIndex プロパティは -1 に設定されます。ストロークがテスト用四角形の内部で終了している場合、最後の StrokeIntersection 要素の EndIndex プロパティは -1 に設定されます。ストローク全体が四角形の内部にある場合、返される配列には BeginIndex プロパティと EndIndex プロパティの両方が -1 に設定された StrokeIntersection 構造体が 1 つ含まれます。ストローク全体がテスト用四角形の外側にある場合、空の StrokeIntersection 配列が返されます。

たとえば、ストロークがテスト用四角形の内部で開始され、四角形の境界の外側に出てから内側に戻り、再び外側に出る場合、GetRectangleIntersections メソッドは {{-1, 1.4}, {5.5, 10.1}} を返して、ストロークの 2 つのセグメントが四角形内にあることを示します。

このメソッドが返す StrokeIntersection 構造体には、交差が発生した場所を示す浮動小数点インデックス値のペアが含まれます。浮動小数点インデックスは、Stroke オブジェクト内の 2 つのポイントの間のある場所を表す浮動小数点値です。たとえば、0.0 がストローク内の最初のポイントで、1.0 がストローク内の 2 番目のポイントの場合、0.5 が最初のポイントと 2 番目のポイントの間の中間です。同様に、浮動小数点インデックス値 37.25 は、ストロークのポイント 37 と 38 の間の線に沿って 25 パーセント進んだ位置を表しています。

この例では、渡された Stroke オブジェクトにおいて、指定された Rectangle 構造体の内側にあるすべてのセグメントが削除されます。これは、StrokeIntersection 構造体を調べ、渡された Stroke オブジェクトを分割する場所と削除するセグメントを決定することで実現されます。

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