PolygonTileMapper
Summary
Section titled “Summary”Handles polygon-to-tile-offset conversion with testable, separated concerns.
This class extracts the complex polygon processing logic from CollisionMapper to enable better testing and separation of responsibilities.
Coordinate semantics - Tile addressing is center-based. For 16×16 tiles, the center is at +8,+8 from the tile origin. - Tests and runtime share “bottom-inclusive, top-exclusive” behavior on axis-aligned boundaries to avoid fencepost rows when a polygon edge lies exactly on a tile boundary.
Pipeline stages: 1. Transform polygon to world space and compute initial tile coverage 2. Apply trapezoid expansion heuristics for convex polygons when beneficial 3. Prune concave polygon fringes to remove unwanted overhangs 4. Filter tiles by minimum area overlap to remove slivers (with concave center-point check)
Methods
Section titled “Methods”static func compute_tile_offsets( polygon_node: CollisionPolygon2D, map: TileMapLayer ) -> Array[Vector2i]
Primary entry point for polygon-to-tile conversion (runtime optimized)
static func compute_tile_offsets_with_positioner( polygon_node: CollisionPolygon2D, map: TileMapLayer, positioner: Node2D ) -> Array[Vector2i]
Primary entry point with positioner reference for consistent positioning Uses positioner’s position as coordinate reference instead of polygon’s position
static func _compute_tile_offsets_internal( polygon_node: CollisionPolygon2D, map: TileMapLayer, center_tile: Vector2i ) -> Array[Vector2i]
Internal implementation shared by both public methods
static func process_polygon_with_diagnostics( polygon_node: CollisionPolygon2D, map: TileMapLayer ) -> ProcessingResult
Full processing with diagnostic information for testing and debugging
static func _analyze_offset_pattern( offsets: Array[Vector2i] ) -> Dictionary
Helper: Analyze offset pattern for trapezoid detection
static func _expansion_adds_new_tiles( original: Array[Vector2i], expanded: Array[Vector2i] ) -> bool
Helper: Check if expansion adds new tile coverage
static func _determine_area_threshold( is_convex: bool, did_expand: bool, thresholds: AreaThresholds ) -> float
Helper: Determine area threshold based on polygon type and processing
static func _compute_tile_rect( abs_tile: Vector2i, map: TileMapLayer, tile_size: Vector2 ) -> Rect2
Helper: Compute tile rectangle in world space
static func _transform_polygon_world( polygon_node: CollisionPolygon2D ) -> PackedVector2Array
World polygon conversion - delegates to utility
static func get_polygon_tile_overlap_area( polygon: PackedVector2Array, rect: Rect2 ) -> float
Polygon-tile overlap calculation using Sutherland-Hodgman clipping
static func _compute_polygon_bounds( polygon: PackedVector2Array ) -> Rect2
Helper: Compute polygon bounding rectangle
static func _clip_polygon_to_rect( polygon: PackedVector2Array, rect: Rect2 ) -> PackedVector2Array
Helper: Clip polygon against rectangle using Sutherland-Hodgman algorithm
static func _point_inside_boundary( point: Vector2, boundary: Dictionary ) -> bool
Helper: Test if point is inside clipping boundary
static func _compute_intersection( a: Vector2, b: Vector2, boundary: Dictionary ) -> Vector2
Helper: Compute line-boundary intersection
static func _compute_polygon_area( polygon: PackedVector2Array ) -> float
Helper: Compute polygon area using shoelace formula
Source
Section titled “Source”addons/grid_building/placement/manager/components/mapper/polygon_tile_mapper.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.