Базовая модель готова

This commit is contained in:
2026-02-23 23:37:02 +03:00
parent bd58286c98
commit dd9d5deb92
4 changed files with 35 additions and 28 deletions

View File

@@ -1,10 +1,10 @@
const std = @import("std");
const basic_models = @import("basic_models.zig");
const defaultCommonProperties = @import("Property.zig").defaultCommonProperties;
const Size = basic_models.Size;
const Point2 = basic_models.Point2;
const Property = @import("Property.zig").Property;
const PropertyData = @import("Property.zig").Data;
const Point2 = basic_models.Point2;
const Size = basic_models.Size;
const defaultCommonProperties = @import("Property.zig").defaultCommonProperties;
const Object = @This();
pub const ShapeKind = enum {
@@ -70,11 +70,10 @@ pub fn deinit(self: *Object, allocator: std.mem.Allocator) void {
self.* = undefined;
}
fn createWithCommon(allocator: std.mem.Allocator, shape: ShapeKind) !Object {
const common = defaultCommonProperties();
fn createWithCommonProperties(allocator: std.mem.Allocator, shape: ShapeKind) !Object {
var properties_list = std.ArrayList(Property).empty;
errdefer properties_list.deinit(allocator);
for (common) |d| try properties_list.append(allocator, .{ .data = d });
for (defaultCommonProperties) |prop| try properties_list.append(allocator, prop);
return .{
.shape = shape,
.properties = properties_list,
@@ -83,28 +82,28 @@ fn createWithCommon(allocator: std.mem.Allocator, shape: ShapeKind) !Object {
}
pub fn createRect(allocator: std.mem.Allocator) !Object {
var obj = try createWithCommon(allocator, .rect);
var obj = try createWithCommonProperties(allocator, .rect);
errdefer obj.deinit(allocator);
try obj.properties.append(allocator, .{ .data = .{ .size = .{ .width = 100, .height = 100 } } });
return obj;
}
pub fn createEllipse(allocator: std.mem.Allocator) !Object {
var obj = try createWithCommon(allocator, .ellipse);
var obj = try createWithCommonProperties(allocator, .ellipse);
errdefer obj.deinit(allocator);
try obj.properties.append(allocator, .{ .data = .{ .radii = .{ .x = 50, .y = 50 } } });
return obj;
}
pub fn createLine(allocator: std.mem.Allocator) !Object {
var obj = try createWithCommon(allocator, .line);
var obj = try createWithCommonProperties(allocator, .line);
errdefer obj.deinit(allocator);
try obj.properties.append(allocator, .{ .data = .{ .end_point = .{ .x = 100, .y = 0 } } });
return obj;
}
pub fn createBrokenLine(allocator: std.mem.Allocator) !Object {
var obj = try createWithCommon(allocator, .broken);
var obj = try createWithCommonProperties(allocator, .broken);
errdefer obj.deinit(allocator);
var points = std.ArrayList(Point2).init(allocator);
try points.appendSlice(allocator, &.{