sbrl / Minetest-WorldEditAdditions

Extra tools and commands to extend WorldEdit for Minetest
https://worldeditadditions.mooncarrot.space/
Mozilla Public License 2.0
16 stars 3 forks source link

//line enhancements #35

Open VorTechnix opened 3 years ago

VorTechnix commented 3 years ago

Ok here goes:

2d lines

2021-01-16 17_17_34-Minetest 5 3 0  OpenGL 4 6 0 The red line is how //line currently behaves when radius is 1. The green line is how it should behave when radius is 1.

That said instead of having a single radius we should have the option to input separate width and vertical thickness values. The new syntax would be: //line <replacenode> <thickness> [<width>].

Further the line creation process should be made iterative based on the central line. The yellow line in the screenshot would be and example of the result of //line <node> 2 1

3d lines

2021-01-16 17_39_31-Minetest 5 3 0  OpenGL 4 6 0 The only suggestion that I have for this is to look into the idea of having an option to make a staggered line (like the one in yellow) optimized for laying minecart track. This would probably be complicated though so it shouldn't be high priority.

sbrl commented 3 years ago

Hrm, this looks tricky. I agree that some improvements are in order, but someone would need to dive into the maths on this.

Currently it checks each node in the defined region, and if the distance from the node to the line is less than <thickness> it set it to <replace_node>.

VorTechnix commented 2 years ago

As per conversation on discord: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

sbrl commented 1 year ago

Ok, just implemented Bresenham's algorithm in 2D! There is another one called DDA, but it's less efficient as it requires floating-point calculations.

Now, we just need to implement it in 3d.... I suspect I'll probably cheese it by running it twice for X/Y and Z/Y, though the 2 different runs will have different numbers of elements in them, so some projection will be needed..... I'll figure it out. Eventually.

Note that an arbitrary thickness of the line requires a modification of the algorithm.

Here's a sample output with some random lines:

Selection_2022-09-17_23:19:58_001_492d157

VorTechnix commented 1 year ago

Now, we just need to implement it in 3d.... I suspect I'll probably cheese it by running it twice for X/Y and Z/Y

I would do the calculations for X/Z, put them in a table A and then run the calculations again for A/Y.

Note that an arbitrary thickness of the line requires a modification of the algorithm.

Why? Why not just run it once and then for each node just create a solid circle around it of [radius] facing roughly in the same direction as the line?

sbrl commented 1 year ago

3d implementation we might be able to copy: http://members.chello.at/easyfilter/bresenham.html

Why? Why not just run it once and then for each node just create a solid circle around it of [radius] facing roughly in the same direction as the line?

Then we'd need to implement a Bresenham circle or something as well haha

This is not out of the question, but implementing these upgrades will have to wait some more I think. I currently have other priorities in WorldEditAdditions. Maybe after the next release?