Skip to content

Commit 20b6086

Browse files
committed
* A little code cleanup
1 parent 5908c5a commit 20b6086

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

KdTreeLib/HyperRect.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public T[] MaxPoint
3232

3333
public static HyperRect<T> Infinite(int dimensions, ITypeMath<T> math)
3434
{
35-
var rect = new HyperRect<T>();
35+
var rect = new HyperRect<T>
36+
{
37+
MinPoint = new T[dimensions],
38+
MaxPoint = new T[dimensions]
39+
};
3640

37-
rect.MinPoint = new T[dimensions];
38-
rect.MaxPoint = new T[dimensions];
39-
40-
for (var dimension = 0; dimension < dimensions; dimension++)
41+
for (var dimension = 0; dimension < dimensions; dimension++)
4142
{
4243
rect.MinPoint[dimension] = math.NegativeInfinity;
4344
rect.MaxPoint[dimension] = math.PositiveInfinity;
@@ -70,10 +71,12 @@ public T[] GetClosestPoint(T[] toPoint, ITypeMath<T> math)
7071

7172
public HyperRect<T> Clone()
7273
{
73-
var rect = new HyperRect<T>();
74-
rect.MinPoint = MinPoint;
75-
rect.MaxPoint = MaxPoint;
76-
return rect;
74+
var rect = new HyperRect<T>
75+
{
76+
MinPoint = MinPoint,
77+
MaxPoint = MaxPoint
78+
};
79+
return rect;
7780
}
7881
}
7982
}

KdTreeLib/KdTree.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,11 @@ public bool TryFindValueAt(TKey[] point, out TValue value)
396396

397397
public TValue FindValueAt(TKey[] point)
398398
{
399-
TValue value;
400-
if (TryFindValueAt(point, out value))
401-
return value;
402-
else
403-
return default(TValue);
404-
}
399+
if (TryFindValueAt(point, out TValue value))
400+
return value;
401+
else
402+
return default(TValue);
403+
}
405404

406405
public bool TryFindValue(TValue value, out TKey[] point)
407406
{
@@ -443,12 +442,11 @@ public bool TryFindValue(TValue value, out TKey[] point)
443442

444443
public TKey[] FindValue(TValue value)
445444
{
446-
TKey[] point;
447-
if (TryFindValue(value, out point))
448-
return point;
449-
else
450-
return null;
451-
}
445+
if (TryFindValue(value, out TKey[] point))
446+
return point;
447+
else
448+
return null;
449+
}
452450

453451
private void AddNodeToStringBuilder(KdTreeNode<TKey, TValue> node, StringBuilder sb, int depth)
454452
{
@@ -598,21 +596,21 @@ public IEnumerator<KdTreeNode<TKey, TValue>> GetEnumerator()
598596
var left = new Stack<KdTreeNode<TKey, TValue>>();
599597
var right = new Stack<KdTreeNode<TKey, TValue>>();
600598

601-
Action<KdTreeNode<TKey, TValue>> addLeft = node =>
599+
void addLeft(KdTreeNode<TKey, TValue> node)
602600
{
603601
if (node.LeftChild != null)
604602
{
605603
left.Push(node.LeftChild);
606604
}
607-
};
605+
}
608606

609-
Action<KdTreeNode<TKey, TValue>> addRight = node =>
607+
void addRight(KdTreeNode<TKey, TValue> node)
610608
{
611609
if (node.RightChild != null)
612610
{
613611
right.Push(node.RightChild);
614612
}
615-
};
613+
}
616614

617615
if (root != null)
618616
{

0 commit comments

Comments
 (0)