Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions Nsi.Geospatial/Spatial/RTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public double cumulativeOverlap { get; set; }
public double siblingOverlap { get; set; }

public RTreeNode(RTreeManager treemanager, int maxChildren, int minChildren, int[] featInd = null)

Check warning on line 28 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_parent' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 28 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
_treeManager = treemanager;
maxChidrens = maxChildren;
Expand Down Expand Up @@ -56,23 +56,23 @@
{
_parent._children.Remove(this);
newKidsOntheBlock[0].UpdateParents(_parent);
newKidsOntheBlock[1].UpdateParents(_parent);
_parent.addChild(newKidsOntheBlock[0], true);
_parent.addChild(newKidsOntheBlock[1], false);
newKidsOntheBlock[1].UpdateParents(_parent);
_parent.addChild(newKidsOntheBlock[0], false, true);
_parent.addChild(newKidsOntheBlock[1], true, true);
}
else
{
RTreeNode newRoot = new RTreeNode(_treeManager, maxChidrens, minChidrens);
newKidsOntheBlock[0].UpdateParents(newRoot);
newKidsOntheBlock[1].UpdateParents(newRoot);
newRoot.addChild(newKidsOntheBlock[0], true);
newRoot.addChild(newKidsOntheBlock[1], false);
_treeManager._root = newRoot;
newRoot.addChild(newKidsOntheBlock[0], false, true);
newRoot.addChild(newKidsOntheBlock[1], true, true);
_treeManager._root = newRoot;
}
}
private void buildChildOptions(List<(RTreeNode[], double[])> options, bool xAxis, bool min)
{
List<RTreeNode> sortedChidrens = null;

Check warning on line 75 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
if(xAxis)
{
if (min) { sortedChidrens = _children.OrderBy(c => c.MBRXMin).ToList(); }
Expand All @@ -93,11 +93,11 @@
var Child = sortedChidrens[i];
if (i < split)
{
node1.addChild(Child, true);
node1.addChild(Child, false, false);
}
else
{
node2.addChild(Child, true);
node2.addChild(Child, false, false);
}
}
double overlapWidth = Math.Max(0, Math.Min(node1.MBRXMax, node2.MBRXMax) - Math.Max(node1.MBRXMin, node2.MBRXMin));
Expand All @@ -118,11 +118,11 @@
{
if(getIsEndNode)
{
addChild(feature, false);
addChild(feature, true, true);
}
else
{
RTreeNode bestCandidate = null;

Check warning on line 125 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
double minExtension = double.MaxValue;
foreach (RTreeNode childnode in _children)
{
Expand All @@ -132,12 +132,12 @@
bestCandidate = childnode;
minExtension = extensionReq;
}
else if (extensionReq == minExtension && childnode.getArea < bestCandidate.getArea)

Check warning on line 135 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
bestCandidate = childnode;
}
}
bestCandidate.addFeatureChild(feature);

Check warning on line 140 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
}
public void addFeatureChildEnforceIntersect(RTreeNode feature)
Expand All @@ -146,7 +146,7 @@
List<RTreeNode> candidateKids = new List<RTreeNode>();
getCandidateEndNodesByMBR(feature.MBRXMax, feature.MBRXMin, feature.MBRYMax, feature.MBRYMin, candidateKids);
if (candidateKids.Count == 0) { candidateKids = _treeManager.getEndNodes; }
RTreeNode bestCandidate = null;

Check warning on line 149 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
double minExtension = double.MaxValue;
foreach (RTreeNode candidate in candidateKids)
{
Expand All @@ -157,20 +157,24 @@
minExtension = extensionReq;
}
}
bestCandidate.addChild(feature, false);
bestCandidate.addChild(feature, true, true);

Check warning on line 160 in Nsi.Geospatial/Spatial/RTreeNode.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
public void addChild(RTreeNode child, bool evaluation)
public void addChild(RTreeNode child, bool canSplit, bool canPropagateMBRup)
{
_children.Add(child);
child._parent = this;
if(child.MBRXMin < MBRXMin) { MBRXMin = child.MBRXMin; }
if(child.MBRXMax > MBRXMax) { MBRXMax = child.MBRXMax; }
if(child.MBRYMin < MBRYMin) { MBRYMin = child.MBRYMin; }
if(child.MBRYMax > MBRYMax) { MBRYMax = child.MBRYMax; }
if(_children.Count > maxChidrens && !evaluation)
if(_children.Count > maxChidrens && canSplit)
{
split();
}
else if(canPropagateMBRup)
{
RecomputeMBR();
}
}
public void RecomputeMBR()
{
Expand Down Expand Up @@ -318,4 +322,4 @@
get { return 2 * ((MBRXMax - MBRXMin) + (MBRYMax - MBRYMin)); }
}
}
}
}
8 changes: 6 additions & 2 deletions tests/Nsi.Geospatial.Tests/RTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void FindByInd_ReturnsLeafToRootPath()
Assert.NotNull(featureIndex);
}

[Fact(Skip = "Fails by design: asserts correct behavior that the original (unfixed) RTree split/overlap defects violate. Re-enable once the RTree defects are fixed.")]
[Fact] //(Skip = "Fails by design: asserts correct behavior that the original (unfixed) RTree split/overlap defects violate. Re-enable once the RTree defects are fixed.")]
public void BulkInsert_AllFeaturesFindableByPoint()
{
var tree = new RTreeManager(minChilds: 3, maxChilds: 6);
Expand All @@ -65,6 +65,10 @@ public void BulkInsert_AllFeaturesFindableByPoint()
for (int i = 0; i < 500; i++)
{
var hits = FeatureIndicesAt(tree, i * 10 + 2.5, i * 10 + 2.5);
if (!hits.Contains(i))
{
string test = "WTF";
}
Assert.Contains(i, hits);
}
}
Expand Down Expand Up @@ -107,4 +111,4 @@ private static List<int> FeatureIndicesAt(RTreeManager tree, double x, double y)
}
return indices;
}
}
}
Loading