Skip to content

Commit 27880bc

Browse files
authored
Merge pull request #12 from RobThree/master
Add support for .Net Core and .Net Standard
2 parents 7969528 + 71bdbac commit 27880bc

20 files changed

+77
-353
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ Generated_Code #added for RIA/Silverlight projects
113113
_UpgradeReport_Files/
114114
Backup*/
115115
UpgradeLog*.XML
116+
/.vs/

KdTreeLib/HyperRect.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using KdTree.Math;
5-
6-
namespace KdTree
1+
namespace KdTree
72
{
8-
public struct HyperRect<T>
3+
public struct HyperRect<T>
94
{
105
private T[] minPoint;
116
public T[] MinPoint
@@ -37,12 +32,13 @@ public T[] MaxPoint
3732

3833
public static HyperRect<T> Infinite(int dimensions, ITypeMath<T> math)
3934
{
40-
var rect = new HyperRect<T>();
41-
42-
rect.MinPoint = new T[dimensions];
43-
rect.MaxPoint = new T[dimensions];
35+
var rect = new HyperRect<T>
36+
{
37+
MinPoint = new T[dimensions],
38+
MaxPoint = new T[dimensions]
39+
};
4440

45-
for (var dimension = 0; dimension < dimensions; dimension++)
41+
for (var dimension = 0; dimension < dimensions; dimension++)
4642
{
4743
rect.MinPoint[dimension] = math.NegativeInfinity;
4844
rect.MaxPoint[dimension] = math.PositiveInfinity;
@@ -75,10 +71,12 @@ public T[] GetClosestPoint(T[] toPoint, ITypeMath<T> math)
7571

7672
public HyperRect<T> Clone()
7773
{
78-
var rect = new HyperRect<T>();
79-
rect.MinPoint = MinPoint;
80-
rect.MaxPoint = MaxPoint;
81-
return rect;
74+
var rect = new HyperRect<T>
75+
{
76+
MinPoint = MinPoint,
77+
MaxPoint = MaxPoint
78+
};
79+
return rect;
8280
}
8381
}
8482
}

KdTreeLib/IKdTree.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
62

73
namespace KdTree
84
{
9-
public interface IKdTree<TKey, TValue> : IEnumerable<KdTreeNode<TKey, TValue>>
5+
public interface IKdTree<TKey, TValue> : IEnumerable<KdTreeNode<TKey, TValue>>
106
{
117
bool Add(TKey[] point, TValue value);
128

KdTreeLib/IPriorityQueue.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace KdTree
1+
namespace KdTree
82
{
9-
public interface IPriorityQueue<TItem, TPriority>
3+
public interface IPriorityQueue<TItem, TPriority>
104
{
115
void Enqueue(TItem item, TPriority priority);
126

KdTreeLib/KdTree.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace KdTree
1010
{
11-
public enum AddDuplicateBehavior
11+
public enum AddDuplicateBehavior
1212
{
1313
Skip,
1414
Error,
@@ -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
{

KdTreeLib/KdTreeLib.csproj

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,25 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{68C8066D-7844-41C2-993D-3160798164D1}</ProjectGuid>
8-
<OutputType>Library</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>KdTree</RootNamespace>
11-
<AssemblyName>KdTreeLib</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
4+
<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;netstandard2.0;netcoreapp2.0</TargetFrameworks>
5+
<Authors>codeandcats@gmail.com</Authors>
6+
<Company>codeandcats@gmail.com</Company>
7+
<PackageId>KdTree</PackageId>
8+
<NoPackageAnalysis>true</NoPackageAnalysis>
9+
<Product>KdTree</Product>
10+
<Copyright>Copyright codeandcats@gmail.com 2013</Copyright>
11+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
12+
<PackageLicenseUrl>https://raw.github.com/codeandcats/KdTree/master/LICENSE</PackageLicenseUrl>
13+
<PackageProjectUrl>https://github.com/codeandcats/KdTree</PackageProjectUrl>
14+
<PackageTags>kdtree kd-tree binary search tree bst spatial</PackageTags>
15+
<PackageReleaseNotes>* Added netcore and netstandard support</PackageReleaseNotes>
16+
<Description>Generic multi-dimensional binary search tree.</Description>
17+
<PackageIconUrl>https://raw.githubusercontent.com/codeandcats/KdTree/master/Images/kdtree.png</PackageIconUrl>
18+
<Version>1.4.0</Version>
19+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1420
</PropertyGroup>
15-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16-
<DebugSymbols>true</DebugSymbols>
17-
<DebugType>full</DebugType>
18-
<Optimize>false</Optimize>
19-
<OutputPath>bin\Debug\</OutputPath>
20-
<DefineConstants>DEBUG;TRACE</DefineConstants>
21-
<ErrorReport>prompt</ErrorReport>
22-
<WarningLevel>4</WarningLevel>
21+
22+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
23+
<DefineConstants>TRACE;RELEASE;NETSTANDARD2_0</DefineConstants>
2324
</PropertyGroup>
24-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25-
<DebugType>pdbonly</DebugType>
26-
<Optimize>true</Optimize>
27-
<OutputPath>bin\Release\</OutputPath>
28-
<DefineConstants>TRACE</DefineConstants>
29-
<ErrorReport>prompt</ErrorReport>
30-
<WarningLevel>4</WarningLevel>
31-
</PropertyGroup>
32-
<ItemGroup>
33-
<Reference Include="System" />
34-
<Reference Include="System.Core" />
35-
<Reference Include="System.Xml.Linq" />
36-
<Reference Include="System.Data.DataSetExtensions" />
37-
<Reference Include="Microsoft.CSharp" />
38-
<Reference Include="System.Data" />
39-
<Reference Include="System.Xml" />
40-
</ItemGroup>
41-
<ItemGroup>
42-
<Compile Include="HyperRect.cs" />
43-
<Compile Include="IPriorityQueue.cs" />
44-
<Compile Include="Math\DoubleMath.cs" />
45-
<Compile Include="Math\FloatMath.cs" />
46-
<Compile Include="Math\GeoMath.cs" />
47-
<Compile Include="Math\GeoUtils.cs" />
48-
<Compile Include="Math\ITypeMath.cs" />
49-
<Compile Include="IKdTree.cs" />
50-
<Compile Include="KdTree.cs" />
51-
<Compile Include="KdTreeNode.cs" />
52-
<Compile Include="Math\TypeMath.cs" />
53-
<Compile Include="NearestNeighbourList.cs" />
54-
<Compile Include="PriorityQueue.cs" />
55-
<Compile Include="Properties\AssemblyInfo.cs" />
56-
</ItemGroup>
57-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
58-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
59-
Other similar extension points exist, see Microsoft.Common.targets.
60-
<Target Name="BeforeBuild">
61-
</Target>
62-
<Target Name="AfterBuild">
63-
</Target>
64-
-->
6525
</Project>

KdTreeLib/KdTreeNode.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
42
using System.Text;
5-
using System.Threading.Tasks;
63

74
namespace KdTree
85
{
9-
[Serializable]
6+
[Serializable]
107
public class KdTreeNode<TKey, TValue>
118
{
129
public KdTreeNode()

KdTreeLib/Math/DoubleMath.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

73
namespace KdTree.Math
84
{

KdTreeLib/Math/FloatMath.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

73
namespace KdTree.Math
84
{
9-
[Serializable]
5+
[Serializable]
106
public class FloatMath : TypeMath<float>
117
{
128
public override int Compare(float a, float b)

KdTreeLib/Math/GeoMath.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

73
namespace KdTree.Math
84
{
9-
[Serializable]
5+
[Serializable]
106
public class GeoMath : FloatMath
117
{
128
public override float DistanceSquaredBetweenPoints(float[] a, float[] b)

0 commit comments

Comments
 (0)