using System; using System.Collections.Generic; using Microsoft.Xna.Framework; namespace MonoGame.Extended.Tilemaps { /// /// Represents an open polyline (unclosed polygon) object in a tilemap. /// /// /// Polyline objects define a series of connected line segments and are /// typically used for paths or boundaries. /// public class TilemapPolylineObject : TilemapObject { /// /// Gets or sets the vertices of the polyline relative to the object's position. /// public Vector2[] Points { get; set; } /// /// Gets the vertices of the polyline in world coordinates. /// public IEnumerable WorldPoints { get { foreach (var point in Points) { yield return Position + point; } } } /// public override RectangleF Bounds { get { if (Points == null || Points.Length == 0) return new RectangleF(Position.X, Position.Y, 0, 0); // Calculate bounding box from all world points float minX = float.MaxValue; float minY = float.MaxValue; float maxX = float.MinValue; float maxY = float.MinValue; foreach (var worldPoint in WorldPoints) { minX = Math.Min(minX, worldPoint.X); minY = Math.Min(minY, worldPoint.Y); maxX = Math.Max(maxX, worldPoint.X); maxY = Math.Max(maxY, worldPoint.Y); } return new RectangleF(minX, minY, maxX - minX, maxY - minY); } } // NOTE: Will use BoundingPolygon2D (unclosed) /// /// Initializes a new instance of the class. /// /// The unique identifier for the object. /// The position of the object (origin point). /// The vertices of the polyline relative to the position. public TilemapPolylineObject(int id, Vector2 position, Vector2[] points) : base(id, position) { Points = points; } } }