It's not clear from this snippet what are `getPolygon()` and
`LevelObjectEntity` really are and what they do.
But idiomatic code would look something like this:
type
Vertex* = tuple[x, y: int32]
Polygon* = object of RootObj
vertices*: seq[Vertex]
fill*: LCDPattern
proc loadPolygon(level: Level, obj: var LevelObjectEntity): bool =
let objOffset: Vertex = (obj.x, obj.y) # tuple instead of array
var polygon: Polygon = obj.getPolygon()
let lastIndex = polygon.vertices.high
if lastIndex < 2:
return false # polygons require at least 3 vertices
for vertex in polygon.vertices.mItems:
vertex += objOffset # or `vertex = vertex + objOffset`
Run
1\. `var` argument modifier makes obj mutable (passes the pointer to it
internally). If `LevelObjectEntity` is already a ref/ptr type - then `var` is
optional, but it still shows your intention to modify the object.
2. `mItems()` \- Iterates over each item of collection so that you can modify
the yielded value.
3. nitpick: `Vertex` could be a `tuple[x, y: int32]`, so you could use `v.x`
in addition to `v[0]`