@@ -112,6 +112,7 @@ function Circle(owner,type,subtype, d, r, a){
112112 angles . push ( child . a + an , child . a - an ) ;
113113 }
114114 }
115+ if ( angles . length == 0 ) angles = [ 0 , 2 * PI ] ;
115116 for ( var i = angles . length ; i > 0 ; i -= 2 ) { //we're going in the oppposite direction as that's how arc() draws
116117 ctx . beginPath ( ) ; ctx . arc ( this . x , this . y , this . r , angles [ i % angles . length ] , angles [ i - 1 ] ) ; ctx . stroke ( ) ;
117118 }
@@ -140,7 +141,8 @@ function Circle(owner,type,subtype, d, r, a){
140141 var dx , dy ;
141142 var oldA = this . a ;
142143 dx = Math . cos ( a ) * ( d ) , dy = Math . sin ( a ) * ( d ) ;
143- this . x = this . owner . x + dx ; this . y = this . owner . y + dy ; this . a = a ; this . d = d ;
144+ this . x = this . owner . x + dx ; this . y = this . owner . y + dy ; this . d = d ;
145+ if ( a < - PI ) this . a = a + 2 * PI ; else if ( a > PI ) this . a = a - 2 * PI ; else this . a = a ;
144146 for ( var i = 0 ; i < this . children . length ; i ++ ) {
145147 if ( mainCircles . contains ( this ) )
146148 this . children [ i ] . update ( this . children [ i ] . d , this . children [ i ] . a ) ;
@@ -248,14 +250,16 @@ $('canvas').mousemove(function(e){
248250 if ( selectedCircle != - 1 ) {
249251 var selected = selectedCircle ;
250252 var a = Math . atan2 ( mouse . y - selected . owner . y , mouse . x - selected . owner . x ) ;
253+ if ( a < 0 ) a += 2 * PI ;
251254 var d = dist ( mouse . x , mouse . y , selected . owner . x , selected . owner . y ) ;
252- if ( selected . type != 6 && currentCircle . children . length > 2 ) { //need extra logic to enforce location of first word/letter
255+ if ( selected . type != 6 && currentCircle . children . length > 2 ) { //todo: extra logic to enforce location of first word/letter
253256 var index = currentCircle . children . indexOf ( selectedCircle ) ;
254257 var splus = ( index + 1 >= currentCircle . children . length ? 0 : index + 1 ) ,
255258 sminus = ( index - 1 < 0 ? currentCircle . children . length - 1 : index - 1 ) ; //preserves order
256259 var aplus = currentCircle . children [ splus ] . a ,
257260 aminus = currentCircle . children [ sminus ] . a ;
258261 if ( aplus > aminus ) { a > 0 ?aminus += 2 * PI :aplus -= 2 * PI ; } //still buggy
262+ if ( a - aplus > 2 * PI || a - aminus > 2 * PI ) a -= 2 * PI ; if ( a - aplus < - 2 * PI || a - aminus < - 2 * PI ) a += 2 * PI ;
259263 if ( a < aplus ) a = aplus ; else if ( a > aminus ) a = aminus ;
260264 }
261265 updateLocation ( selected , d , a ) ;
0 commit comments