MCPcopy Index your code
hub / github.com/NikLever/ThreeJS-PathEditor / changeNode

Method changeNode

index.js:399–438  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

397 }
398
399 changeNode(){
400 //Called by context menu
401 if (this.activeNode){
402 const index = this.nodes.indexOf( this.activeNode );
403 if (index!=-1){
404 const node = this.nodes[index];
405 if (node.tool == this.config.tool) return;
406 if (index == 0){
407 //Only moveTo allowed
408 if (this.config.tool != 'moveTo'){
409 alert("You can only change the first node to 'moveTo'");
410 return;
411 }
412 node.tool = this.config.tool;
413 delete node.options;
414 }else{
415 const prevNode = this.nodes[index-1];
416 node.tool = this.config.tool;
417 delete node.options;
418 let ctrlA, ctrlB, center;
419 switch( node.tool ){
420 case 'quadraticCurveTo':
421 ctrlA = Geometry.calcLineMidPoint( prevNode, node );
422 node.options = { ctrlA };
423 break;
424 case 'bezierCurveTo':
425 ctrlA = Geometry.calcPointAlongLine( prevNode, node, 0.33 );
426 ctrlB = Geometry.calcPointAlongLine( prevNode, node, 0.66 );
427 node.options = { ctrlA, ctrlB };
428 break;
429 case 'arc':
430 const radius = Geometry.distanceBetweenPoints( prevNode, node );
431 node.options = { radius, start: 0, end: Math.PI/2, clockwise: false };
432 break;
433 }
434 }
435 this.render(true);
436 }
437 }
438 }
439
440 newPath(){
441 const names = this.store.getPathNames();

Callers

nothing calls this directly

Calls 3

renderMethod · 0.95
calcLineMidPointMethod · 0.80
calcPointAlongLineMethod · 0.80

Tested by

no test coverage detected