Skip to content

Conversation

@hagish
Copy link

@hagish hagish commented Jul 18, 2015

This is a snippet from the unit test that triggered the bug.

private class Something
{
    public int Id;
    public Envelope Envelope;

    public override int GetHashCode()
    {
        return Id.GetHashCode();
    }

    public override bool Equals(System.Object obj)
    {
        // If parameter is null return false.
        if (obj == null)
        {
            return false;
        }

        if (obj is Something)
        {
            return Id == ((Something)obj).Id;
        }
        else
        {
            return false;
        }
    }

    public bool Equals(Something p)
    {
        // If parameter is null return false:
        if ((object)p == null)
        {
            return false;
        }

        // Return true if the fields match:
        return Id == p.Id;
    }

    public override string ToString()
    {
        return string.Format("[Id={0} Env={1}]", Id, Envelope);
    }
}

[TestMethod]
public void RTreeMass2()
{
    RTree<Something> r = new RTree<Something>();

    List<Something> l = new List<Something>();

    int count = 100;

    for (int i = 0; i < count; ++i)
    {
        int x = 5 - (i % 10);
        int y = 5 - ((i*i) % 10);
        int radius = 1 + i % 5;

        var o = new Something(){
            Id = i,
            Envelope = new Envelope(x-radius, y-radius, x+radius, y+radius),
        };

        l.Add(o);
    }

    // add all
    foreach(var it in l){
        r.Insert(it, it.Envelope);
    }

    // query all
    foreach(var it in l)
    {
        // search
        Assert.AreEqual(true, r.Search(it.Envelope).Any(i => i.Data == it));

        Assert.AreEqual(count, r.Search(new Envelope(-1000, -1000, 1000, 1000)).Count());

        // remove
        r.Remove(it, it.Envelope);
        count--;

        Assert.AreEqual(count, r.Search(new Envelope(-1000, -1000, 1000, 1000)).Count());                
    }

    Assert.AreEqual(count, r.Search(new Envelope(-1000, -1000, 1000, 1000)).Count());                
}

hagish added 2 commits July 18, 2015 19:06
The path list in CondenseNodes in the C# implementation seems to be reverted in comparison to the original JS implementation.
@deight
Copy link

deight commented Nov 17, 2017

Thank you very much for the contribuition!
You saved me a lot of time.

Its a pity that your pull has not been accepted yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants