worldedit selection helper function + improvements to error feedback#2825
worldedit selection helper function + improvements to error feedback#2825H41ogen wants to merge 1 commit intoPixelGuys:masterfrom
Conversation
| } | ||
| }; | ||
|
|
||
| pub fn getSelectionBounds(source: *User) error{PositionNotSet}![2]main.vec.Vec3i { |
There was a problem hiding this comment.
I would prefer to return a struct here instead of a vector to keep things explicit:
const Selection = struct {
minPos: Vec3i,
maxPos: Vec3i,
}Its a bit silly, but I think we should distinguish between that arbitrary pos1/pos2 and the normalized min/max positions.
There was a problem hiding this comment.
Alternatively we could just change variable names in caller, but that struct will automatically enforce consistent names in callers.
There was a problem hiding this comment.
Actually we don't need to min/max it - Blueprint.capture does that anyway no?
There was a problem hiding this comment.
I would like this interface improved anyway tho; its a little bit out of scope, but it would be nice to change Blueprint.capture to accept Selection that has fn init(pos1, pos2) and that init min/maxes the positions.
src/blueprint.zig:77
pub fn capture(allocator: NeverFailingAllocator, selection: Selection) CaptureResult {Selection struct should be placed inside blueprint.zig
const Selection = struct {
minPos: Vec3i,
maxPos: Vec3i,
fn init(pos1, pos2) Selection {
...
}
}Then we can remove min/max-ing from capture
/// Remove:
const startX = @min(pos1[0], pos2[0]);
const startY = @min(pos1[1], pos2[1]);
const startZ = @min(pos1[2], pos2[2]);
const endX = @max(pos1[0], pos2[0]);
const endY = @max(pos1[1], pos2[1]);
const endZ = @max(pos1[2], pos2[2]);And just go
const startX, const startY, const startZ = selection.minPos;
const endX , const endY , const endZ = selection.maxPos;We can also add fn size to Selection and remove it from capture body (src/blueprint.zig:86)
IntegratedQuantum
left a comment
There was a problem hiding this comment.
I agree with @Argmaster: This should be a struct with min and max for better readability.
You don't need to do all the interface changes he suggested here, but at least the newly introduced function should return a struct.
Closes #2816