对于某些事情而言,不同的数据结构对于其他事物而言是好的/更好的。
有没有办法转换要由WPF多边形使用的Vector数组?
let mutable nodes = [| Vector (100.0, 100.0); Vector (60.0, 20.0); Vector (80.0, 60.0); Vector(50.0, 100.0); Vector (100.0, 80.0); Vector (30.0, 140.0); Vector (20.0, 80.0); Vector (30.0, 30.0); |]
let spolyS : Point seq = Seq.ofArray [| Vector (0.0, 0.0); Vector (6.0, 2.0); Vector (8.0, 6.0); Vector(5.0, 10.0); Vector (10.0, 8.0); Vector (3.0, 14.0); Vector (-2.0, 8.0); Vector (-3.0, 3.0); |]
let seqFromArray1 = [| 1..10 |] :> seq<int>
let seqFromArray2 = [| 1 .. 10 |] |> Seq.ofArray
let seqFromArray3 = polyS :> seq<Point>
let mutable arrayList1 = new System.Collections.ArrayList(10)
for i in 1 .. 10 do arrayList1.Add(10) |> ignore
let seqCast : seq<int> = Seq.cast arrayList1
let mutable arrayList2 = new Media.PointCollection(10)
for i in 1 .. 10 do arrayList1.Add(10) |> ignore
let seqCast : seq<Point> = Seq.cast arrayList2
let spts : Point seq = Seq.ofArray polyS |> new Media.PointCollection
let spts : Point seq = Seq.ofArray polyS |> new Media.PointCollection
let spts : Point seq = Seq.ofArray polyS |> new Media.PointCollection(spts IEnumerable<Point>):unit
答案 0 :(得分:3)
可能是这样的:
let vectors = [| Vector(100.0, 100.0); Vector(60.0, 20.0); ... |]
let points = vectors |> Array.map (fun v -> Point(v.X, v.Y))
let mediaPoints = Media.PointCollection(points)