Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/ViewportConstraints/ProportionsConstraint.cs @ 13467

Last change on this file since 13467 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 965 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6
7namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
8{
9  public sealed class ProportionsConstraint : ViewportConstraint
10  {
11    private double widthToHeightRatio = 1;
12    public double WidthToHeightRatio
13    {
14      get { return widthToHeightRatio; }
15      set
16      {
17        if (widthToHeightRatio != value)
18        {
19          widthToHeightRatio = value;
20          RaiseChanged();
21        }
22      }
23    }
24
25    public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport)
26    {
27      double ratio = newDataRect.Width / newDataRect.Height;
28      double coeff = Math.Sqrt(ratio);
29
30      double newWidth = newDataRect.Width / coeff;
31      double newHeight = newDataRect.Height * coeff;
32
33      Point center = newDataRect.GetCenter();
34      DataRect res = DataRect.FromCenterSize(center, newWidth, newHeight);
35      return res;
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.