## #4845 closed defect (fixed)

# Simplify rmgen code with vector algebra

Reported by: | elexis | Owned by: | |
---|---|---|---|

Priority: | Should Have | Milestone: | Alpha 23 |

Component: | Maps | Keywords: | |

Cc: | Patch: |

## Description (last modified by )

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 (32)

### comment:1 by , 3 years ago

Description: | modified (diff) |
---|

### comment:2 by , 3 years ago

A really awesome property of the cross product is that it allows computation of things that in other ways do require division by zero checks (for instance the if-statements in `checkIfIntersect`

).

At first it looked like there are only few functions that would benefit from using Vectors (by using vector operations), however it seems the entire rmgen code should use Vectors to address x/z coordinates. (Rewriting everything again will be quick after #4805, #4804, #4831)

### comment:5 by , 3 years ago

Milestone: | Alpha 23 → Backlog |
---|---|

Status: | assigned → new |

### comment:22 by , 3 years ago

Milestone: | Backlog → Alpha 23 |
---|---|

Resolution: | → fixed |

Status: | new → closed |

Marking this as fixed since most of rmgen code uses vectors as of a23.

**Note:**See TracTickets for help on using tickets.

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.