Esempio n. 1
0
        private Box GetBox([NotNull] BoxTile tile)
        {
            Pnt     min      = Pnt.Create(_dimension);
            Pnt     max      = Pnt.Create(_dimension);
            var     handled  = new bool[_dimension];
            var     nHandled = 0;
            BoxTile t        = tile;

            while (t.Parent != null && nHandled < _dimension)
            {
                if (!handled[t.Parent.SplitDimension])
                {
                    min[t.Parent.SplitDimension]     = t.MinInParentSplitDim;
                    max[t.Parent.SplitDimension]     = t.MaxInParentSplitDim;
                    handled[t.Parent.SplitDimension] = true;
                    nHandled++;
                }

                t = t.Parent;
            }

            if (nHandled < _dimension)
            {
                for (var iHandled = 0; iHandled < _dimension; iHandled++)
                {
                    if (!handled[iHandled])
                    {
                        min[iHandled] = _mainBox.Min[iHandled];
                        max[iHandled] = _mainBox.Max[iHandled];
                    }
                }
            }

            return(new Box(min, max));
        }
            public NeighborhoodEnumerator([NotNull] BoxTree searchingTree,
                                          [NotNull] BoxTree neighbourTree,
                                          double searchDistance, [CanBeNull] IBox common)
            {
                _searchingTree  = searchingTree;
                _neighbourTree  = neighbourTree;
                _searchDistance = searchDistance;

                Pnt min = Pnt.Create(_searchingTree._unitBox.Min);
                Pnt max = Pnt.Create(_searchingTree._unitBox.Max);

                for (var i = 0; i < min.Dimension; i++)
                {
                    min[i] = Math.Max(min[i], _neighbourTree._unitBox.Min[i]);
                    if (common != null)
                    {
                        min[i] = Math.Max(min[i], common.Min[i]);
                    }

                    min[i] -= searchDistance;

                    max[i] = Math.Min(max[i], _neighbourTree._unitBox.Max[i]);
                    if (common != null)
                    {
                        max[i] = Math.Min(max[i], common.Max[i]);
                    }

                    max[i] += searchDistance;
                }

                _common = new Box(min, max);

                Reset();
            }
                private void WriteBox(StringBuilder s, string ctx, Box box, Box x, double f,
                                      double lineWidth = 1, string color = null)
                {
                    Pnt min = (1.0 / f) * (Pnt.Create(box.Min) - x.Min);
                    Pnt max = (1.0 / f) * (Pnt.Create(box.Max) - x.Min);

                    s.AppendFormat("{0}.save();", ctx);
                    s.AppendLine();
                    s.AppendFormat("{0}.lineWidth = {1:N0};", ctx, lineWidth);
                    s.AppendLine();
                    if (!string.IsNullOrEmpty(color))
                    {
                        s.AppendFormat("{0}.strokeStyle = '{1}';", ctx, color);
                        s.AppendLine();
                    }

                    s.AppendFormat("{0}.beginPath();", ctx);
                    s.AppendLine();
                    s.AppendFormat("{0}.moveTo({1:N1},{2:N1});", ctx, min.X, min.Y);
                    s.AppendLine();
                    s.AppendFormat("{0}.lineTo({1:N1},{2:N1});", ctx, min.X, max.Y);
                    s.AppendLine();
                    s.AppendFormat("{0}.lineTo({1:N1},{2:N1});", ctx, max.X, max.Y);
                    s.AppendLine();
                    s.AppendFormat("{0}.lineTo({1:N1},{2:N1});", ctx, max.X, min.Y);
                    s.AppendLine();
                    s.AppendFormat("{0}.lineTo({1:N1},{2:N1});", ctx, min.X, min.Y);
                    s.AppendLine();
                    s.AppendFormat("{0}.stroke();", ctx);
                    s.AppendLine();
                    s.AppendFormat("{0}.restore();", ctx);
                    s.AppendLine();
                }
Esempio n. 4
0
        private void InitSize([NotNull] IEnumerable data)
        {
            Assert.ArgumentNotNull(data, nameof(data));

            _unitBox = null;

            foreach (object row in data)
            {
                var  geometry = row as IGmtry;
                IBox box      = geometry?.Extent ?? ((TileEntry)row).Box;

                if (_unitBox == null)
                {
                    Pnt min = Pnt.Create(_dimension);
                    Pnt max = Pnt.Create(_dimension);
                    for (var i = 0; i < _dimension; i++)
                    {
                        min[i] = box.Min[i];
                        max[i] = box.Max[i];
                    }

                    _unitBox = new Box(min, max);
                    continue;
                }

                for (var i = 0; i < _dimension; i++)
                {
                    if (box.Min[i] < _unitBox.Min[i])
                    {
                        _unitBox.Min[i] = box.Min[i];
                    }

                    if (box.Max[i] > _unitBox.Max[i])
                    {
                        _unitBox.Max[i] = box.Max[i];
                    }
                }
            }

            if (_unitBox == null)
            {
                throw new InvalidOperationException("data containes no values");
            }

            // double the size of each dimension
            _mainBox     = _unitBox.Clone();
            _mainCounter = new int[_dimension];
            _mainSize    = new int[_dimension];

            for (var i = 0; i < _dimension; i++)
            {
                _mainBox.Max[i] = 2 * _unitBox.Max[i] - _unitBox.Min[i];
                _mainCounter[i] = 0;
                _mainSize[i]    = 2;
            }
        }
Esempio n. 5
0
        public static Pnt CreatePoint3D(WKSPointZ wksPoint)
        {
            Pnt result = Pnt.Create(3);

            result.X  = wksPoint.X;
            result.Y  = wksPoint.Y;
            result[2] = wksPoint.Z;

            return(result);
        }
                private void TileToString(StringBuilder sb, IBox b0, IBox bt)
                {
                    Pnt dx0 = Pnt.Create(b0.Max) - b0.Min;
                    Pnt dxt = Pnt.Create(bt.Max) - bt.Min;
                    Pnt ds  = Pnt.Create(bt.Min) - b0.Min;

                    for (var i = 0; i < bt.Dimension; i++)
                    {
                        var nx = (int)Math.Round(dx0[i] / dxt[i]);
                        var ix = (int)Math.Round(2 * ds[i] / dxt[i]);
                        sb.AppendFormat("{0}:{1}/{2}; ", (char)('x' + i), ix, nx);
                    }
                }
Esempio n. 7
0
        public IEnumerable <SegmentProxy> GetSegments(IBox box)
        {
            foreach (SegmentProxy segment in GetSegments())
            {
                Pnt min    = Pnt.Create(segment.Min);
                Pnt max    = Pnt.Create(segment.Max);
                var segBox = new Box(min, max);

                if (segBox.Intersects(box))
                {
                    yield return(segment);
                }
            }
        }
        private static Box GetSearchBox([NotNull] IBox rawBox, double search,
                                        [NotNull] IBox commonBox)
        {
            int dim = commonBox.Dimension;
            Pnt min = Pnt.Create(dim);
            Pnt max = Pnt.Create(dim);

            for (var i = 0; i < dim; i++)
            {
                min[i] = Math.Max(rawBox.Min[i] - search, commonBox.Min[i]);
                max[i] = Math.Min(rawBox.Max[i] + search, commonBox.Max[i]);

                if (min[i] > max[i])
                {
                    return(null);
                }
            }

            return(new Box(min, max));
        }