refactor(basetype): Add intersect and min/max functions to Region and Coord types - #3271
refactor(basetype): Add intersect and min/max functions to Region and Coord types#3271stephanmeesters wants to merge 2 commits into
Conversation
PR Summary by QodoAdd coordinate min/max and region intersection helpers
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can tweak Display preferences with a live preview to see your comment before it ships |
|
| Filename | Overview |
|---|---|
| Core/Libraries/Include/Lib/BaseType.h | Adds the shared coordinate and region operations; their behavior is straightforward, but the min/max names conflict with Windows macros in some consumers. |
| Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | Replaces explicit pathfinding-bound clamps with equivalent coordinate and region helper calls. |
| Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp | Replaces manual axis swaps with equivalent component-wise min/max normalization. |
Prompt To Fix All With AI
### Issue 1
Core/Libraries/Include/Lib/BaseType.h:335-349
**Windows macros break coordinate API**
The new public member names `min` and `max` collide with the function-like Windows macros in translation units such as WorldBuilder, whose precompiled header includes `BaseType.h` before `afxwin.h`. After MFC defines those macros, a call such as `coord.min(other)` is expanded as a malformed two-argument macro invocation and fails to compile. This makes these shared coordinate APIs unusable from that supported component. Please use macro-safe names or ensure `NOMINMAX` is consistently defined for all consumers. The same issue applies to the new `ICoord2D`, `Coord3D`, and `ICoord3D` methods.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "Apply new min, max, and intersect functi..." | Re-trigger Greptile
| void min( const Coord2D &other ) | ||
| { | ||
| if (x > other.x) | ||
| x = other.x; | ||
| if (y > other.y) | ||
| y = other.y; | ||
| } | ||
|
|
||
| void max( const Coord2D &other ) | ||
| { | ||
| if (x < other.x) | ||
| x = other.x; | ||
| if (y < other.y) | ||
| y = other.y; | ||
| } |
There was a problem hiding this comment.
Windows macros break coordinate API
The new public member names min and max collide with the function-like Windows macros in translation units such as WorldBuilder, whose precompiled header includes BaseType.h before afxwin.h. After MFC defines those macros, a call such as coord.min(other) is expanded as a malformed two-argument macro invocation and fails to compile. This makes these shared coordinate APIs unusable from that supported component. Please use macro-safe names or ensure NOMINMAX is consistently defined for all consumers. The same issue applies to the new ICoord2D, Coord3D, and ICoord3D methods.
Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/Libraries/Include/Lib/BaseType.h
Line: 335-349
Comment:
**Windows macros break coordinate API**
The new public member names `min` and `max` collide with the function-like Windows macros in translation units such as WorldBuilder, whose precompiled header includes `BaseType.h` before `afxwin.h`. After MFC defines those macros, a call such as `coord.min(other)` is expanded as a malformed two-argument macro invocation and fails to compile. This makes these shared coordinate APIs unusable from that supported component. Please use macro-safe names or ensure `NOMINMAX` is consistently defined for all consumers. The same issue applies to the new `ICoord2D`, `Coord3D`, and `ICoord3D` methods.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
NOMINMAX is set through WWLib\always.h
There was a problem hiding this comment.
That addresses the WorldBuilder case if WWLib/always.h is guaranteed to be included before any Windows/MFC header in its precompiled header. My concern only remains for other consumers of the shared BaseType.h that do not include always.h first, or include afxwin.h before it; those can still have min/max defined when calling coord.min(other). If the project guarantees that include order for every consumer, this comment can be dismissed.
Split off from #3245 where an intersect function was needed for
IRegion2D.In the current PR we implement
intersectfunctions forIRegion3D,IRegion2D,Region3DandRegion2D. For that purpose it also addsminandmaxto the Coords variants.In the second commit it replaces various usages with these new functions. Cases where the replacement was not straight-forward were skipped, some cases also looked more like a union operation so those were also skipped.
AI was used to implement this, every line was checked.