【发布时间】:2018-09-27 18:05:32
【问题描述】:
我有一个想要转换为“普通”VB.NET 代码的 Lambda 代码。
我还没有找到任何可以将 Lambda 转换为代码的工具,我不明白这段代码的作用。
什么是理解这段代码的好方法?
特别是,我不知道这条线是做什么的:
Let p3 = uDestPoints.First(Function(p) Math.Abs(p.X - t.P3.X) < 1 AndAlso Math.Abs(p.Y - t.P3.Y) < 1)
Select New With {Key .X1 = destList.IndexOf(p1), Key .X2 = destList.IndexOf(p2), Key .X3 = destList.IndexOf(p3)}
谢谢。
Public Function GetWarps(ByVal uSourcePoints As IEnumerable(Of Point), ByVal uDestPoints As IEnumerable(Of Point), ByVal uDestTriangles As IEnumerable(Of Triangle)) As IEnumerable(Of Warp)
' build lists of source and destination landmark points
Dim sourceList = uSourcePoints.ToList()
Dim destList = uDestPoints.ToList()
' find all three triangle points in the list of destination landmark points
Dim indices = From t In uDestTriangles
Let p1 = uDestPoints.First(Function(p) Math.Abs(p.X - t.P1.X) < 1 AndAlso Math.Abs(p.Y - t.P1.Y) < 1)
Let p2 = uDestPoints.First(Function(p) Math.Abs(p.X - t.P2.X) < 1 AndAlso Math.Abs(p.Y - t.P2.Y) < 1)
Let p3 = uDestPoints.First(Function(p) Math.Abs(p.X - t.P3.X) < 1 AndAlso Math.Abs(p.Y - t.P3.Y) < 1)
Select New With {Key .X1 = destList.IndexOf(p1), Key .X2 = destList.IndexOf(p2), Key .X3 = destList.IndexOf(p3)}
' return enumeration of warps from source to destination triangles
Return From x In indices
Select New Warp(New Triangle(sourceList(x.X1), sourceList(x.X2), sourceList(x.X3)), New Triangle(destList(x.X1), destList(x.X2), destList(x.X3)))
End Function
【问题讨论】:
-
我也想知道。这些怪物吓死我了。
-
Lambda(函数)是代码——它只是编写静态方法的一种简写方式,然后您可以将其传递给另一个方法。也许您应该专注于
Enumerable.First的作用?