Skip to content

CoordinateRect.Contains doesn't work for 'inverted' objects #4596

@SprinterDave

Description

@SprinterDave

Issue:
The CoordinateRect.Contains class does not act logically for CoordinateRects where IsInvertedX or IsInvertedY returns true.

ScottPlot Version:
5.0.47

Code Sample:

using System.Diagnostics;

namespace ScottPlotInvertedCoordinateRect
{
  internal class Program
  {
    static void Main(string[] args)
    {
      double value = 5;
      ScottPlot.Plot myPlot = new();
      ScottPlot.Bar myNegativeBar = new() { Value = -value };
      ScottPlot.Bar myPositiveBar = new() { Value = value };
      myPlot.Add.Bars(new[] { myNegativeBar, myPositiveBar });

      myPlot.SavePng("repro.png", 400, 300);
      myPlot.ZoomRectangle.VerticalSpan = true;

      // Should not assert
      Debug.Assert(myPositiveBar.Rect.Contains(0, value / 2),
        $"Rect {myPositiveBar.Rect} should contain the point (0, {value/2})");

      // Should not assert, but does
      Debug.Assert(myNegativeBar.Rect.Contains(0, -value / 2),
        $"Rect {myNegativeBar.Rect} should contain the point (0, {-value / 2})");
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions