Rectangle constructor sometimes assigns properties incorrectly/not at all

In regards to the Rectangle constructor, I discovered that the constructor sometimes assigns the wrong property values (or not at all).

Consider these unit tests:

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class GeneralTests
{
    [TestMethod]
    public void TestMethod1()
    {
        var r = new Aspose.Pdf.Rectangle(1, 2, 3, 4);

        Assert.AreEqual(1, r.LLX);
        Assert.AreEqual(2, r.LLY);
        Assert.AreEqual(3, r.URX);
        Assert.AreEqual(4, r.URY);
    }

    [TestMethod]
    public void TestMethod2()
    {
        var r = new Aspose.Pdf.Rectangle(0, 0, 0, 0);

        Assert.AreEqual(0, r.LLX);
        Assert.AreEqual(0, r.LLY);
        Assert.AreEqual(0, r.URX);
        Assert.AreEqual(0, r.URY);
    }

    [TestMethod]
    public void TestMethod3()
    {
        var r = new Aspose.Pdf.Rectangle(10_000, 10_000, 0, 0);

        Assert.AreEqual(10_000, r.LLX);
        Assert.AreEqual(10_000, r.LLY);
        Assert.AreEqual(0, r.URX);
        Assert.AreEqual(0, r.URY);
    }

    [TestMethod]
    public void TestMethod4()
    {
        var r = new Aspose.Pdf.Rectangle(0, 0, 0, 0);

        r.LLX = 10_000;
        r.LLY = 10_000;

        Assert.AreEqual(10_000, r.LLX);
        Assert.AreEqual(10_000, r.LLY);
        Assert.AreEqual(0, r.URX);
        Assert.AreEqual(0, r.URY);
    }

    [TestMethod]
    public void TestMethod5()
    {
        var r = new Aspose.Pdf.Rectangle(1_000, 1_000, 0, 0);

        Assert.AreEqual(1_000, r.LLX);
        Assert.AreEqual(1_000, r.LLY);
        Assert.AreEqual(0, r.URX);
        Assert.AreEqual(0, r.URY);
    }

    [TestMethod]
    public void TestMethod6()
    {
        var r = new Aspose.Pdf.Rectangle(100, 200, 300, 400);

        Assert.AreEqual(100, r.LLX);
        Assert.AreEqual(200, r.LLY);
        Assert.AreEqual(300, r.URX);
        Assert.AreEqual(400, r.URY);
    }

    [TestMethod]
    public void TestMethod7()
    {
        var r = new Aspose.Pdf.Rectangle(10_000, 10_000, 200, 200);

        Assert.AreEqual(10_000, r.LLX);
        Assert.AreEqual(10_000, r.LLY);
        Assert.AreEqual(200, r.URX);
        Assert.AreEqual(200, r.URY);
    }
}

Here, the following tests succeed:

  • Test Method 1
  • Test Method 2
  • Test Method 4
  • Test Method 6

Whereas the following tests fail:

  • Test Method 3
  • Test Method 5
  • Test Method 7

image.png (8.9 KB)

My questions

Am I doing something wrong?

If not, any fix/workaround to always have the constructor work correctly?

Probably I figured it out:

The following additional test method works:

[TestMethod]
public void TestMethod8()
{
    var r = new Aspose.Pdf.Rectangle(0, 0, 10_000, 10_000);

    Assert.AreEqual(0, r.LLX);
    Assert.AreEqual(0, r.LLY);
    Assert.AreEqual(10_000, r.URX);
    Assert.AreEqual(10_000, r.URY);
}

It seems that the constructor enforces this parameter order (as documented):

  1. X of lower left corner.
  2. Y of lower left corner.
  3. X of upper right corner.
  4. Y of upper right corner.

The emphasis here seems to be “lower” and “upper”.

So as soon as parameter 1 is smaller (“lower”) than parameter 3 and parameter 2 is smaller (“lower”) than parameter 4, the unit tests seems to succeed.

On the other hand as soon as a “lower” parameter is greater than an “upper” parameter, it is simply ignored/modified. :confused:

Expectations

I still would expect such an essential method to correctly throw an ArgumentException and not simply silently ignore/modify my passed values, but at least it behaves deterministically now.

@Uwe_Keim

We have observed your comments and have logged an enhancement request as PDFNET-51448 in our issue management system. We will further check this scenario and implement the required exception in the API. We will let you know as soon as the ticket is resolved. Please spare us some time.

We are sorry for the inconvenience.

1 Like