Opened 6 years ago

Last modified 6 years ago

#4845 closed defect

Simplify rmgen code with vector algebra — at Version 1

Reported by: elexis Owned by:
Priority: Should Have Milestone: Alpha 23
Component: Maps Keywords:
Cc: Patch:

Description (last modified by elexis)

In a number of locations in the rmgen library we have equations that are duplicated for each dimension and equations that are the result of vector algebra, but written in an obfuscated way.

By using the Vector2D operations, these functions can become both much shorter and have their geometric meaning expressed instead of the way these are computed.

Thus making it easier for new readers to comprehend and extend the given piece of code.

We should consider switching from X/Y Vectors to X/Z ones: #4834.

Change History (1)

comment:1 by elexis, 6 years ago

Description: modified (diff)

In r20428:
Add Vector3D crossproduct and Vector2D perpendicular function.
Describe geometric features of the two cross- and dot-product functions.

In r20429:

Extend the random map river algorithm (r20185) to allow arbitrary start and end points.

Reverse engineer and cleanup obfuscated Rivers map code, refs r11137.
Use vector algebra to replace magic equations and express geometric intend.
Fix seed typo by removing river curve duplicate.

On the Rivers map, use areAllies directly instead of copying the diplomacies to a 2D array called isRiver.
Use modulo operator instead of an if-statement with duplication to determine the neighbor of the last player, refs r11174.

In r20435:
Further clarify geometric meaning of the river painting in r11137 and r20429.
Refer to the normalized river vector instead of the river vector divided by the length of the river.
Rename mag to magnitude.

Note: See TracTickets for help on using tickets.