Add optional name property to BoxBrush and normalize function

This commit is contained in:
2026-03-31 04:22:24 +02:00
parent e40949177b
commit 0040bcde35

View File

@@ -25,6 +25,7 @@ export type BoxBrushFaces = Record<BoxFaceId, BrushFace>;
export interface BoxBrush {
id: string;
kind: "box";
name?: string;
center: Vec3;
size: Vec3;
faces: BoxBrushFaces;
@@ -46,6 +47,15 @@ export const DEFAULT_BOX_BRUSH_SIZE: Vec3 = {
z: 2
};
export function normalizeBrushName(name: string | null | undefined): string | undefined {
if (name === undefined || name === null) {
return undefined;
}
const trimmedName = name.trim();
return trimmedName.length === 0 ? undefined : trimmedName;
}
function cloneVec3(vector: Vec3): Vec3 {
return {
x: vector.x,
@@ -144,7 +154,7 @@ export function createDefaultBoxBrushFaces(): BoxBrushFaces {
}
export function createBoxBrush(
overrides: Partial<Pick<BoxBrush, "id" | "center" | "size" | "faces" | "layerId" | "groupId">> = {}
overrides: Partial<Pick<BoxBrush, "id" | "name" | "center" | "size" | "faces" | "layerId" | "groupId">> = {}
): BoxBrush {
const center = cloneVec3(overrides.center ?? DEFAULT_BOX_BRUSH_CENTER);
const size = cloneVec3(overrides.size ?? DEFAULT_BOX_BRUSH_SIZE);
@@ -156,6 +166,7 @@ export function createBoxBrush(
return {
id: overrides.id ?? createOpaqueId("brush"),
kind: "box",
name: normalizeBrushName(overrides.name),
center,
size,
faces: overrides.faces === undefined ? createDefaultBoxBrushFaces() : cloneBoxBrushFaces(overrides.faces),