Stroke.GetRectangleIntersections 方法
返回 StrokeIntersection 结构的数组,这些结构指示 Stroke 对象与给定 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[]
参数
- intersectRectangle
类型:System.Drawing.Rectangle
Rectangle 结构采用墨迹空间 坐标,用于描述命中测试区域。
返回值
类型:array<Microsoft.Ink.StrokeIntersection[]
返回 StrokeIntersection 结构的数组,这些结构指示 Stroke 对象与 intersectRectangle 参数的相交位置。
备注
此方法返回零个或多个索引集,这些索引集表示笔画与矩形相交的线段的开头和末尾。如果笔画直接穿过矩形,从而在两个位置与边界相交,则索引集由每个交点的浮点索引值组成。如果笔画在多个位置与矩形相交,则增加的索引数与交点数相同。
如果笔画从测试矩形内部开始,则第一个 StrokeIntersection 元素的 BeginIndex 属性设置为 -1。如果笔画在测试矩形内部终止,则最后一个 StrokeIntersection 元素的 EndIndex 属性设置为 -1。如果笔画完全包含在矩形中,则返回的数组将具有单个 StrokeIntersection 结构,其 BeginIndex 属性和 EndIndex 属性均设置为 -1。如果笔画完全位于测试矩形外部,则返回一个空 StrokeIntersection 数组。
例如,如果笔画从测试矩形内部开始,离开该矩形边界,然后返回内部,最后再离开,则 GetRectangleIntersections 方法可能返回 {{-1, 1.4}, {5.5, 10.1}} 来描述落在矩形中的两个笔画线段。
此方法返回的 StrokeIntersection 结构包含指示发生相交的位置的成对浮点索引值。浮点索引是一个浮点值,表示 Stroke 对象中两点之间的某个位置。例如,如果 0.0 是笔画中的第一个点,而 1.0 是笔画中的第二个点,则 0.5 位于第一个点和第二个点的正中间。与之类似,浮点索引值 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