Skip to content

Commit e402b60

Browse files
committed
Fix zooming issues
1 parent 104977f commit e402b60

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

Mandelray/Mandelray.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<Reference Include="System" />
7777
<Reference Include="System.Drawing" />
7878
<Reference Include="System.Core" />
79+
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
80+
<HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
81+
</Reference>
7982
<Reference Include="System.Xaml">
8083
<RequiredTargetFramework>4.0</RequiredTargetFramework>
8184
</Reference>

Mandelray/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Reflection;
22
using System.Runtime.InteropServices;
33

4-
[assembly: AssemblyVersion("1.0.0")]
4+
[assembly: AssemblyVersion("1.0.1")]
55

66
[assembly: AssemblyTitle("Mandelray")]
77
[assembly: AssemblyDescription("A Mandelbrot Set Viewer in C#")]

Mandelray/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<package id="Costura.Fody" version="1.6.2" targetFramework="net45" developmentDependency="true" />
55
<package id="Fody" version="2.0.0" targetFramework="net45" developmentDependency="true" />
66
<package id="MathNet.Numerics" version="4.4.0" targetFramework="net45" />
7+
<package id="System.ValueTuple" version="4.3.0" targetFramework="net45" />
78
<package id="WriteableBitmapEx" version="1.5.1.0" targetFramework="net45" />
89
</packages>

Mandelray/src/Util/ZoomSelectionHandler.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,14 @@ public void MoveSelection(MouseEventArgs e)
122122
var newWidth = (int) (_rectEnd.X - _rectStart.X);
123123
var newHeight = (int) (_rectEnd.Y - _rectStart.Y);
124124

125-
// fix ratio
126-
if (Math.Abs(newWidth) > Math.Abs(newHeight)) newWidth = (int) (newHeight * GausRatioYx);
127-
if (Math.Abs(newHeight) > Math.Abs(newWidth)) newHeight = (int) (newWidth * GausRatioXy);
128-
129-
// only quadratic zooming in 4th quadrant allowed
125+
// show rectangle only in 4th quadrant
130126
if (newWidth > 0 && newHeight > 0)
131127
{
132-
ZoomingRectangle.Width = newWidth;
133-
ZoomingRectangle.Height = newHeight;
128+
(ZoomingRectangle.Width, ZoomingRectangle.Height) = FixRatio(newWidth, newHeight);
129+
}
130+
else
131+
{
132+
(ZoomingRectangle.Width, ZoomingRectangle.Height) = (0, 0);
134133
}
135134
}
136135
}
@@ -141,16 +140,23 @@ public void EndSelection()
141140
if (_isZooming)
142141
{
143142
// remember positions
144-
var startX = (int) ZoomingRectangle.Margin.Left;
145-
var startY = (int) ZoomingRectangle.Margin.Top;
146-
var width = (int) ZoomingRectangle.Width;
147-
var height = (int) ZoomingRectangle.Height;
143+
var startX = (int) _rectStart.X;
144+
var startY = (int) _rectStart.Y;
145+
var width = (int) (_rectEnd.X - _rectStart.X);
146+
var height = (int) (_rectEnd.Y - _rectStart.Y);
147+
148+
// only quadratic zooming in 4th quadrant allowed
149+
if (width > 0 && height > 0)
150+
{
151+
// fix ratio
152+
(width, height) = FixRatio(width, height);
148153

149-
// disable zooming and hide rectangle
150-
AbortSelection();
154+
// disable zooming and hide rectangle
155+
AbortSelection();
151156

152-
// invoke event handler
153-
ZoomSelected?.Invoke(this, new ZoomSelectionEventArgs(startX, startY, width, height));
157+
// invoke event handler
158+
ZoomSelected?.Invoke(this, new ZoomSelectionEventArgs(startX, startY, width, height));
159+
}
154160
}
155161
}
156162

@@ -163,5 +169,13 @@ public void AbortSelection()
163169
ZoomingRectangle.Width = 0;
164170
ZoomingRectangle.Height = 0;
165171
}
172+
173+
private static (int width, int height) FixRatio(int width, int height)
174+
{
175+
if (Math.Abs(width) > Math.Abs(height)) width = (int)(height * GausRatioYx);
176+
if (Math.Abs(height) > Math.Abs(width)) height = (int)(width * GausRatioXy);
177+
178+
return (width, height);
179+
}
166180
}
167181
}

0 commit comments

Comments
 (0)