Compartir a través de


Stroke.GetRectangleIntersections (Método)

Actualización: noviembre 2007

Devuelve una matriz de estructuras StrokeIntersection que indican el lugar donde un objeto Stroke forma una intersección con un objeto Rectangle determinado.

Espacio de nombres:  Microsoft.Ink
Ensamblado:  Microsoft.Ink (en Microsoft.Ink.dll)

Sintaxis

'Declaración
Public Function GetRectangleIntersections ( _
    intersectRectangle As Rectangle _
) As StrokeIntersection()
'Uso
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[]

Parámetros

  • intersectRectangle
    Tipo: System.Drawing.Rectangle
    La estructura Rectangle, en coordenadas de espacio de entrada manuscrita, que describe el área de la prueba de posicionamiento.

Valor devuelto

Tipo: array<Microsoft.Ink.StrokeIntersection[]
Devuelve una matriz de estructuras StrokeIntersection que indican el lugar donde un objeto Stroke forma una intersección con el parámetro intersectRectangle.

Comentarios

Este método devuelve cero o varios conjuntos de índices que representan el principio y el fin de los segmentos del trazo que forman una intersección con el rectángulo. Si un trazo atraviesa directamente un rectángulo, formando intersección con el límite en dos lugares, el conjunto de índices se obtiene de los valores de índice de punto flotante de cada intersección. Si un trazo forma una intersección con un rectángulo más de dos veces, el número de índices se incrementa por el número de intersecciones.

Si el trazo comienza dentro del rectángulo de pruebas, la propiedad BeginIndex del primer elemento StrokeIntersection se establece en -1. Si el trazo finaliza dentro del rectángulo de pruebas, la propiedad EndIndex del último elemento StrokeIntersection se establece en -1. Si el trazo está completamente dentro del rectángulo, la matriz devuelta tendrá una única estructura StrokeIntersection con la propiedad BeginIndex y la propiedad EndIndex establecidas en -1. Si el trazo está completamente fuera del rectángulo de pruebas, se devuelve una matriz StrokeIntersection vacía.

Por ejemplo, si un trazo comienza dentro del rectángulo de pruebas, deja los límites del rectángulo, vuelve dentro y sale de nuevo, el método GetRectangleIntersections puede devolver {{-1, 1,4}, {5,5, 10,1}} para describir los dos segmentos del trazo que están dentro del rectángulo.

Las estructuras StrokeIntersection que este método devuelve contienen valores de índice de punto flotante emparejados que indican las ubicaciones en las que se producen las intersecciones. Un índice de punto flotante es un valor flotante que representa una ubicación situada en algún lugar entre dos puntos del objeto Stroke. Por ejemplo, si 0,0 es el primer punto del trazo y 1,0 el segundo punto, 0,5 se encontrará a mitad de camino entre el primer y el segundo punto. De igual forma, un valor de índice de punto flotante de 37,25 representa una ubicación que se encuentra en el 25 por ciento de la línea que une los puntos 37 y 38 del trazo.

Ejemplos

En este ejemplo, se eliminan todos los segmentos de un objeto Stroke que se ha pasado que se encuentran en la estructura Rectangle especificada. Esto se consigue con el examen de las estructuras StrokeIntersection para determinar dónde se divide del objeto Stroke pasado y qué segmentos se van a eliminar.

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);
        }
    }
}

Plataformas

Windows Vista

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Información de versión

.NET Framework

Compatible con: 3.0

Vea también

Referencia

Stroke (Clase)

Stroke (Miembros)

Microsoft.Ink (Espacio de nombres)

Stroke.FindIntersections

StrokeIntersection