@@ -43,21 +43,45 @@ function Canvas({ onAnimationFinish }) {
4343
4444
4545 const isCircle = ( ) => {
46- if ( circlePath . length < 10 ) {
46+ if ( circlePath . length < 20 ) {
4747 console . log ( 'Too few points to form a circle' ) ;
4848 return false ; // Not enough points to form a circle
4949 }
5050
51- const start = circlePath [ 0 ] ;
51+ // const start = circlePath[0];
5252 const end = circlePath [ circlePath . length - 1 ] ;
53-
54- // Check if the start and end points are close enough
55- const distance = Math . sqrt ( ( start . x - end . x ) ** 2 + ( start . y - end . y ) ** 2 ) ;
56- console . log ( 'Start-End Distance:' , distance ) ;
57- if ( distance > 20 ) { // Adjust the threshold as needed
58- console . log ( 'Start and end points are too far apart' ) ;
59- return false ;
53+ let isClosed = false ;
54+
55+ // Define how many of the initial points to check against.
56+ // Let's check against the first 25% of the path, up to a max of 30 points.
57+ const checkZoneLength = Math . min ( 40 , Math . floor ( circlePath . length * 0.5 ) ) ;
58+
59+ // Check if the path closes on itself
60+ // Loop through the first few points of the path and see if the
61+ // endpoint is close to any of them.
62+ for ( let i = 0 ; i < checkZoneLength ; i ++ ) {
63+ const pointNearStart = circlePath [ i ] ;
64+ const distance = Math . sqrt ( ( pointNearStart . x - end . x ) ** 2 + ( pointNearStart . y - end . y ) ** 2 ) ;
65+
66+ if ( distance < 25 ) { // Threshold for considering the loop "closed"
67+ isClosed = true ;
68+ console . log ( 'Path is considered closed.' ) ;
69+ break ; // Exit the loop once we find a close point
70+ }
71+ }
72+
73+ if ( ! isClosed ) {
74+ console . log ( 'Start and end points are too far apart' ) ;
75+ return false ;
6076 }
77+
78+ // // Check if the start and end points are close enough
79+ // const distance = Math.sqrt((start.x - end.x) ** 2 + (start.y - end.y) ** 2);
80+ // console.log('Start-End Distance:', distance);
81+ // if (distance > 20) { // Adjust the threshold as needed
82+ // console.log('Start and end points are too far apart');
83+ // return false;
84+ // }
6185
6286 // Calculate the center of the path
6387 const centerX = ( Math . min ( ...circlePath . map ( ( p ) => p . x ) ) + Math . max ( ...circlePath . map ( ( p ) => p . x ) ) ) / 2 ;
0 commit comments