Position edits (#7)

* Moving annotations for vector classes and positions: `core_namespace.lua` -> `classes/vector.lua`. Rethinking position annotations

* Replacing float positions with integer positions where required (voxel manipulator, node coordinates, etc.). Adding missing annotations to the position parameters of core methods

* Fix position annotations in noises classes

* remove alias `MapPosition2d`

* Review fixes
This commit is contained in:
Van
2026-02-13 12:09:24 +03:00
committed by GitHub
parent e5a12d31ba
commit 5d3804168b
12 changed files with 160 additions and 94 deletions

View File

@@ -15,11 +15,11 @@
ValueNoise = {}
--- Returns 2D noise value at `pos={x=,y=}`
--- @param pos Position2d
--- @param pos IntegerPosition2d
--- @return number
function ValueNoise:get_2d(pos) end
--- Returns 3D noise value at `pos={x=,y=,z=}`
--- @param pos Position
--- @param pos IntegerPosition
--- @return number
function ValueNoise:get_3d(pos) end

View File

@@ -21,37 +21,37 @@ ValueNoiseMap = {}
--- Returns a `<size.x>` times `<size.y>` 2D array of 2D noise
--- with values starting at `pos={x=,y=}`
--- @param pos Position2d
--- @param pos IntegerPosition2d
--- @return table
function ValueNoiseMap:get_2d_map(pos) end
--- Returns a `<size.x>` times `<size.y>` times `<size.z>`
--- 3D array of 3D noise with values starting at `pos={x=,y=,z=}`
--- @param pos Position
--- @param pos IntegerPosition
--- @return table
function ValueNoiseMap:get_3d_map(pos) end
--- Returns a flat `<size.x * size.y>` element
--- array of 2D noise with values starting at `pos={x=,y=}`
--- @param pos Position2d
--- @param pos IntegerPosition2d
--- @param buffer table If `buffer` is not nil, this table will be used to store the result instead of creating a new table.
--- @return table
function ValueNoiseMap:get_2d_map_flat(pos, buffer) end
--- Same as `get2dMap_flat`, but 3D noise
--- @param pos Position
--- @param pos IntegerPosition
--- @param buffer table If `buffer` is not nil, this table will be used to store the result instead of creating a new table.
--- @return table
function ValueNoiseMap:get_3d_map_flat(pos, buffer) end
--- Calculates the 2d noise map starting at `pos`. The result
--- is stored internally.
--- @param pos Position2d
--- @param pos IntegerPosition2d
function ValueNoiseMap:calc_2d_map(pos) end
--- Calculates the 3d noise map starting at `pos`. The result
--- is stored internally.
--- @param pos Position
--- @param pos IntegerPosition
function ValueNoiseMap:calc_3d_map(pos) end
--- In the form of an array,
@@ -71,8 +71,8 @@ function ValueNoiseMap:calc_3d_map(pos) end
--- noise:calc_3d_map({x=1000, y=1000, z=1000})
--- noisevals = noise:get_map_slice({x=24, z=1}, {x=1, z=1})
--- ```
--- @param slice_offset {x:number?,y:number?,z:number?}
--- @param slice_size {x:number?,y:number?,z:number?}
--- @param slice_offset {x:integer?,y:integer?,z:integer?}
--- @param slice_size {x:integer?,y:integer?,z:integer?}
--- @param buffer table If `buffer` is not nil, this table will be used to store the result instead of creating a new table.
--- @return table
function ValueNoiseMap:get_map_slice(slice_offset, slice_size, buffer) end

View File

@@ -7,8 +7,8 @@
--- `VoxelArea:new({MinEdge = pmin, MaxEdge = pmax})`.
--- The coordinates are *inclusive*, like most other things in Luanti.
---
--- @field MinEdge Position
--- @field MaxEdge Position
--- @field MinEdge MapPosition
--- @field MaxEdge MapPosition
--- @field ystride integer
--- @field zstride integer
VoxelArea = {}
@@ -17,12 +17,12 @@ VoxelArea = {}
---
--- Also you can create an instance via `VoxelArea(pmin, pmax)`
---
--- @param cuboid { MinEdge: Position, MaxEdge: Position }
--- @param cuboid { MinEdge: MapPosition, MaxEdge: MapPosition }
--- @return VoxelArea
function VoxelArea:new(cuboid) end
--- returns a 3D vector containing the size of the area formed by `MinEdge` and `MaxEdge`.
--- @return Position
--- @return IntegerPosition
function VoxelArea:getExtent() end
--- returns the volume of the area formed by `MinEdge` and `MaxEdge`.
@@ -44,13 +44,13 @@ function VoxelArea:index(x, y, z) end
--- same functionality as `index(x, y, z)` but takes a vector.
--- * As with `index(x, y, z)`, the components of `p` must be integers, and `p`
--- is not checked for being inside the area volume.
--- @param position Position
--- @param position MapPosition
--- @return integer
function VoxelArea:indexp(position) end
--- returns the absolute position vector corresponding to index `i`.
--- @param i integer
--- @return Position
--- @return MapPosition
function VoxelArea:position(i) end
--- check if (`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`.
@@ -61,7 +61,7 @@ function VoxelArea:position(i) end
function VoxelArea:contains(x, y, z) end
--- check if Position(`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`.
--- @param position Position
--- @param position MapPosition
--- @return boolean
function VoxelArea:containsp(position) end
@@ -83,7 +83,7 @@ function VoxelArea:iter(min_x, min_y, min_z, max_x, max_y, max_z) end
--- returns an iterator that returns indices.
--- * from (`min_x`,`min_y`,`min_z`) to (`max_x`,`max_y`,`max_z`) in the order of `[z [y [x]]]`.
--- @param min_pos Position
--- @param max_pos Position
--- @param min_pos MapPosition
--- @param max_pos MapPosition
--- @return fun(tbl: table<integer, integer>): integer, integer
function VoxelArea:iterp(min_pos, max_pos) end

View File

@@ -6,9 +6,9 @@ VoxelManip = {}
--- Loads a chunk of map into the VoxelManip object containing the region formed by `p1` and `p2`.
--- * returns actual emerged `pmin`, actual emerged `pmax`
--- @param position1 Position min position for load part of map
--- @param position2 Position max position for load part of map
--- @return Position, Position
--- @param position1 MapPosition min position for load part of map
--- @param position2 MapPosition max position for load part of map
--- @return MapPosition, MapPosition
function VoxelManip:read_from_map(position1, position2) end
--- Writes the data loaded from the `VoxelManip` back to the map.
@@ -22,12 +22,12 @@ function VoxelManip:read_from_map(position1, position2) end
function VoxelManip:write_to_map(light) end
--- Returns a `MapNode` table of the node currently loaded in the `VoxelManip` at that position.
--- @param pos Position
--- @param pos MapPosition
--- @return MapNode
function VoxelManip:get_node_at(pos) end
--- Sets a specific `MapNode` in the `VoxelManip` at that position.
--- @param pos Position
--- @param pos MapPosition
--- @param node MapNode
function VoxelManip:set_node_at(pos, node) end
@@ -90,11 +90,11 @@ function VoxelManip:set_param2_data(param2_data) end
--- * `propagate_shadow` is an optional boolean deciding whether shadows in a
--- generated mapchunk above are propagated down into the mapchunk, defaults
--- to `true` if left out.
--- @overload fun(p1:Position, p2:Position)
--- @overload fun(p1:MapPosition, p2:MapPosition)
--- @overload fun(propagate_shadow:boolean)
--- @overload fun()
--- @param p1 Position
--- @param p2 Position
--- @param p1 MapPosition
--- @param p2 MapPosition
--- @param propagate_shadow boolean
function VoxelManip:calc_lighting(p1, p2, propagate_shadow) end
@@ -107,5 +107,5 @@ function VoxelManip:update_liquids() end
function VoxelManip:was_modified() end
--- Returns actual emerged minimum and maximum positions.
--- @return Position, Position
--- @return MapPosition, MapPosition
function VoxelManip:get_emerged_area() end

View File

@@ -1,5 +1,22 @@
--- @meta
--- @class Position
--- @field x number
--- @field y number
--- @field z number
--- @class IntegerPosition: Position
--- @field x integer
--- @field y integer
--- @field z integer
--- @class Position2d
--- @field x number
--- @field y number
--- @class IntegerPosition2d: Position2d
--- @field x integer
--- @field y integer
--- @class vector: Position
--- @operator eq : boolean
@@ -13,6 +30,21 @@
--- @field z number
vector = {}
--- Same as `vector`, but all fields are integers.
--- @class IntegerVector: vector
--- @operator eq : boolean
--- @operator unm : IntegerVector
--- @operator add(Position): IntegerVector
--- @operator sub(Position): IntegerVector
--- @operator mul(number) : IntegerVector
--- @operator div(number) : IntegerVector
--- @field x integer
--- @field y integer
--- @field z integer
--- @alias MapPosition IntegerPosition
--- @alias MapVector IntegerVector
--- @alias PositionVector IntegerVector
--- Creates a new vector `(a, b, c)`.
--- * Deprecated: `vector.new()` does the same as `vector.zero()` and