Ejemplo n.º 1
0
        private static void DrawRectangle(List <HpglItem> result, HPoint pt, int w, int h)
        {
            var p1 = pt.Add(new HPoint()
            {
                X = w, Y = h
            });
            var p2 = pt.Add(new HPoint()
            {
                X = -w, Y = h
            });
            var p3 = pt.Add(new HPoint()
            {
                X = -w, Y = -h
            });
            var p4 = pt.Add(new HPoint()
            {
                X = w, Y = -h
            });

            result.Add(new PenUp()
            {
                Points = { p1 }
            });
            result.Add(new PenDown()
            {
                Points = { p2, p3, p4, p1 }
            });
            result.Add(new PenUp()
            {
            });
        }
Ejemplo n.º 2
0
    public HBhvAnimation AddAnimation(string name, string targetpath, HPoint pivot)
    {
        IntPtr        cPtr = HCSMVOPINVOKE.HBhvBehaviorManager_AddAnimation__SWIG_2(swigCPtr, name, targetpath, HPoint.getCPtr(pivot));
        HBhvAnimation ret  = (cPtr == IntPtr.Zero) ? null : new HBhvAnimation(cPtr, false);

        return(ret);
    }
Ejemplo n.º 3
0
 protected override void MoveTo(HPoint p)
 {
     if (isPenDown)
     {
         if (Numbering && HPoint.LengthAbs(p, lastText) > 20)
         {
             var tp = ToPoint(p);
             g.DrawString(counter + "", SystemFonts.IconTitleFont, Brushes.Black, tp.X, tp.Y);
             counter++;
             lastText = p;
         }
         if (current == p)
         {
             g.DrawLine(currentGPen, ToPoint(p), ToPoint(p.Add(new HPoint(1, 1))));
         }
         else
         {
             g.DrawLine(currentGPen, ToPoint(current), ToPoint(p));
         }
     }
     else
     {
         if (DebugPenUp)
         {
             g.DrawLine(debugPen, ToPoint(current), ToPoint(p));
         }
     }
     base.MoveTo(p);
 }
Ejemplo n.º 4
0
 public HSlideObject(int id, HPoint location, HPoint target, HMoveType type = HMoveType.None)
 {
     Id = id;
     Location = location;
     Target = target;
     Type = type;
 }
Ejemplo n.º 5
0
        public FurnitureDropEventArgs(Func <Task> continuation, int step, HMessage packet)
            : base(continuation, step, packet)
        {
            Id     = Packet.ReadInteger();
            TypeId = Packet.ReadInteger();

            int x = Packet.ReadInteger();
            int y = Packet.ReadInteger();

            Direction = (HDirection)Packet.ReadInteger();

            Tile = new HPoint(x, y,
                              double.Parse(Packet.ReadString(), CultureInfo.InvariantCulture));

            Packet.ReadString();
            Packet.ReadInteger();
            Packet.ReadInteger();
            Packet.ReadString();

            IsRental = (Packet.ReadInteger() != 1);
            Packet.ReadInteger();

            OwnerId   = Packet.ReadInteger();
            OwnerName = Packet.ReadString();
        }
Ejemplo n.º 6
0
    public virtual HPoint GetRotationAxis(MVO_POINTER_SIZED_INT handlekey)
    {
        IntPtr cPtr = HCSMVOPINVOKE.HUtilityGeomHandle_GetRotationAxis(swigCPtr, handlekey);
        HPoint ret  = (cPtr == IntPtr.Zero) ? null : new HPoint(cPtr, false);

        return(ret);
    }
Ejemplo n.º 7
0
        private HPoint[] GetOutlinedRect(HPoint p1, HPoint p2, int outline)
        {
            /*     p1
             *   +--+--+
             *    \  \  \
             *     \  \  \
             *      +--+--+
             *         p2   p2+len
             *
             */
            if (p1 == p2)
            {
                return(new[] { p1, p1, p1, p1 });
            }

            var pt1    = new Point2D(p1.X, p1.Y);
            var pt2    = new Point2D(p2.X, p2.Y);
            var vector = Vector2D.FromPoints(pt2, pt1);
            var points = new[] {
                new Point2D(-outline, 0),
                new Point2D(0, outline),
                new Point2D(vector.Length, outline),
                new Point2D(vector.Length + outline, 0),
                new Point2D(vector.Length, -outline),
                new Point2D(0, -outline),
                new Point2D(-outline, 0),
            };
            var rotated = points.Select(pt => pt1.Add(pt.Rotate(vector.Angle))).Select(pt => new HPoint((int)pt.X, (int)pt.Y)).ToArray();

            return(rotated);
        }
Ejemplo n.º 8
0
    public HFloorObject(IHFormat format, ref ReadOnlySpan <byte> packetSpan)
    {
        Id     = format.Read <int>(ref packetSpan);
        TypeId = format.Read <int>(ref packetSpan);

        int x = format.Read <int>(ref packetSpan);
        int y = format.Read <int>(ref packetSpan);

        Facing = (HDirection)format.Read <int>(ref packetSpan);
        Tile   = new HPoint(x, y, float.Parse(format.ReadUTF8(ref packetSpan), CultureInfo.InvariantCulture));

        Height = double.Parse(format.ReadUTF8(ref packetSpan), CultureInfo.InvariantCulture);
        Extra  = format.Read <int>(ref packetSpan);

        StuffData = HStuffData.Parse(format, ref packetSpan);

        SecondsToExpiration = format.Read <int>(ref packetSpan);
        UsagePolicy         = (HUsagePolicy)format.Read <int>(ref packetSpan);

        OwnerId = format.Read <int>(ref packetSpan);
        if (TypeId < 0)
        {
            StaticClass = format.ReadUTF8(ref packetSpan);
        }
    }
Ejemplo n.º 9
0
        private List <HpglItem> SegmentsToHpgl()
        {
            var result = new List <HpglItem>();

            result.Add(new Initialization());
            var last = new HPoint();

            foreach (var line in segments)
            {
                if (last != line.P1 || result.Count == 0)
                {
                    result.Add(new PenUp()
                    {
                        Points = { line.P1 }
                    });
                    result.Add(new PenDown()
                    {
                        Points = { line.P2 }
                    });
                }
                else
                {
                    var lastDown = (PenDown)result.Last();
                    lastDown.Points.Add(line.P2);
                }
                last = line.P2;
            }
            result.Add(new PenUp());
            return(result);
        }
Ejemplo n.º 10
0
 public HPlane(HPoint normal, float D) : this(HCSMVOPINVOKE.new_HPlane__SWIG_5(HPoint.getCPtr(normal), D), true)
 {
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 11
0
 public HostMoveFurnitureEventArgs(Func <Task> continuation, int step, HMessage packet)
     : base(continuation, step, packet)
 {
     Id        = packet.ReadInteger();
     Tile      = new HPoint(packet.ReadInteger(), packet.ReadInteger());
     Direction = (HDirection)packet.ReadInteger();
 }
Ejemplo n.º 12
0
    public HPoint GetPivot()
    {
        IntPtr cPtr = HCSMVOPINVOKE.HBhvTargetObject_GetPivot__SWIG_1(swigCPtr);
        HPoint ret  = (cPtr == IntPtr.Zero) ? null : new HPoint(cPtr, false);

        return(ret);
    }
Ejemplo n.º 13
0
        public HostWalkEventArgs(HMessage packet)
        {
            _packet = packet;
            Header  = _packet.Header;

            Tile = new HPoint(_packet.ReadInt(0), _packet.ReadInt(4));
        }
Ejemplo n.º 14
0
    public HPoint WindowColor()
    {
        IntPtr cPtr = HCSMVOPINVOKE.HOutputHandlerOptions_WindowColor__SWIG_0(swigCPtr);
        HPoint ret  = (cPtr == IntPtr.Zero) ? null : new HPoint(cPtr, false);

        return(ret);
    }
Ejemplo n.º 15
0
        public HFloorObject(HMessage packet)
        {
            Id     = packet.ReadInteger();
            TypeId = packet.ReadInteger();

            var tile = new HPoint(packet.ReadInteger(), packet.ReadInteger());

            Facing = (HDirection)packet.ReadInteger();

            tile.Z = double.Parse(packet.ReadString(), CultureInfo.InvariantCulture);
            Tile   = tile;

            packet.ReadString();
            packet.ReadInteger();

            Category = packet.ReadInteger();
            Stuff    = ReadData(packet, Category);

            SecondsToExpiration = packet.ReadInteger();
            UsagePolicy         = (HUsagePolicy)packet.ReadInteger();

            OwnerId = packet.ReadInteger();
            if (TypeId < 0)
            {
                packet.ReadString();
            }
        }
Ejemplo n.º 16
0
    public HSlideObjectBundle(IHFormat format, ref ReadOnlySpan <byte> packetSpan)
    {
        int locationX = format.Read <int>(ref packetSpan);
        int locationY = format.Read <int>(ref packetSpan);

        int    targetX = format.Read <int>(ref packetSpan);
        int    targetY = format.Read <int>(ref packetSpan);
        HPoint location, target;

        Objects = new HSlideObject[format.Read <int>(ref packetSpan)];
        for (int i = 0; i < Objects.Length; i++)
        {
            int objectId = format.Read <int>(ref packetSpan);

            location = new HPoint(locationX, locationY, float.Parse(format.ReadUTF8(ref packetSpan), CultureInfo.InvariantCulture));
            target   = new HPoint(targetX, targetY, float.Parse(format.ReadUTF8(ref packetSpan), CultureInfo.InvariantCulture));

            Objects[i] = new HSlideObject(objectId, location, target);
        }

        Id = format.Read <int>(ref packetSpan);
        if (!packetSpan.IsEmpty)
        {
            var type = (HMoveType)format.Read <int>(ref packetSpan);

            int entityIndex = format.Read <int>(ref packetSpan);
            location = new HPoint(locationX, locationY, float.Parse(format.ReadUTF8(ref packetSpan), CultureInfo.InvariantCulture));
            target   = new HPoint(targetX, targetY, float.Parse(format.ReadUTF8(ref packetSpan), CultureInfo.InvariantCulture));

            Entity = new HSlideObject(entityIndex, location, target, type);
        }
    }
Ejemplo n.º 17
0
 ////////////////////////////////////////
 //
 void Move()
 {
     if (IsDown)
     {
         ControlPosition = Position;
     }
 }
Ejemplo n.º 18
0
        public static List <HpglItem> DrawString(string s, int scale = 6)
        {
            var result = new List <HpglItem>();

            EnsureCharMap();
            bool penUp = true;

            result.Add(new PenUp());

            foreach (var ch in s)
            {
                var current = new Point(0, scale); //jeden bod nad carou
                if (ch < ' ' || ch > '\x7f')
                {
                    continue;
                }
                if (ch != ' ')
                {
                    var charInstructions = charMap[ch];
                    for (int i = 0; i < charInstructions.Count; i++)
                    {
                        var instr = charInstructions[i];
                        if ((instr & 0x40) > 0)
                        {
                            if (penUp)
                            {
                                result.Add(new PenDown());
                            }
                            penUp = false;
                        }
                        else
                        {
                            if (!penUp)
                            {
                                result.Add(new PenUp());
                            }
                            penUp = true;
                        }
                        var np = new Point(instr & 0x7, (instr & 0x38) >> 3); //absolutni pozice od 0,0
                        np = new Point(np.X * scale, np.Y * scale);
                        result.Add(new PenRelative()
                        {
                            Points = { new HPoint(np.X - current.X, np.Y - current.Y) }
                        });
                        current = np;
                    }
                }

                //move
                penUp = true;
                var p = new HPoint(6 * scale - current.X, scale - current.Y);
                result.Add(new PenUp());
                result.Add(new PenRelative()
                {
                    Points = { p }
                });
            }
            return(result);
        }
Ejemplo n.º 19
0
 public static void ComputeShellNormal(MVO_POINTER_SIZED_INT skey, HPoint tnormal)
 {
     HCSMVOPINVOKE.HUtility_ComputeShellNormal(skey, HPoint.getCPtr(tnormal));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 20
0
 public static void CalculateBoundingInfo(MVO_POINTER_SIZED_INT startkey, HPoint min, HPoint max, HPoint delta, HPoint mid)
 {
     HCSMVOPINVOKE.HUtility_CalculateBoundingInfo(startkey, HPoint.getCPtr(min), HPoint.getCPtr(max), HPoint.getCPtr(delta), HPoint.getCPtr(mid));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 21
0
 private HPoint CompensatePen(HPoint size)
 {
     if (PenWidthCompensation > 0)
     {
         size = size.Sub(new HPoint((int)(1000 * PenWidthCompensation), (int)(1000 * PenWidthCompensation)));
     }
     return(size);
 }
Ejemplo n.º 22
0
 new public virtual void MoveText(HPoint A, HPoint B)
 {
     HCSMVOPINVOKE.HUtilityAnnotationMeasure_MoveText__SWIG_1(swigCPtr, HPoint.getCPtr(A), HPoint.getCPtr(B));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 23
0
 public static void InterpolateNormalAlongEdge(HPoint p1, HPoint n1, HPoint p2, HPoint n2, HPoint p3, HPoint n3)
 {
     HCSMVOPINVOKE.HUtility_InterpolateNormalAlongEdge(HPoint.getCPtr(p1), HPoint.getCPtr(n1), HPoint.getCPtr(p2), HPoint.getCPtr(n2), HPoint.getCPtr(p3), HPoint.getCPtr(n3));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 24
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     if (!IsDragable)
     {
         base.OnMouseDown(e); return;
     }
     DownLocation = PointToClient(MousePosition); IsDown = true; base.OnMouseDown(e);
 }
Ejemplo n.º 25
0
 public static void ComputeVectorToVectorRotationMatrix(float[] matrix, HPoint v1, HPoint v2)
 {
     HCSMVOPINVOKE.HUtility_ComputeVectorToVectorRotationMatrix(matrix, HPoint.getCPtr(v1), HPoint.getCPtr(v2));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 26
0
 public static void AdjustPositionToPlane(HBaseView view, HPoint position, HPoint point_in_plane)
 {
     HCSMVOPINVOKE.HUtility_AdjustPositionToPlane(HBaseView.getCPtr(view), HPoint.getCPtr(position), HPoint.getCPtr(point_in_plane));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 27
0
 public static void RotateToVector(HPoint start, HPoint end)
 {
     HCSMVOPINVOKE.HUtility_RotateToVector__SWIG_1(HPoint.getCPtr(start), HPoint.getCPtr(end));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 28
0
 public static void SmoothTransition(HPoint co, HPoint to, HPoint uo, float fieldwidtho, float fieldheighto, HPoint cn, HPoint tn, HPoint un, float fieldwidthn, float fieldheightn, HBaseView view)
 {
     HCSMVOPINVOKE.HUtility_SmoothTransition__SWIG_0(HPoint.getCPtr(co), HPoint.getCPtr(to), HPoint.getCPtr(uo), fieldwidtho, fieldheighto, HPoint.getCPtr(cn), HPoint.getCPtr(tn), HPoint.getCPtr(un), fieldwidthn, fieldheightn, HBaseView.getCPtr(view));
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 29
0
 protected override void OnMouseUp(MouseEventArgs e)
 {
     DownLocation = null; if (!IsDragable)
     {
         base.OnMouseUp(e); return;
     }
     IsDown = false; base.OnMouseUp(e);
 }
Ejemplo n.º 30
0
 public static void GetMatrixFromCamera(HPoint target, HPoint position, HPoint up_vector, HPoint translation, float[] matrix)
 {
     HCSMVOPINVOKE.HUtility_GetMatrixFromCamera(HPoint.getCPtr(target), HPoint.getCPtr(position), HPoint.getCPtr(up_vector), HPoint.getCPtr(translation), matrix);
     if (HCSMVOPINVOKE.SWIGPendingException.Pending)
     {
         throw HCSMVOPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 31
0
 // used in initial conditions of KDTree.nearest()
 public static HRect InfiniteHRect(int d)
 {
     HPoint vmin = new HPoint(d);
     HPoint vmax = new HPoint(d);
     for (int i = 0; i < d; ++i) {
         vmin.Coord[i] = double.NegativeInfinity;
         vmax.Coord[i] = double.PositiveInfinity;
     }
     return new HRect(vmin, vmax);
 }
Ejemplo n.º 32
0
 // from Moore's eqn. 6.6
 public HPoint Closest(HPoint t)
 {
     HPoint p = new HPoint(t.Coord.Length);
     for (int i = 0; i < t.Coord.Length; ++i) {
         if (t.Coord[i] <= this.min.Coord[i]) {
             p.Coord[i] = this.min.Coord[i];
         } else if (t.Coord[i] >= this.max.Coord[i]) {
             p.Coord[i] = this.max.Coord[i];
         } else {
             p.Coord[i] = t.Coord[i];
         }
     }
     return p;
 }
Ejemplo n.º 33
0
            // Method ins translated from 352.ins.c of Gonnet & Baeza-Yates
            public static KDNode ins(HPoint key, Object val, KDNode t, int lev, int K) {
                if (t == null) {
                    t = new KDNode(key, val);
                }

                else if (key.equals(t.k)) {

                    // "re-insert"
                    if (t.deleted) {
                        t.deleted = false;
                        t.v = val;
                    }

                    else {
                        throw (new KeyDuplicateException());
                    }
                }

                else if (key.coord[lev] > t.k.coord[lev]) {
                    t.right = ins(key, val, t.right, (lev + 1) % K, K);
                }
                else {
                    t.left = ins(key, val, t.left, (lev + 1) % K, K);
                }

                return t;
            }
Ejemplo n.º 34
0
        /**
        * Find KD-tree nodes whose keys are <I>n</I> nearest neighbors to
        * key. Uses algorithm above.  Neighbors are returned in ascending
        * order of distance to key. 
        *
        * @param key key for KD-tree node
        * @param n how many neighbors to find
        *
        * @return objects at node nearest to key, or null on failure
        *
        * @throws KeySizeException if key.length mismatches K
        * @throws IllegalArgumentException if <I>n</I> is negative or
        * exceeds tree size 
        */
        public Object[] nearest(float[] key, int n) {

            if (n < 0 || n > m_count) {
                throw new ArgumentException("Number of neighbors cannot be negative or greater than number of nodes");
            }

            if (key.Length != m_K) {
                throw new ApplicationException("new KeySizeException(");
            }

            Object[] nbrs = new Object[n];
            NearestNeighborList nnl = new NearestNeighborList(n);

            // initial call is with infinite hyper-rectangle and max distance
            HRect hr = new AABB();
            float max_dist_sqd = float.MaxValue;
            HPoint keyp = new HPoint(key);

            KDNode.nnbr(m_root, keyp, hr, max_dist_sqd, 0, m_K, nnl);

            for (int i = 0; i < n; ++i) {
                KDNode kd = (KDNode)nnl.removeHighest();
                nbrs[n - i - 1] = kd.v;
            }

            return nbrs;
        }
Ejemplo n.º 35
0
            public static KDNode delete(HPoint key, KDNode t, int lev, int K, ref bool deleted) {
                if (t == null) return null;
                if (!t.deleted && key.equals(t.k)) {
                    t.deleted = true;
                    deleted = true;
                }
                else if (key.coord[lev] > t.k.coord[lev]) {
                    t.right = delete(key, t.right, (lev + 1) % K, K, ref deleted);
                }
                else {
                    t.left = delete(key, t.left, (lev + 1) % K, K, ref deleted);
                }

                if (!t.deleted || t.left != null || t.right != null) {
                    return t;
                }
                else {
                    return null;
                }
            }
Ejemplo n.º 36
0
            // Method srch translated from 352.srch.c of Gonnet & Baeza-Yates
            public static KDNode srch(HPoint key, KDNode t, int K) {

                for (int lev = 0; t != null; lev = (lev + 1) % K) {

                    if (!t.deleted && key.equals(t.k)) {
                        return t;
                    }
                    else if (key.coord[lev] > t.k.coord[lev]) {
                        t = t.right;
                    }
                    else {
                        t = t.left;
                    }
                }

                return null;
            }
Ejemplo n.º 37
0
            // Method Nearest Neighbor from Andrew Moore's thesis. Numbered
            // comments are direct quotes from there. Step "SDL" is added to
            // make the algorithm work correctly.  NearestNeighborList solution
            // courtesy of Bjoern Heckel.
            public static void nnbr(KDNode kd, HPoint target, HRect hr,
                                  float max_dist_sqd, int lev, int K,
                                  NearestNeighborList nnl) {

                // 1. if kd is empty then set dist-sqd to infinity and exit.
                if (kd == null) {
                    return;
                }

                // 2. s := split field of kd
                int s = lev % K;

                // 3. pivot := dom-elt field of kd
                HPoint pivot = kd.k;
                float pivot_to_target = HPoint.sqrdist(pivot, target);

                // 4. Cut hr into to sub-hyperrectangles left-hr and right-hr.
                //    The cut plane is through pivot and perpendicular to the s
                //    dimension.
                HRect left_hr = hr; // optimize by not cloning
                HRect right_hr = (HRect)hr.clone();
                left_hr.max.coord[s] = pivot.coord[s];
                right_hr.min.coord[s] = pivot.coord[s];

                // 5. target-in-left := target_s <= pivot_s
                bool target_in_left = target.coord[s] < pivot.coord[s];

                KDNode nearer_kd;
                HRect nearer_hr;
                KDNode further_kd;
                HRect further_hr;

                // 6. if target-in-left then
                //    6.1. nearer-kd := left field of kd and nearer-hr := left-hr
                //    6.2. further-kd := right field of kd and further-hr := right-hr
                if (target_in_left) {
                    nearer_kd = kd.left;
                    nearer_hr = left_hr;
                    further_kd = kd.right;
                    further_hr = right_hr;
                }
                //
                // 7. if not target-in-left then
                //    7.1. nearer-kd := right field of kd and nearer-hr := right-hr
                //    7.2. further-kd := left field of kd and further-hr := left-hr
                else {
                    nearer_kd = kd.right;
                    nearer_hr = right_hr;
                    further_kd = kd.left;
                    further_hr = left_hr;
                }

                // 8. Recursively call Nearest Neighbor with paramters
                //    (nearer-kd, target, nearer-hr, max-dist-sqd), storing the
                //    results in nearest and dist-sqd
                nnbr(nearer_kd, target, nearer_hr, max_dist_sqd, lev + 1, K, nnl);

                KDNode nearest = (KDNode)nnl.getHighest();
                float dist_sqd;

                if (!nnl.isCapacityReached()) {
                    dist_sqd = float.MaxValue;
                }
                else {
                    dist_sqd = nnl.getMaxPriority();
                }

                // 9. max-dist-sqd := minimum of max-dist-sqd and dist-sqd
                max_dist_sqd = Math.Min(max_dist_sqd, dist_sqd);

                // 10. A nearer point could only lie in further-kd if there were some
                //     part of further-hr within distance sqrt(max-dist-sqd) of
                //     target.  If this is the case then
                HPoint closest = further_hr.closest(target);
                if (HPoint.Distance(ref closest, ref target) < Math.Sqrt(max_dist_sqd)) {

                    // 10.1 if (pivot-target)^2 < dist-sqd then
                    if (pivot_to_target < dist_sqd) {

                        // 10.1.1 nearest := (pivot, range-elt field of kd)
                        nearest = kd;

                        // 10.1.2 dist-sqd = (pivot-target)^2
                        dist_sqd = pivot_to_target;

                        // add to nnl
                        if (!kd.deleted) {
                            nnl.insert(kd, dist_sqd);
                        }

                        // 10.1.3 max-dist-sqd = dist-sqd
                        // max_dist_sqd = dist_sqd;
                        if (nnl.isCapacityReached()) {
                            max_dist_sqd = nnl.getMaxPriority();
                        }
                        else {
                            max_dist_sqd = float.MaxValue;
                        }
                    }

                    // 10.2 Recursively call Nearest Neighbor with parameters
                    //      (further-kd, target, further-hr, max-dist_sqd),
                    //      storing results in temp-nearest and temp-dist-sqd
                    nnbr(further_kd, target, further_hr, max_dist_sqd, lev + 1, K, nnl);
                    KDNode temp_nearest = (KDNode)nnl.getHighest();
                    float temp_dist_sqd = nnl.getMaxPriority();

                    // 10.3 If tmp-dist-sqd < dist-sqd then
                    if (temp_dist_sqd < dist_sqd) {

                        // 10.3.1 nearest := temp_nearest and dist_sqd := temp_dist_sqd
                        nearest = temp_nearest;
                        dist_sqd = temp_dist_sqd;
                    }
                }

                // SDL: otherwise, current point is nearest
                else if (pivot_to_target < max_dist_sqd) {
                    nearest = kd;
                    dist_sqd = pivot_to_target;
                }
            }
Ejemplo n.º 38
0
            // Method rsearch translated from 352.range.c of Gonnet & Baeza-Yates
            public static void rsearch(HPoint lowk, HPoint uppk, KDNode t, int lev,
                      int K, List<KDNode> v) {

                if (t == null) return;
                if (lowk.coord[lev] <= t.k.coord[lev]) {
                    rsearch(lowk, uppk, t.left, (lev + 1) % K, K, v);
                }
                int j;
                for (j = 0; j < K && lowk.coord[j] <= t.k.coord[j] &&
                     uppk.coord[j] >= t.k.coord[j]; j++)
                    ;
                if (j == K && !t.deleted) v.Add(t);
                if (uppk.coord[lev] > t.k.coord[lev]) {
                    rsearch(lowk, uppk, t.right, (lev + 1) % K, K, v);
                }
            }
Ejemplo n.º 39
0
            // constructor is used only by class; other methods are static
            private KDNode(HPoint key, Object val) {

                k = key;
                v = val;
                left = null;
                right = null;
                deleted = false;
            }
Ejemplo n.º 40
0
 private static void hpcopy(HPoint hp_src, HPoint hp_dst) {
     for (int i = 0; i < hp_dst.coord.Length; ++i) {
         hp_dst.coord[i] = hp_src.coord[i];
     }
 }
Ejemplo n.º 41
0
 // currently unused
 public HRect Intersection(HRect r)
 {
     HPoint newmin = new HPoint(this.min.Coord.Length);
     HPoint newmax = new HPoint(this.min.Coord.Length);
     for (int i = 0; i < this.min.Coord.Length; ++i) {
         newmin.Coord[i] = Math.Max(this.min.Coord[i], r.min.Coord[i]);
         newmax.Coord[i] = Math.Min(this.max.Coord[i], r.max.Coord[i]);
         if (newmin.Coord[i] >= newmax.Coord[i]) {
             return null;
         }
     }
     return new HRect(newmin, newmax);
 }
Ejemplo n.º 42
0
 public HRect(int ndims)
 {
     this.min = new HPoint(ndims);
     this.max = new HPoint(ndims);
 }
Ejemplo n.º 43
0
 public HRect(HPoint vmin, HPoint vmax)
 {
     this.min = (HPoint) vmin.Clone();
     this.max = (HPoint) vmax.Clone();
 }