| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using Microsoft.Xna.Framework;
- namespace MonoGame.Extended.Tilemaps
- {
- /// <summary>
- /// Represents an open polyline (unclosed polygon) object in a tilemap.
- /// </summary>
- /// <remarks>
- /// Polyline objects define a series of connected line segments and are
- /// typically used for paths or boundaries.
- /// </remarks>
- public class TilemapPolylineObject : TilemapObject
- {
- /// <summary>
- /// Gets or sets the vertices of the polyline relative to the object's position.
- /// </summary>
- public Vector2[] Points { get; set; }
- /// <summary>
- /// Gets the vertices of the polyline in world coordinates.
- /// </summary>
- public IEnumerable<Vector2> WorldPoints
- {
- get
- {
- foreach (var point in Points)
- {
- yield return Position + point;
- }
- }
- }
- /// <inheritdoc/>
- 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)
- /// <summary>
- /// Initializes a new instance of the <see cref="TilemapPolylineObject"/> class.
- /// </summary>
- /// <param name="id">The unique identifier for the object.</param>
- /// <param name="position">The position of the object (origin point).</param>
- /// <param name="points">The vertices of the polyline relative to the position.</param>
- public TilemapPolylineObject(int id, Vector2 position, Vector2[] points) : base(id, position)
- {
- Points = points;
- }
- }
- }
|