Skip to content

refactor(basetype): Add utility functions to Region and Coord types - #3271

Open
stephanmeesters wants to merge 17 commits into
TheSuperHackers:mainfrom
stephanmeesters:refactor/intersect-min-max
Open

refactor(basetype): Add utility functions to Region and Coord types#3271
stephanmeesters wants to merge 17 commits into
TheSuperHackers:mainfrom
stephanmeesters:refactor/intersect-min-max

Conversation

@stephanmeesters

@stephanmeesters stephanmeesters commented Sep 8, 2026

Copy link
Copy Markdown

Split off from #3245 where an intersect function was needed for IRegion2D.

In the current PR we implement

  • intersectWith and uniteWith functions for IRegion3D, IRegion2D, Region3D and Region2D
  • updateMin and updateMax functions for ICoord3D, ICoord2D, Coord3D and Coord2D
  • asCoord2D and asICoord2D functions for Coord3D and ICoord3D respectively.

AI was used to implement this, every line was checked.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add coordinate min/max and region intersection helpers

✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds component-wise min/max helpers to integer and floating-point 2D/3D coordinates.
• Adds mutating intersection operations to all 2D and 3D region variants.
• Replaces duplicated window and pathfinding bounds-clamping logic with shared helpers.
Diagram

classDiagram
  class Coord2D {
    +min(other)
    +max(other)
  }
  class ICoord2D {
    +min(other)
    +max(other)
  }
  class Region2D {
    +intersect(other)
  }
  class IRegion2D {
    +intersect(other)
  }
  class Coord3D {
    +min(other)
    +max(other)
  }
  class ICoord3D {
    +min(other)
    +max(other)
  }
  class Region3D {
    +intersect(other)
  }
  class IRegion3D {
    +intersect(other)
  }
  Region2D *-- Coord2D : bounds
  IRegion2D *-- ICoord2D : bounds
  Region3D *-- Coord3D : bounds
  IRegion3D *-- ICoord3D : bounds
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Non-mutating free functions
  • ➕ Make value transformation explicit at call sites
  • ➕ Allow source bounds to remain unchanged
  • ➕ Can return a new region suitable for expression composition
  • ➖ Require additional assignments or temporary objects
  • ➖ Do not match the existing mutable POD-style APIs
  • ➖ Produce greater call-site churn for this legacy codebase
2. Templated coordinate and region types
  • ➕ Eliminate duplication between integer and floating-point variants
  • ➕ Centralize dimension-independent min, max, and intersection behavior
  • ➖ Greatly expands the scope and compatibility risk
  • ➖ Could disrupt serialization, ABI assumptions, or legacy call sites
  • ➖ Provides limited immediate benefit for this focused refactor

Recommendation: Keep the PR's mutating member-function approach because it fits the existing region and coordinate design and cleanly replaces repeated clamping logic. A templated redesign could reduce duplication but should be a separate, compatibility-focused change; tests for overlapping and disjoint regions would strengthen the current approach.

Files changed (3) +106 / -76

Enhancement (1) +98 / -12
BaseType.hAdd coordinate min/max and region intersection APIs +98/-12

Add coordinate min/max and region intersection APIs

• Adds mutating component-wise 'min' and 'max' methods to all 2D and 3D integer and floating-point coordinate types. Adds 'intersect' to corresponding region types and reuses coordinate helpers when constructing 3D bounds from points.

Core/Libraries/Include/Lib/BaseType.h

Refactor (2) +8 / -64
GameWindow.cppNormalize window bounds with coordinate min/max helpers +3/-20

Normalize window bounds with coordinate min/max helpers

• Replaces manual axis-by-axis endpoint swapping with the new component-wise coordinate operations while preserving the original lower endpoint for the upper-bound calculation.

Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp

AIPathfind.cppUse shared bounds clipping in pathfinding +5/-44

Use shared bounds clipping in pathfinding

• Replaces repeated coordinate clamps with 'min' and region 'intersect' operations during zone calculation, zone modification, and object-footprint classification. This centralizes two-dimensional bounds clipping behavior.

Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can tweak Display preferences with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds reusable coordinate projection, component-wise bound updates, and region intersection/union helpers, then replaces equivalent manual coordinate and bounds operations throughout the engine and both game variants.

  • Adds asCoord2D/asICoord2D, updateMin/updateMax, and intersectWith/uniteWith helpers.
  • Refactors pathfinding, bridge, polygon, AI, prison-yard, rendering, and WorldBuilder calculations to use the helpers.
  • Renames the newly introduced integer-coordinate projection helper from getXY to asICoord2D and updates all callers.
  • The previous macro-collision thread is resolved; the current API uses updateMin and updateMax rather than member names min and max.

Confidence Score: 5/5

The PR appears safe to merge, with no outstanding correctness, security, or repository-rule issue identified.

The latest change only renames ICoord3D::getXY() to asICoord2D() and updates both existing callers; no stale calls remain, and the calls match the IRegion2D::uniteWith(const ICoord2D&) overload. The previous macro-collision finding was manually resolved and the implicated min/max member names are no longer present.

Important Files Changed

Filename Overview
Core/Libraries/Include/Lib/BaseType.h Introduces coordinate projection and component-wise region utility methods; the latest helper rename is consistently applied.
Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Replaces manual pathfinding-bound clipping and expansion with behaviorally equivalent region helpers.
Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp Uses the renamed integer-coordinate projection helper when accumulating polygon bounds.
GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp Mirrors the type-correct polygon-bound refactor for the Zero Hour variant.
Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp Consolidates bridge-bound and 3D-to-2D coordinate calculations through the new utilities.
GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp Applies the same bridge and coordinate refactoring to the Zero Hour implementation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    C3[Coord3D] -->|asCoord2D| C2[Coord2D]
    IC3[ICoord3D] -->|asICoord2D| IC2[ICoord2D]
    C2 -->|updateMin / updateMax| R2[Region2D operations]
    IC2 -->|updateMin / updateMax| IR2[IRegion2D operations]
    R2 -->|intersectWith / uniteWith| Users[Engine and tool call sites]
    IR2 -->|intersectWith / uniteWith| Users
Loading

Reviews (9): Last reviewed commit: "Rename getXY() in ICoord2D to asICoord2D..." | Re-trigger Greptile

Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
@stephanmeesters stephanmeesters added Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing Minor Severity: Minor < Major < Critical < Blocker labels Sep 8, 2026
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp Outdated
@stephanmeesters
stephanmeesters force-pushed the refactor/intersect-min-max branch from 99f6cda to b89757e Compare September 9, 2026 18:21

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ook

Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@stephanmeesters
stephanmeesters force-pushed the refactor/intersect-min-max branch from 49ff85a to 9bdddc3 Compare September 10, 2026 12:26
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp Outdated
@stephanmeesters stephanmeesters changed the title refactor(basetype): Add intersect and min/max functions to Region and Coord types refactor(basetype): Add utility functions to Region and Coord types Sep 10, 2026
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Core/Libraries/Include/Lib/BaseType.h
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants