@@ -82,7 +82,7 @@ public static Point TransformPoint(
8282 /// <param name="height">Height of output image</param>
8383 /// <param name="isRotated">Output grid is rotated (width swapped with height)</param>
8484 /// <returns>List of lines</returns>
85- public static IEnumerable < Line > CreateGrid ( GridType gridType , double width , double height , bool isRotated )
85+ public static IList < Line > CreateGrid ( GridType gridType , double width , double height , bool isRotated )
8686 {
8787 var actualAspectRatio = CalculateAspectRatio ( width , height , isRotated ) ;
8888
@@ -294,7 +294,7 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
294294 const double FullTurn = 2.0 * Math . PI ;
295295 const double MaxAngle = ( ( double ) NumberOfTurns ) * FullTurn ;
296296
297- for ( var theta = 0.0 ; theta < MaxAngle ; )
297+ for ( var theta = 0.0 ; theta < MaxAngle ; )
298298 {
299299 var r = Math . Pow ( RatioConstants . GoldenSpiralCInRadians , theta ) ;
300300
@@ -413,6 +413,25 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
413413 lines . Add ( new Line ( rectangle . Right , rectangle . Top , rectangle . Right - w , rectangle . Bottom ) ) ;
414414 lines . Add ( new Line ( rectangle . Right , rectangle . Bottom , rectangle . Right - w , rectangle . Top ) ) ;
415415
416+ return lines ;
417+ }
418+ case GridType . GoldenCircles :
419+ {
420+ var lines = new List < Line > ( ) ;
421+
422+ var rectangle = CalculateDynamicRectangleExtents ( RatioConstants . Phi , actualAspectRatio ) ;
423+ var centerLine = rectangle . Top + rectangle . Height / 2.0 ;
424+
425+ // Major circles
426+ var majorRadius = ( rectangle . Width * RatioConstants . Phi5D8 ) / 2.0 ;
427+ lines . AddRange ( CreateCirclePoints ( rectangle . Left + majorRadius , centerLine , majorRadius , actualAspectRatio ) ) ;
428+ lines . AddRange ( CreateCirclePoints ( rectangle . Right - majorRadius , centerLine , majorRadius , actualAspectRatio ) ) ;
429+
430+ // Minor circles
431+ var minorRadius = ( rectangle . Width * RatioConstants . Phi3D8 ) / 2.0 ;
432+ lines . AddRange ( CreateCirclePoints ( rectangle . Left + minorRadius , centerLine , minorRadius , actualAspectRatio ) ) ;
433+ lines . AddRange ( CreateCirclePoints ( rectangle . Right - minorRadius , centerLine , minorRadius , actualAspectRatio ) ) ;
434+
416435 return lines ;
417436 }
418437 case GridType . RootPhiRectangle :
@@ -422,7 +441,7 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
422441
423442 var w = rectangle . Width / ( RatioConstants . RootPhi * RatioConstants . RootPhi ) ;
424443 var h = rectangle . Height / ( RatioConstants . RootPhi * RatioConstants . RootPhi ) ;
425-
444+
426445 lines . Add ( new Line ( rectangle . Left + w , rectangle . Top , rectangle . Left + w , rectangle . Bottom ) ) ;
427446 lines . Add ( new Line ( rectangle . Right - w , rectangle . Top , rectangle . Right - w , rectangle . Bottom ) ) ;
428447 lines . Add ( new Line ( rectangle . Left , rectangle . Top + h , rectangle . Right , rectangle . Top + h ) ) ;
@@ -448,6 +467,7 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
448467 lines . Add ( new Line ( rectangle . Left , rectangle . Top , RatioConstants . Half , rectangle . Bottom ) ) ;
449468 lines . Add ( new Line ( RatioConstants . Half , rectangle . Bottom , rectangle . Right , rectangle . Top ) ) ;
450469 lines . Add ( new Line ( RatioConstants . Half , rectangle . Top , rectangle . Right , rectangle . Bottom ) ) ;
470+
451471 return lines ;
452472 }
453473 case GridType . Root3Rectangle :
@@ -466,6 +486,7 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
466486 var h = rectangle . Height / 3.0 ;
467487 lines . Add ( new Line ( rectangle . Left , rectangle . Top + h , rectangle . Right , rectangle . Top + h ) ) ;
468488 lines . Add ( new Line ( rectangle . Left , rectangle . Bottom - h , rectangle . Right , rectangle . Bottom - h ) ) ;
489+
469490 return lines ;
470491 }
471492 case GridType . Root4Rectangle :
@@ -509,6 +530,7 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
509530 lines . Add ( new Line ( rectangle . Left , rectangle . CenterY , rectangle . Right , rectangle . CenterY ) ) ;
510531 lines . Add ( new Line ( rectangle . Left , rectangle . Top + h , rectangle . Right , rectangle . Top + h ) ) ;
511532 lines . Add ( new Line ( rectangle . Left , rectangle . Bottom - h , rectangle . Right , rectangle . Bottom - h ) ) ;
533+
512534 return lines ;
513535 }
514536 default :
@@ -518,6 +540,29 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
518540 }
519541 }
520542
543+ private static IList < Line > CreateCirclePoints ( double centerX , double centerY , double radius , double actualAspectRatio )
544+ {
545+ const double FullTurn = 2.0 * Math . PI ;
546+ var step = 0.01 * FullTurn ; // TODO: compute optimal step from circle radius with desired smoothness
547+
548+ var points = new List < Point > ( ( int ) ( FullTurn / step ) ) ;
549+ for ( var theta = 0.0 ; theta < FullTurn ; theta += step )
550+ {
551+ var x = centerX + radius * Math . Cos ( theta ) ;
552+ var y = 1.0 - ( centerY + radius * Math . Sin ( theta ) * actualAspectRatio ) ; // Flip Y axis
553+
554+ points . Add ( new Point ( x , y ) ) ;
555+ }
556+
557+ var lines = new List < Line > ( ) ;
558+ for ( var i = 1 ; i < points . Count ; i ++ )
559+ {
560+ lines . Add ( new Line ( points [ i - 1 ] , points [ i ] ) ) ;
561+ }
562+
563+ return lines ;
564+ }
565+
521566 private static double CalculateAspectRatio ( double width , double height , bool isRotated = false )
522567 {
523568 return ( ( isRotated ) ? ( height / width ) : ( width / height ) ) ;
@@ -547,6 +592,32 @@ private static Rectangle CalculateDynamicRectangleExtents(double desiredAspectRa
547592 return new Rectangle { X = left , Y = top , Width = right - left , Height = bottom - top } ;
548593 }
549594
595+ private static IList < Line > CreateRectangle ( Rectangle rectangle , bool withMainDiagonals = false )
596+ {
597+ var left = rectangle . Left ;
598+ var right = rectangle . Right ;
599+ var top = rectangle . Top ;
600+ var bottom = rectangle . Bottom ;
601+
602+ var lines = new List < Line > ( )
603+ {
604+ // Four lines making contour
605+ new Line ( left , top , left , bottom ) ,
606+ new Line ( right , top , right , bottom ) ,
607+ new Line ( left , top , right , top ) ,
608+ new Line ( left , bottom , right , bottom )
609+ } ;
610+
611+ // Two main diagonals
612+ if ( withMainDiagonals )
613+ {
614+ lines . Add ( new Line ( left , top , right , bottom ) ) ;
615+ lines . Add ( new Line ( left , bottom , right , top ) ) ;
616+ }
617+
618+ return lines ;
619+ }
620+
550621 private static List < Line > CreateRectangleWithMainDiagonals ( Rectangle rectangle )
551622 {
552623 double left , right , top , bottom ;
@@ -680,7 +751,7 @@ private static IList<Line> CreateRectangleLines(int left, int right, int top, in
680751 } ) ;
681752 }
682753
683- private static IEnumerable < Line > CreateLines ( Point [ ] points )
754+ private static IList < Line > CreateLines ( Point [ ] points )
684755 {
685756 var res = new List < Line > ( ) ;
686757
0 commit comments