const std = @import("std"); const basic_models = @import("basic_models.zig"); const Size_f = basic_models.Size_f; const Document = @This(); pub const Object = @import("Object.zig"); const shape = @import("shape/shape.zig"); size: Size_f, allocator: std.mem.Allocator, objects: std.ArrayList(Object), pub fn init(allocator: std.mem.Allocator, size: Size_f) Document { return .{ .size = size, .allocator = allocator, .objects = std.ArrayList(Object).empty, }; } pub fn deinit(self: *Document) void { for (self.objects.items) |*obj| obj.deinit(self.allocator); self.objects.deinit(self.allocator); } pub fn addObject(self: *Document, template: Object) !void { const obj = try template.clone(self.allocator); try self.objects.append(self.allocator, obj); } pub fn addShape(self: *Document, parent: ?*Object, shape_kind: Object.ShapeKind) !void { const obj = try shape.createObject(self.allocator, shape_kind); if (parent) |p| { try p.addChild(self.allocator, obj); } else { try self.addObject(obj); } }