minetest-mods / areas

A rewrite of the node_ownership Minetest mod with many new features.
GNU Lesser General Public License v2.1
51 stars 52 forks source link

There are 0 hard problems in computer science: off-by-1 errors #46

Open emorrp1 opened 4 years ago

emorrp1 commented 4 years ago

/area_info: "You can protect areas spanning up to 64x128x64." /list_areas: (-32,-64,-32) (32,64,32) markers:land_title_register: "It spans 65x65 = 4225 m^2. Height: 129 m."

Now, I can see how this might be deliberate to make mental maths easier, but one of those two statements is wrong - either the spanning is 65x129x65 (perhaps written as +/-32,+/-64,+/-32) or the protection should be one less.

FeXoR-o-Illuria commented 3 years ago

Not really since none of the statements is telling if it talks about coordinates(zero volume points)/distance between nodes(one node has 0 distance to itself) or nodes (with volume and width of 1). If /area info speaks about the distance between the node's centers in all directions and markers:land_title_register about the volume covered by all those nodes they can be both correct.

Example: An area with corner coordinates 0 0 0 to 1 1 1 contains only one node with center at 0.5 0.5 0.5 (Probably identified as node 000). But if node identifiers are meant those are 8 nodes (000, 001, 010, 011, 100, 101, 110, 111). The volume of those 8 nodes is 8 but the maximum distance from one node's center to the furthest away in each direction is still only 1 (1.5 - 0.5 = 1) so in terms of node identifiers it "spans" 1x1x1.

S-S-X commented 2 years ago

Protection size is always full nodes which should make this fairly simple... you cannot protect just single point, you have to protect full nodes.

FeXoR-o-Illuria commented 2 months ago

AFAIK the size of the area one can protect now is what /area_info states. (And one should no longer be able to protect the example area with the stated info text because that's one larger in each dimension) Too lazy to check for the commit though.