| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -21,8 +21,8 @@ class PhysicsWorker { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this.positions = {}; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this.timestep = 0.5; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this.toRemove = { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      nodes: [], | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      edges: [] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      nodeIds: [], | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      edgeIds: [] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -50,8 +50,8 @@ class PhysicsWorker { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      case 'removeElements': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // schedule removal of elements on the next physicsTick
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // avoids having to defensively check every node read in each physics implementation
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.toRemove.nodes.push.apply(this.toRemove.nodes, msg.data.nodes); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.toRemove.edges.push.apply(this.toRemove.edges, msg.data.edges); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.toRemove.nodeIds.push.apply(this.toRemove.nodeIds, msg.data.nodeIds); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.toRemove.edgeIds.push.apply(this.toRemove.edgeIds, msg.data.edgeIds); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        break; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      case 'initPhysicsData': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.initPhysicsData(msg.data); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -103,8 +103,8 @@ class PhysicsWorker { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this.processRemovals(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this.calculateForces(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this.moveNodes(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    for (let i = 0; i < this.toRemove.nodes.length; i++) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      delete this.positions[this.toRemove.nodes[i]]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    for (let i = 0; i < this.toRemove.nodeIds.length; i++) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      delete this.positions[this.toRemove.nodeIds[i]]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this.postMessage({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      type: 'positions', | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -116,22 +116,36 @@ class PhysicsWorker { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  updateProperties(data) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    let optionsNode = this.body.nodes[data.id]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (optionsNode) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let opts = data.options; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (opts.fixed) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (opts.fixed.x !== undefined) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          optionsNode.options.fixed.x = opts.fixed.x; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (data.type === 'node') { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let optionsNode = this.body.nodes[data.id]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (optionsNode) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        let opts = data.options; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (opts.fixed) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          if (opts.fixed.x !== undefined) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            optionsNode.options.fixed.x = opts.fixed.x; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          if (opts.fixed.y !== undefined) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            optionsNode.options.fixed.y = opts.fixed.y; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (opts.fixed.y !== undefined) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          optionsNode.options.fixed.y = opts.fixed.y; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (opts.mass !== undefined) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          optionsNode.options.mass = opts.mass; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        console.warn('sending properties to unknown node'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (opts.mass !== undefined) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        optionsNode.options.mass = opts.mass; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } else if (data.type === 'edge') { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let edge = this.body.edges[data.id]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (edge) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        let opts = data.options; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (opts.connected) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          edge.connected = opts.connected; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        console.warn('sending properties to unknown edge'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      console.log('sending property to unknown node'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      console.warn('sending properties to unknown element'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -169,8 +183,8 @@ class PhysicsWorker { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  processRemovals() { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    while (this.toRemove.nodes.length > 0) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let nodeId = this.toRemove.nodes.pop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    while (this.toRemove.nodeIds.length > 0) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let nodeId = this.toRemove.nodeIds.pop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let index = this.physicsBody.physicsNodeIndices.indexOf(nodeId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (index > -1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.physicsBody.physicsNodeIndices.splice(index,1); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -180,8 +194,8 @@ class PhysicsWorker { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      delete this.positions[nodeId]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      delete this.body.nodes[nodeId]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    while (this.toRemove.edges.length > 0) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let edgeId = this.toRemove.edges.pop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    while (this.toRemove.edgeIds.length > 0) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let edgeId = this.toRemove.edgeIds.pop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let index = this.physicsBody.physicsEdgeIndices.indexOf(edgeId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (index > -1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.physicsBody.physicsEdgeIndices.splice(index,1); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
 |