Refactor: Перенёс логику создания фигур
Я перенёс логику создания объектов фигур из `Document.zig` и `Object.zig` в новый модуль `shape.zig`. Это упрощает добавление новых фигур и улучшает организацию кода.
This commit is contained in:
@@ -4,6 +4,7 @@ const Size = basic_models.Size;
|
||||
const Document = @This();
|
||||
|
||||
pub const Object = @import("Object.zig");
|
||||
const shape = @import("shape.zig");
|
||||
|
||||
size: Size,
|
||||
allocator: std.mem.Allocator,
|
||||
@@ -27,13 +28,8 @@ pub fn addObject(self: *Document, template: Object) !void {
|
||||
try self.objects.append(self.allocator, obj);
|
||||
}
|
||||
|
||||
pub fn addShape(self: *Document, parent: ?*Object, shape: Object.ShapeKind) !void {
|
||||
const obj = switch (shape) {
|
||||
.line => try Object.createLine(self.allocator),
|
||||
.ellipse => try Object.createEllipse(self.allocator),
|
||||
.broken => try Object.createBrokenLine(self.allocator),
|
||||
.arc => return error.ArcNotImplemented,
|
||||
};
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user