public AsInterval(T start, T end)
 {
     Start = start;
     End   = new List <T>();
     End.Add(end);
     NextDimensionIntervals = new AsIntervalTree <T>();
 }
        public DIntervalTree(int dimensions)
        {
            if (dimensions <= 0)
            {
                throw new Exception("Dimension should be greater than 0.");
            }

            this.dimensions = dimensions;
            this.tree       = new AsIntervalTree <T>();
        }
        /// <summary>
        /// does this interval overlap with any interval in this interval tree?
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private List <DInterval <T> > GetOverlaps(AsIntervalTree <T> currentTree,
                                                  T[] start, T[] end, int dimension)
        {
            var nodes = currentTree.GetOverlaps(new AsInterval <T>(start[dimension], end[dimension]));

            if (dimension + 1 == dimensions)
            {
                var result = new List <DInterval <T> >();

                foreach (var node in nodes)
                {
                    var fStart = new T[dimensions];
                    var fEnd   = new T[dimensions];

                    fStart[dimension] = node.Start;
                    fEnd[dimension]   = node.End[node.MatchingEndIndex];

                    var thisDimResult = new DInterval <T>(fStart, fEnd);

                    result.Add(thisDimResult);
                }

                return(result);
            }
            else
            {
                var result = new List <DInterval <T> >();

                foreach (var node in nodes)
                {
                    var nextDimResult = GetOverlaps(node.NextDimensionIntervals, start, end, dimension + 1);

                    foreach (var nextResult in nextDimResult)
                    {
                        nextResult.Start[dimension] = node.Start;
                        nextResult.End[dimension]   = node.End[node.MatchingEndIndex];

                        result.Add(nextResult);
                    }
                }

                return(result);
            }
        }