/// <summary>
 /// Converts an object into its XML representation.
 /// </summary>
 /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized. </param>
 public void WriteXml(XmlWriter writer)
 {
     writer.WriteElementString("BottomLeft", BottomLeft.ToString());
     writer.WriteElementString("BottomRight", BottomRight.ToString());
     writer.WriteElementString("TopLeft", TopLeft.ToString());
     writer.WriteElementString("TopRight", TopRight.ToString());
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a new item into the Quadrant.
 /// </summary>
 public void Add(T item, Rect bounds)
 {
     if (!LastLevelQuadrant)
     {
         if (topRightBounds.Contains(bounds))
         {
             TopRight ??= new Quadrant(topRightBounds);
             TopRight.Add(item, bounds);
         }
         else if (topLeftBounds.Contains(bounds))
         {
             TopLeft ??= new Quadrant(topLeftBounds);
             TopLeft.Add(item, bounds);
         }
         else if (bottomRightBounds.Contains(bounds))
         {
             BottomRight ??= new Quadrant(bottomRightBounds);
             BottomRight.Add(item, bounds);
         }
         else if (bottomLeftBounds.Contains(bounds))
         {
             BottomLeft ??= new Quadrant(bottomLeftBounds);
             BottomLeft.Add(item, bounds);
         }
         else
         {
             ItemsInQuadrant.Add(item);
         }
     }
     else
     {
         ItemsInQuadrant.Add(item);
     }
     Count++;
 }
Exemplo n.º 3
0
        /// <summary>
        /// help method to sort units in the right subtree based on thier position in the quad
        /// </summary>
        void AddObjectToSubTrees(Agent agent)
        {
            var pos = agent.position.ToWorld();

            if (pos.X < Quad.Center.X)
            {
                if (pos.Y < Quad.Center.Y)
                {
                    BottomLeft.AddObject(agent);
                }
                else
                {
                    TopLeft.AddObject(agent);
                }
            }
            else
            {
                if (pos.Y < Quad.Center.Y)
                {
                    BottomRight.AddObject(agent);
                }
                else
                {
                    TopRight.AddObject(agent);
                }
            }
        }
Exemplo n.º 4
0
 public override int GetHashCode()
 {
     return(TopLeft.GetHashCode()
            ^ TopRight.GetHashCode()
            ^ BottomLeft.GetHashCode()
            ^ BottomRight.GetHashCode());
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the distance from this to the other rect. 0 if there is an overlap.
        /// </summary>
        /// <param name="Other">Other rectangle.</param>
        public double Distance(C2DRect Other)
        {
            if (this.Overlaps(Other))
            {
                return(0);
            }

            if (Other.GetLeft() > this.BottomRight.x)
            {
                // Other is to the right
                if (Other.GetBottom() > this.TopLeft.y)
                {
                    // Other is to the top right
                    C2DPoint ptTopRight = new C2DPoint(BottomRight.x, TopLeft.y);
                    return(ptTopRight.Distance(new C2DPoint(Other.GetLeft(), Other.GetBottom())));
                }
                else if (Other.GetTop() < this.BottomRight.y)
                {
                    // Other to the bottom right
                    return(BottomRight.Distance(Other.TopLeft));
                }
                else
                {
                    // to the right
                    return(Other.GetLeft() - this.BottomRight.x);
                }
            }
            else if (Other.GetRight() < this.TopLeft.x)
            {
                // Other to the left
                if (Other.GetBottom() > this.TopLeft.y)
                {
                    // Other is to the top left
                    return(TopLeft.Distance(Other.BottomRight));
                }
                else if (Other.GetTop() < this.BottomRight.y)
                {
                    // Other to the bottom left
                    C2DPoint ptBottomLeft = new C2DPoint(TopLeft.x, BottomRight.y);
                    return(ptBottomLeft.Distance(new C2DPoint(Other.GetRight(), Other.GetTop())));
                }
                else
                {
                    //Just to the left
                    return(this.TopLeft.x - Other.GetRight());
                }
            }
            else
            {
                // There is horizontal overlap;
                if (Other.GetBottom() > TopLeft.y)
                {
                    return(Other.GetBottom() - TopLeft.y);
                }
                else
                {
                    return(BottomRight.y - Other.GetTop());
                }
            }
        }
Exemplo n.º 6
0
 public SquareTarget(Block topLeft)
 {
     TopLeft     = topLeft;
     TopRight    = TopLeft.GetRightBlock();
     BottomRight = TopRight.GetBottomBlock();
     BottomLeft  = BottomRight.GetLeftBlock();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Splits the given leaf at the given point and returns itself (with changes, if the leaf was found).
        /// </summary>
        /// <param name="leaf">The leaf supposed to be split.</param>
        /// <param name="x">The x coordinate of the point.</param>
        /// <param name="y">The y coordinate of the point.</param>
        /// <returns>Itself (with changes, if they happened).</returns>
        public override QuadTreeNode <TContent, TAverage> Split(QuadTreeNode <TContent, TAverage> leaf, double x, double y)
        {
            // Can't find a null leaf.
            if (leaf == null)
            {
                return(this);
            }

            throwWhenOutsideNode(x, y);

            if (TopRight.IsInsideNode(x, y))
            {
                TopRight = TopRight.Split(leaf, x, y);
            }

            if (BottomRight.IsInsideNode(x, y))
            {
                BottomRight = BottomRight.Split(leaf, x, y);
            }

            if (BottomLeft.IsInsideNode(x, y))
            {
                BottomLeft = BottomLeft.Split(leaf, x, y);
            }

            if (TopLeft.IsInsideNode(x, y))
            {
                TopLeft = TopLeft.Split(leaf, x, y);
            }

            invalidateAverage();

            return(this);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Splits the leaf node that contains the point at the given point and returns itself (with changes, if they happened).
        /// </summary>
        /// <param name="x">The x coordinate of the point.</param>
        /// <param name="y">The y coordinate of the point.</param>
        /// <returns>Itself (with changes, if they happened).</returns>
        public override QuadTreeNode <TContent, TAverage> Split(double x, double y)
        {
            throwWhenOutsideNode(x, y);

            if (TopRight.IsInsideNode(x, y))
            {
                TopRight = TopRight.Split(x, y);
            }

            if (BottomRight.IsInsideNode(x, y))
            {
                BottomRight = BottomRight.Split(x, y);
            }

            if (BottomLeft.IsInsideNode(x, y))
            {
                BottomLeft = BottomLeft.Split(x, y);
            }

            if (TopLeft.IsInsideNode(x, y))
            {
                TopLeft = TopLeft.Split(x, y);
            }

            invalidateAverage();

            return(this);
        }
Exemplo n.º 9
0
            /// <summary>
            /// Removes an item from this Quadrant.
            /// Returns true if item was found and removed, false otherwise.
            /// </summary>
            public bool Remove(T item, Rect bounds)
            {
                bool removed;

                if (TopRight != null && topRightBounds.Contains(bounds))
                {
                    removed = TopRight.Remove(item, bounds);
                }
                else if (TopLeft != null && topLeftBounds.Contains(bounds))
                {
                    removed = TopLeft.Remove(item, bounds);
                }
                else if (BottomRight != null && bottomRightBounds.Contains(bounds))
                {
                    removed = BottomRight.Remove(item, bounds);
                }
                else if (BottomLeft != null && bottomLeftBounds.Contains(bounds))
                {
                    removed = BottomLeft.Remove(item, bounds);
                }
                else
                {
                    removed = ItemsInQuadrant.Remove(item);
                }

                if (removed)
                {
                    Count--;
                }
                return(removed);
            }
Exemplo n.º 10
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (TopLeft == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "TopLeft");
     }
     if (TopRight == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "TopRight");
     }
     if (BottomRight == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "BottomRight");
     }
     if (BottomLeft == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "BottomLeft");
     }
     if (TopLeft != null)
     {
         TopLeft.Validate();
     }
     if (TopRight != null)
     {
         TopRight.Validate();
     }
     if (BottomRight != null)
     {
         BottomRight.Validate();
     }
     if (BottomLeft != null)
     {
         BottomLeft.Validate();
     }
 }
Exemplo n.º 11
0
 public bool Equals(LatLngQuad other)
 {
     return(TopLeft.Equals(other.TopLeft) &&
            TopRight.Equals(other.TopRight) &&
            BottomLeft.Equals(other.BottomLeft) &&
            BottomRight.Equals(other.BottomRight));
 }
Exemplo n.º 12
0
 public void MergeFrom(PathTimeObstacle other)
 {
     if (other == null)
     {
         return;
     }
     if (other.ObstacleId.Length != 0)
     {
         ObstacleId = other.ObstacleId;
     }
     if (other.bottomLeft_ != null)
     {
         if (bottomLeft_ == null)
         {
             bottomLeft_ = new global::Apollo.Planning.PathTimePoint();
         }
         BottomLeft.MergeFrom(other.BottomLeft);
     }
     if (other.upperLeft_ != null)
     {
         if (upperLeft_ == null)
         {
             upperLeft_ = new global::Apollo.Planning.PathTimePoint();
         }
         UpperLeft.MergeFrom(other.UpperLeft);
     }
     if (other.upperRight_ != null)
     {
         if (upperRight_ == null)
         {
             upperRight_ = new global::Apollo.Planning.PathTimePoint();
         }
         UpperRight.MergeFrom(other.UpperRight);
     }
     if (other.bottomRight_ != null)
     {
         if (bottomRight_ == null)
         {
             bottomRight_ = new global::Apollo.Planning.PathTimePoint();
         }
         BottomRight.MergeFrom(other.BottomRight);
     }
     if (other.TimeLower != 0D)
     {
         TimeLower = other.TimeLower;
     }
     if (other.TimeUpper != 0D)
     {
         TimeUpper = other.TimeUpper;
     }
     if (other.PathLower != 0D)
     {
         PathLower = other.PathLower;
     }
     if (other.PathUpper != 0D)
     {
         PathUpper = other.PathUpper;
     }
 }
Exemplo n.º 13
0
 public Vector2D[] GetRotatedRectangleCorners(Vector2D center, float rotation)
 {
     return(new[]
     {
         TopLeft.RotateAround(center, rotation), BottomLeft.RotateAround(center, rotation),
         BottomRight.RotateAround(center, rotation), TopRight.RotateAround(center, rotation)
     });
 }
Exemplo n.º 14
0
        public override string getCodeName()
        {
            String output = this.GetType().Name.imbGetWordAbbrevation(3, true);

            output = output.add(TopLeft.getCodeName(), "-").add(BottomRight.getCodeName(), "-");

            return(output);
        }
Exemplo n.º 15
0
 public override Container GetBounds()
 {
     return(new Container()
     {
         TopLeft = TopLeft.Clone(),
         BottomRight = BottomRight.Clone()
     });
 }
Exemplo n.º 16
0
 public Obj16Tile FlipY()
 {
     return(new Obj16Tile(
                TopRight.FlipY(),
                TopLeft.FlipY(),
                BottomRight.FlipY(),
                BottomLeft.FlipY()));
 }
Exemplo n.º 17
0
 public bool Equals(GeoBoundingBox other)
 {
     if (other == null)
     {
         throw new ArgumentNullException(nameof(other));
     }
     return(TopLeft.Equals(other.TopLeft) && BottomRight.Equals(other.BottomRight));
 }
Exemplo n.º 18
0
        public override int GetHashCode()
        {
            int result = 17;

            result = result * 37 + TopLeft.GetHashCode();
            result = result * 37 + BottomRight.GetHashCode();
            return(result);
        }
Exemplo n.º 19
0
 public bool Equals(Obj16Tile other)
 {
     return
         (TopLeft.Equals(other.TopLeft) &&
          TopRight.Equals(other.TopRight) &&
          BottomLeft.Equals(other.BottomLeft) &&
          BottomRight.Equals(other.BottomRight));
 }
Exemplo n.º 20
0
        /// <summary>
        ///     Creates a new quad by rotate all 4 vertices clockwise about the specified center point
        /// </summary>
        /// <param name="degrees">Angle to rotate clockwise (degrees)</param>
        /// <param name="centerX">X coordinate of point about which to rotate</param>
        /// <param name="centerY">Y coordinate of point about which to rotate</param>
        /// <returns>Returns the rotate quad</returns>
        public Quad Rotate(double degrees, double centerX, double centerY)
        {
            var newBottomLeft  = BottomLeft.Rotate(degrees, centerX, centerY);
            var newTopLeft     = TopLeft.Rotate(degrees, centerX, centerY);
            var newTopRight    = TopRight.Rotate(degrees, centerX, centerY);
            var newBottomRight = BottomRight.Rotate(degrees, centerX, centerY);

            return(new Quad(newBottomLeft, newTopLeft, newTopRight, newBottomRight));
        }
Exemplo n.º 21
0
 public void UpdateTerrain(TerrainUpdate update)
 {
     if (!BottomRight.Contains(update.Position))
     {
         return; // We can ignore out of bound updates, as these are not accessible anyway.
     }
     (Int32 x, Int32 y) = update.Position;
     Terrain[x, y]      = update.NewTerrain;
 }
Exemplo n.º 22
0
        /// <summary>
        /// Projection onto the Vector.
        /// </summary>
        /// <param name="Vector">Vector to project on.</param>
        /// <param name="Interval">Ouput. Projection.</param>
        public override void Project(C2DVector Vector, CInterval Interval)
        {
            this.TopLeft.Project(Vector, Interval);
            Interval.ExpandToInclude(BottomRight.Project(Vector));
            C2DPoint TR = new C2DPoint(BottomRight.x, TopLeft.y);
            C2DPoint BL = new C2DPoint(TopLeft.x, BottomRight.y);

            Interval.ExpandToInclude(TR.Project(Vector));
            Interval.ExpandToInclude(BL.Project(Vector));
        }
Exemplo n.º 23
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = List.GetHashCode();
         hashCode = (hashCode * 397) ^ UpperLeft.GetHashCode();
         hashCode = (hashCode * 397) ^ BottomRight.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// Projection onto the line
        /// </summary>
        /// <param name="Line">Line to project on.</param>
        /// <param name="Interval">Ouput. Projection.</param>
        public override void Project(C2DLine Line, CInterval Interval)
        {
            this.TopLeft.Project(Line, Interval);
            Interval.ExpandToInclude(BottomRight.Project(Line));
            var TR = new C2DPoint(BottomRight.x, TopLeft.y);
            var BL = new C2DPoint(TopLeft.x, BottomRight.y);

            Interval.ExpandToInclude(TR.Project(Line));
            Interval.ExpandToInclude(BL.Project(Line));
        }
Exemplo n.º 25
0
        public override bool Equals(object obj)
        {
            Rectangle other = obj as Rectangle;

            if (other == null)
            {
                return(false);
            }

            return(TopLeft.Equals(other.TopLeft) && BottomRight.Equals(other.BottomRight));
        }
Exemplo n.º 26
0
 public void RangeScanQuads(WorldPosition position, double range, List <Agent> buffer)
 {
     if (new Quad(position, range).Intersect(Quad))
     {
         buffer.AddRange(Agents);
         TopRight?.RangeScanQuads(position, range, buffer);
         TopLeft?.RangeScanQuads(position, range, buffer);
         BottomRight?.RangeScanQuads(position, range, buffer);
         BottomLeft?.RangeScanQuads(position, range, buffer);
     }
 }
Exemplo n.º 27
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = TopLeft.GetHashCode();
         hashCode = (hashCode * 397) ^ TopRight.GetHashCode();
         hashCode = (hashCode * 397) ^ BottomRight.GetHashCode();
         hashCode = (hashCode * 397) ^ BottomLeft.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 28
0
 /// <summary>
 /// Returns a hash code for the specified object
 /// </summary>
 /// <returns>A hash code for the specified object</returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (BottomLeft != null ? BottomLeft.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TopLeft != null ? TopLeft.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TopRight != null ? TopRight.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (BottomRight != null ? BottomRight.GetHashCode() : 0);
         return(hashCode);
     }
 }
Exemplo n.º 29
0
        /// <inheritdoc/>
        public override void Move(double dx, double dy)
        {
            if (!TopLeft.State.Flags.HasFlag(ShapeStateFlags.Connector))
            {
                TopLeft.Move(dx, dy);
            }

            if (!BottomRight.State.Flags.HasFlag(ShapeStateFlags.Connector))
            {
                BottomRight.Move(dx, dy);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Reflect throught the point given.
        /// Switches Top Left and Bottom Right to maintain validity.
        /// </summary>
        /// <param name="Point">Reflection point.</param>
        public override void Reflect(C2DPoint Point)
        {
            TopLeft.Reflect(Point);
            BottomRight.Reflect(Point);

            double x = TopLeft.x;
            double y = TopLeft.y;

            TopLeft.Set(BottomRight);
            BottomRight.x = x;
            BottomRight.y = y;
        }