Skip to content

Commit 30be9c9

Browse files
committed
Fixed GoldenSpiralZoomed / FibonacciRectanglesZoomed grid creating in case of rotated grid
1 parent 8183f7c commit 30be9c9

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Src/ScreenGrid.Models/Grids/GridCreator.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ public static Point TransformPoint(
8080
/// <param name="gridType">Selected type of grid</param>
8181
/// <param name="width">Width of output image</param>
8282
/// <param name="height">Height of output image</param>
83+
/// <param name="isRotated">Output grid is rotated (width swapped with height)</param>
8384
/// <returns>List of lines</returns>
84-
public static IEnumerable<Line> CreateGrid(GridType gridType, double width, double height)
85+
public static IEnumerable<Line> CreateGrid(GridType gridType, double width, double height, bool isRotated)
8586
{
8687
switch (gridType)
8788
{
@@ -256,7 +257,8 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
256257

257258
if (gridType == GridType.FibonacciRectanglesZoomed)
258259
{
259-
lines = StretchToRectangleWithAspectRatio(lines, width, height, left, right, top, bottom);
260+
var aspect = (isRotated) ? (height / width) : (width / height);
261+
lines = StretchToRectangleWithAspectRatio(lines, aspect, left, right, top, bottom);
260262
}
261263
else if (gridType == GridType.FibonacciRectanglesStretched)
262264
{
@@ -341,11 +343,11 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
341343

342344
if (gridType == GridType.GoldenSpiralZoomed)
343345
{
344-
lines = StretchToRectangleWithAspectRatio(lines, width, height, minX, maxX, minY, maxY);
346+
var aspect = (isRotated) ? (height / width) : (width / height);
347+
lines = StretchToRectangleWithAspectRatio(lines, aspect, minX, maxX, minY, maxY);
345348

346349
// Adding extents lines
347350
var extents = GetExtents(lines);
348-
var aspect = (width / height);
349351
if (aspect < RatioConstants.Phi)
350352
{
351353
lines.Add(new Line(RatioConstants.Zero, extents.Top, RatioConstants.One, extents.Top));
@@ -375,10 +377,8 @@ public static IEnumerable<Line> CreateGrid(GridType gridType, double width, doub
375377
}
376378
}
377379

378-
private static List<Line> StretchToRectangleWithAspectRatio(List<Line> lines, double width, double height, double left, double right, double top, double bottom)
380+
private static List<Line> StretchToRectangleWithAspectRatio(List<Line> lines, double aspect, double left, double right, double top, double bottom)
379381
{
380-
var aspect = (width / height);
381-
382382
if (aspect < RatioConstants.Phi)
383383
{
384384
lines = StretchToRectangle(1.0, (RatioConstants.Phi - 1.0) * aspect, lines, left, top, right, bottom);

Src/ScreenGrid.ViewModels/ScreenGridViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ public void UpdateContentControl()
259259
this.contentControl.Children.Clear();
260260

261261
// TODO: place calculated results in cache
262-
var gridLines = GridCreator.CreateGrid(this.gridMode, this.RenderWidth, this.RenderHeight);
262+
var isRotated = ((this.Rot == Rotation.R90) || (this.Rot == Rotation.R270));
263+
var gridLines = GridCreator.CreateGrid(this.gridMode, this.RenderWidth, this.RenderHeight, isRotated);
263264

264265
var lines = GridCreator.Transform(gridLines, this.rotation, this.isFlippedHorizontal, this.isFlippedVertical, this.RenderWidth, this.RenderHeight);
265266
for (var i = 0; i < lines.Length; i++)

0 commit comments

Comments
 (0)