Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15383


Ignore:
Timestamp:
09/27/17 13:06:35 (7 years ago)
Author:
bwerth
Message:

#2827 changed dimensionality check to be much more defensive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/SingleObjectiveTestFunctionSolutionView.cs

    r15336 r15383  
    2222using System;
    2323using System.Drawing;
     24using System.Linq;
    2425using System.Windows.Forms;
    2526using HeuristicLab.Core.Views;
     
    136137
    137138    private void GenerateImage() {
    138       if (pictureBox.Enabled && Content.BestRealVector.Length == 2 && pictureBox.Width > 0 && pictureBox.Height > 0) {
    139         if (Content == null) {
    140           pictureBox.Image = null;
    141         } else {
    142           if (backgroundImage == null) {
    143             GenerateBackgroundImage();
    144             pictureBox.Image = backgroundImage;
    145           }
    146           pictureBox.Refresh();
    147           DoubleMatrix bounds = Content.Bounds;
    148           if (bounds == null) bounds = Content.Evaluator.Bounds;
    149           double xMin = bounds[0, 0], xMax = bounds[0, 1], yMin = bounds[1 % bounds.Rows, 0], yMax = bounds[1 % bounds.Rows, 1];
    150           double xStep = backgroundImage.Width / (xMax - xMin), yStep = backgroundImage.Height / (yMax - yMin);
    151           using (Graphics graphics = pictureBox.CreateGraphics()) {
    152             if (Content.BestKnownRealVector != null) {
    153               Pen cross = new Pen(Brushes.Red, 2.0f);
    154               float a = (float)((Content.BestKnownRealVector[0] - xMin) * xStep);
    155               float b = (float)((Content.BestKnownRealVector[1] - yMin) * yStep);
    156               graphics.DrawLine(cross, a - 4, b - 4, a + 4, b + 4);
    157               graphics.DrawLine(cross, a - 4, b + 4, a + 4, b - 4);
    158             }
    159             if (Content.Population != null) {
    160               foreach (RealVector vector in Content.Population)
    161                 graphics.FillEllipse(Brushes.Blue, (float)((vector[0] - xMin) * xStep - 4), (float)((vector[1] - yMin) * yStep - 4), 8.0f, 8.0f);
    162             }
    163             if (Content.BestRealVector != null) {
    164               graphics.FillEllipse(Brushes.Green, (float)((Content.BestRealVector[0] - xMin) * xStep - 5), (float)((Content.BestRealVector[1] - yMin) * yStep - 5), 10.0f, 10.0f);
    165             }
    166           }
     139      if (!pictureBox.Enabled || pictureBox.Width <= 0 || pictureBox.Height <= 0) return;
     140      if (Content == null) {
     141        pictureBox.Image = null;
     142        return;
     143      }
     144      if (backgroundImage == null) {
     145        GenerateBackgroundImage();
     146        pictureBox.Image = backgroundImage;
     147      }
     148      pictureBox.Refresh();
     149      DoubleMatrix bounds = Content.Bounds;
     150      if (bounds == null) bounds = Content.Evaluator.Bounds;
     151      double xMin = bounds[0, 0], xMax = bounds[0, 1], yMin = bounds[1 % bounds.Rows, 0], yMax = bounds[1 % bounds.Rows, 1];
     152      double xStep = backgroundImage.Width / (xMax - xMin), yStep = backgroundImage.Height / (yMax - yMin);
     153
     154      using (Graphics graphics = pictureBox.CreateGraphics()) {
     155        if (Content.BestKnownRealVector != null && Content.BestKnownRealVector.Length == 2) {
     156          Pen cross = new Pen(Brushes.Red, 2.0f);
     157          float a = (float)((Content.BestKnownRealVector[0] - xMin) * xStep);
     158          float b = (float)((Content.BestKnownRealVector[1] - yMin) * yStep);
     159          graphics.DrawLine(cross, a - 4, b - 4, a + 4, b + 4);
     160          graphics.DrawLine(cross, a - 4, b + 4, a + 4, b - 4);
     161        }
     162        if (Content.Population != null) {
     163          foreach (RealVector vector in Content.Population.Where(x => x.Length == 2))
     164            graphics.FillEllipse(Brushes.Blue, (float)((vector[0] - xMin) * xStep - 4), (float)((vector[1] - yMin) * yStep - 4), 8.0f, 8.0f);
     165        }
     166        if (Content.BestRealVector != null && Content.BestRealVector.Length == 2) {
     167          graphics.FillEllipse(Brushes.Green, (float)((Content.BestRealVector[0] - xMin) * xStep - 5), (float)((Content.BestRealVector[1] - yMin) * yStep - 5), 10.0f, 10.0f);
    167168        }
    168169      }
Note: See TracChangeset for help on using the changeset viewer.