Skip to content

Commit 9741b6d

Browse files
committed
Implemented 1.5 Rectangle
1 parent e98afd7 commit 9741b6d

4 files changed

Lines changed: 44 additions & 19 deletions

File tree

Src/ScreenGrid.Models/Grids/GridCreator.cs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,32 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
372372

373373
return lines;
374374
}
375-
////case GridType.OneDotFiveRectangle:
376-
//// {
377-
//// var rectangle = CalculateDynamicRectangleExtents(1.5 / RatioConstants.One, actualAspectRatio);
378-
//// var lines = CreateRootNRectangle(rectangle);
379-
//// // TODO: armature
380-
//// return lines;
381-
//// }
375+
case GridType.OneDotFiveRectangle:
376+
{
377+
var rectangle = CalculateDynamicRectangleExtents(RatioConstants.OneDotFive, actualAspectRatio);
378+
var lines = CreateRectangleWithMainDiagonals(rectangle);
379+
380+
var w = rectangle.Width / (RatioConstants.OneDotFive * RatioConstants.OneDotFive);
381+
var h = rectangle.Height / (RatioConstants.OneDotFive * RatioConstants.OneDotFive);
382+
lines.Add(new Line(rectangle.Left + w, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
383+
lines.Add(new Line(rectangle.Right - w, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
384+
lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
385+
lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));
386+
387+
// Left
388+
lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
389+
lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.Left + w, rectangle.Top));
390+
391+
// Right
392+
lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
393+
lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.Right - w, rectangle.Top));
394+
395+
return lines;
396+
}
382397
case GridType.GoldenRectangle:
383398
{
384399
var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Phi / RatioConstants.One, actualAspectRatio);
385-
var lines = CreateRootNRectangle(rectangle);
400+
var lines = CreateRectangleWithMainDiagonals(rectangle);
386401

387402
var w = rectangle.Width * RatioConstants.Phi3D8;
388403
var h = rectangle.Height * RatioConstants.Phi3D8;
@@ -409,7 +424,7 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
409424
case GridType.Root2Rectangle:
410425
{
411426
var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root2 / RatioConstants.One, actualAspectRatio);
412-
var lines = CreateRootNRectangle(rectangle);
427+
var lines = CreateRectangleWithMainDiagonals(rectangle);
413428
lines.Add(new Line(rectangle.Left, RatioConstants.Half, rectangle.Right, RatioConstants.Half));
414429
lines.Add(new Line(RatioConstants.Half, rectangle.Top, RatioConstants.Half, rectangle.Bottom));
415430
lines.Add(new Line(rectangle.Left, rectangle.Bottom, RatioConstants.Half, rectangle.Top));
@@ -421,7 +436,7 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
421436
case GridType.Root3Rectangle:
422437
{
423438
var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root3 / RatioConstants.One, actualAspectRatio);
424-
var lines = CreateRootNRectangle(rectangle);
439+
var lines = CreateRectangleWithMainDiagonals(rectangle);
425440
lines.AddRange(CreateRegularLines(rectangle, 2));
426441
var w = rectangle.Width / 3.0;
427442
// Left
@@ -433,13 +448,13 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
433448
// Two horizontals
434449
var h = rectangle.Height / 3.0;
435450
lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
436-
lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));
451+
lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));
437452
return lines;
438453
}
439454
case GridType.Root4Rectangle:
440455
{
441456
var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root4 / RatioConstants.One, actualAspectRatio);
442-
var lines = CreateRootNRectangle(rectangle);
457+
var lines = CreateRectangleWithMainDiagonals(rectangle);
443458
lines.AddRange(CreateRegularLines(rectangle, 3));
444459
var w = rectangle.Width / 4.0;
445460
// Left
@@ -456,14 +471,14 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
456471
// Two horizontals
457472
var h = rectangle.Height / 4.0;
458473
lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
459-
lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));
474+
lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));
460475

461476
return lines;
462477
}
463478
case GridType.Root5Rectangle:
464479
{
465480
var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root5 / RatioConstants.One, actualAspectRatio);
466-
var lines = CreateRootNRectangle(rectangle);
481+
var lines = CreateRectangleWithMainDiagonals(rectangle);
467482
lines.AddRange(CreateRegularLines(rectangle, 4));
468483
var w = rectangle.Width / 5.0;
469484
// Left
@@ -515,7 +530,7 @@ private static Rectangle CalculateDynamicRectangleExtents(double desiredAspectRa
515530
return new Rectangle { X = left, Y = top, Width = right - left, Height = bottom - top };
516531
}
517532

518-
private static List<Line> CreateRootNRectangle(Rectangle rectangle)
533+
private static List<Line> CreateRectangleWithMainDiagonals(Rectangle rectangle)
519534
{
520535
double left, right, top, bottom;
521536
left = rectangle.Left;
@@ -525,12 +540,13 @@ private static List<Line> CreateRootNRectangle(Rectangle rectangle)
525540

526541
var lines = new List<Line>();
527542

543+
// Four contour lines
528544
lines.Add(new Line(left, top, left, bottom));
529545
lines.Add(new Line(right, top, right, bottom));
530546
lines.Add(new Line(left, top, right, top));
531547
lines.Add(new Line(left, bottom, right, bottom));
532548

533-
// Main diagonals
549+
// Two main diagonals
534550
lines.Add(new Line(left, top, right, bottom));
535551
lines.Add(new Line(left, bottom, right, top));
536552

Src/ScreenGrid.Models/Grids/GridModeItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static IEnumerable<GridModeItem> List
4848
new GridModeItem(GridType.GoldenSpiralZoomed, "Golden Spiral"),
4949
new GridModeItem(GridType.FibonacciRectanglesStretched, "Fibonacci Rectangles (stretched)"),
5050
new GridModeItem(GridType.GoldenSpiralStretched, "Golden Spiral (stretched)"),
51-
// TODO: new GridModeItem(GridType.OneDotFiveRectangle, "1.5 Rectangle"),
51+
new GridModeItem(GridType.OneDotFiveRectangle, "1.5 Rectangle"),
5252
new GridModeItem(GridType.GoldenRectangle, "Golden (Phi) Rectangle"),
5353
// TODO: new GridModeItem(GridType.RootPhiRectangle, "Root-Phi Rectangle"),
5454
new GridModeItem(GridType.Root2Rectangle, "Root-2 Rectangle"),

Src/ScreenGrid.Models/Grids/GridType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public enum GridType
6666
GoldenSpiralStretched,
6767

6868
/// <summary>
69-
/// 1.5 Rectangle
69+
/// 1.5 Rectangle (1:1.5 or 3:2)
7070
/// </summary>
71-
// TODO: OneDotFiveRectangle,
71+
OneDotFiveRectangle,
7272

7373
/// <summary>
7474
/// Golden rectangle or Auron (1:φ)

Src/ScreenGrid.Models/Grids/RatioConstants.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ static class RatioConstants
88

99
public static readonly double One = 1.0;
1010

11+
public static readonly double Two = 2.0;
12+
13+
public static readonly double Three = 3.0;
14+
1115
/// <summary>
1216
/// 1.618
1317
/// </summary>
@@ -25,6 +29,11 @@ static class RatioConstants
2529

2630
public static readonly double OneSixth = 1.0 / 6.0;
2731

32+
/// <summary>
33+
/// 1.5
34+
/// </summary>
35+
public static readonly double OneDotFive = RatioConstants.Three / RatioConstants.Two;
36+
2837
public static readonly double RootPhi = Math.Sqrt(Phi);
2938

3039
public static readonly double Root2 = Math.Sqrt(2.0);

0 commit comments

Comments
 (0)