@@ -24,62 +24,51 @@ class GameScene: SKScene {
2424 }
2525
2626 private func redraw( _ sites: Set < Site > ) {
27- // removeAllChildren()
2827 let totalPath = UIBezierPath ( )
2928
30- // DispatchQueue.global(qos: .userInteractive).async { [unowned self] in
31- self . diagram. clear ( )
32- self . fs. compute (
33- sites: sites,
34- diagram: & self . diagram,
35- clippingRect: self . clippingRect
36- )
29+ diagram. clear ( )
30+ fs. compute (
31+ sites: sites,
32+ diagram: & self . diagram,
33+ clippingRect: self . clippingRect
34+ )
35+
36+ self . diagram. cells. forEach { cell in
37+ var points : [ Site ] = [ ]
38+ var he = cell. outerComponent
3739
38- self . diagram. cells. forEach { cell in
39- var points : [ Site ] = [ ]
40- var he = cell. outerComponent
40+ var finish = false
41+ while !finish {
42+
43+ let o = he!. origin!
44+ points. append ( o)
4145
42- var finish = false
43- while !finish {
44-
45- // if he!.toSegment()!.length() < 1.0 {
46- // he = he?.next
47- // finish = he === cell.outerComponent
48- // continue
49- // }
50-
51- let o = he!. origin!
52- points. append ( o)
53-
54-
55- he = he? . next
56- finish = he === cell. outerComponent
57- }
5846
47+ he = he? . next
48+ finish = he === cell. outerComponent
49+ }
50+
5951// let hullVertices = points.map { $0.cgPoint }
6052// for i in 0..<hullVertices.count {
6153// if i == 0 {
6254// totalPath.move(to: hullVertices[i])
6355// } else { totalPath.addLine(to: hullVertices[i])}
6456// }
6557// totalPath.close()
66-
67- let hullVertices = points. map { $0. cgPoint }
68-
69- for i in 0 ..< 1 {
70- let paddedHull = paddedPolygon ( hullVertices, padding: CGFloat ( - i) * 10 )
71- if let path = UIBezierPath . roundedCornersPath ( paddedHull, 10 ) {
72- totalPath. append ( path)
73- }
58+
59+ let hullVertices = points. map { $0. cgPoint }
60+
61+ for i in 0 ..< 1 {
62+ let paddedHull = paddedPolygon ( hullVertices, padding: CGFloat ( - i) * 10 )
63+ if let path = UIBezierPath . roundedCornersPath ( paddedHull, 10 ) {
64+ totalPath. append ( path)
7465 }
7566 }
76-
77- // DispatchQueue.main.async {
78- self . diagramNode. path = totalPath. cgPath
79- self . diagramNode. strokeColor = UIColor . black
80- self . diagramNode. fillColor = . clear
81- // }
82- // }
67+ }
68+
69+ diagramNode. path = totalPath. cgPath
70+ diagramNode. strokeColor = UIColor . black
71+ diagramNode. fillColor = . clear
8372 }
8473
8574 override func didMove( to view: SKView ) {
@@ -90,19 +79,19 @@ class GameScene: SKScene {
9079 let lby = offset
9180 let ubx = Double ( view. bounds. width) - 2 * offset
9281 let uby = Double ( view. bounds. height) - 2 * offset
93- let randomPoints = hexLike// randomSites(50, xRange: lbx..<ubx, yRange: lby..<uby)
82+ let randomPoints = randomSites ( 50 , xRange: lbx..< ubx, yRange: lby..< uby)
9483 let r : CGFloat = 20
9584 balls = randomPoints. map {
9685 let point = SKShapeNode ( circleOfRadius: r)
9786 point. position = $0. cgPoint
9887 point. fillColor = . red
9988
100- // let body = SKPhysicsBody(circleOfRadius: r)
101- // body.affectedByGravity = false
102- // body.linearDamping = 0
103- // body.mass = 0.0
104- //
105- // point.physicsBody = body
89+ let body = SKPhysicsBody ( circleOfRadius: r)
90+ body. affectedByGravity = false
91+ body. linearDamping = 0
92+ body. mass = 0.0
93+
94+ point. physicsBody = body
10695 point. isHidden = false
10796
10897 addChild ( point)
@@ -148,7 +137,6 @@ class GameScene: SKScene {
148137 y: Double ( j) * step + 200
149138 )
150139 )
151- print ( res. last!)
152140 }
153141 }
154142 return res
0 commit comments