Skip to content

worldedit selection helper function + improvements to error feedback#2825

Open
H41ogen wants to merge 1 commit intoPixelGuys:masterfrom
H41ogen:worldedit-positions
Open

worldedit selection helper function + improvements to error feedback#2825
H41ogen wants to merge 1 commit intoPixelGuys:masterfrom
H41ogen:worldedit-positions

Conversation

@H41ogen
Copy link
Copy Markdown
Contributor

@H41ogen H41ogen commented Apr 5, 2026

Closes #2816

@Wunka Wunka moved this to Low Priority in PRs to review Apr 6, 2026
}
};

pub fn getSelectionBounds(source: *User) error{PositionNotSet}![2]main.vec.Vec3i {
Copy link
Copy Markdown
Collaborator

@Argmaster Argmaster Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could just change variable names in caller, but that struct will automatically enforce consistent names in callers.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't need to min/max it - Blueprint.capture does that anyway no?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Add a helper function to get worldedit positions

4 participants