Базовая модель готова
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const basic_models = @import("basic_models.zig");
|
const basic_models = @import("basic_models.zig");
|
||||||
const properties = @import("Property.zig");
|
|
||||||
const Property = properties.Property;
|
|
||||||
const PropertyData = properties.Data;
|
|
||||||
const Point2 = basic_models.Point2;
|
|
||||||
const Size = basic_models.Size;
|
const Size = basic_models.Size;
|
||||||
const Object = @import("Object.zig");
|
|
||||||
const Document = @This();
|
const Document = @This();
|
||||||
|
|
||||||
|
pub const Object = @import("Object.zig");
|
||||||
|
|
||||||
size: Size,
|
size: Size,
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
objects: std.ArrayList(Object),
|
objects: std.ArrayList(Object),
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const basic_models = @import("basic_models.zig");
|
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 Property = @import("Property.zig").Property;
|
||||||
const PropertyData = @import("Property.zig").Data;
|
const PropertyData = @import("Property.zig").Data;
|
||||||
const Point2 = basic_models.Point2;
|
const defaultCommonProperties = @import("Property.zig").defaultCommonProperties;
|
||||||
const Size = basic_models.Size;
|
|
||||||
const Object = @This();
|
const Object = @This();
|
||||||
|
|
||||||
pub const ShapeKind = enum {
|
pub const ShapeKind = enum {
|
||||||
@@ -70,11 +70,10 @@ pub fn deinit(self: *Object, allocator: std.mem.Allocator) void {
|
|||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createWithCommon(allocator: std.mem.Allocator, shape: ShapeKind) !Object {
|
fn createWithCommonProperties(allocator: std.mem.Allocator, shape: ShapeKind) !Object {
|
||||||
const common = defaultCommonProperties();
|
|
||||||
var properties_list = std.ArrayList(Property).empty;
|
var properties_list = std.ArrayList(Property).empty;
|
||||||
errdefer properties_list.deinit(allocator);
|
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 .{
|
return .{
|
||||||
.shape = shape,
|
.shape = shape,
|
||||||
.properties = properties_list,
|
.properties = properties_list,
|
||||||
@@ -83,28 +82,28 @@ fn createWithCommon(allocator: std.mem.Allocator, shape: ShapeKind) !Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn createRect(allocator: std.mem.Allocator) !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);
|
errdefer obj.deinit(allocator);
|
||||||
try obj.properties.append(allocator, .{ .data = .{ .size = .{ .width = 100, .height = 100 } } });
|
try obj.properties.append(allocator, .{ .data = .{ .size = .{ .width = 100, .height = 100 } } });
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createEllipse(allocator: std.mem.Allocator) !Object {
|
pub fn createEllipse(allocator: std.mem.Allocator) !Object {
|
||||||
var obj = try createWithCommon(allocator, .ellipse);
|
var obj = try createWithCommonProperties(allocator, .ellipse);
|
||||||
errdefer obj.deinit(allocator);
|
errdefer obj.deinit(allocator);
|
||||||
try obj.properties.append(allocator, .{ .data = .{ .radii = .{ .x = 50, .y = 50 } } });
|
try obj.properties.append(allocator, .{ .data = .{ .radii = .{ .x = 50, .y = 50 } } });
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createLine(allocator: std.mem.Allocator) !Object {
|
pub fn createLine(allocator: std.mem.Allocator) !Object {
|
||||||
var obj = try createWithCommon(allocator, .line);
|
var obj = try createWithCommonProperties(allocator, .line);
|
||||||
errdefer obj.deinit(allocator);
|
errdefer obj.deinit(allocator);
|
||||||
try obj.properties.append(allocator, .{ .data = .{ .end_point = .{ .x = 100, .y = 0 } } });
|
try obj.properties.append(allocator, .{ .data = .{ .end_point = .{ .x = 100, .y = 0 } } });
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createBrokenLine(allocator: std.mem.Allocator) !Object {
|
pub fn createBrokenLine(allocator: std.mem.Allocator) !Object {
|
||||||
var obj = try createWithCommon(allocator, .broken);
|
var obj = try createWithCommonProperties(allocator, .broken);
|
||||||
errdefer obj.deinit(allocator);
|
errdefer obj.deinit(allocator);
|
||||||
var points = std.ArrayList(Point2).init(allocator);
|
var points = std.ArrayList(Point2).init(allocator);
|
||||||
try points.appendSlice(allocator, &.{
|
try points.appendSlice(allocator, &.{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ pub const Property = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const default_common_data: []const Data = .{
|
const default_common_data = [_]Data{
|
||||||
.{ .position = .{ .x = 0, .y = 0 } },
|
.{ .position = .{ .x = 0, .y = 0 } },
|
||||||
.{ .angle = 0 },
|
.{ .angle = 0 },
|
||||||
.{ .scale = .{ .scale_x = 1, .scale_y = 1 } },
|
.{ .scale = .{ .scale_x = 1, .scale_y = 1 } },
|
||||||
@@ -55,9 +55,13 @@ const default_common_data: []const Data = .{
|
|||||||
.{ .locked = false },
|
.{ .locked = false },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn defaultCommonProperties() []const Data {
|
pub const defaultCommonProperties: [default_common_data.len]Property = blk: {
|
||||||
return &default_common_data;
|
var result: [default_common_data.len]Property = undefined;
|
||||||
}
|
for (default_common_data, &result) |d, *p| {
|
||||||
|
p.* = .{ .data = d };
|
||||||
|
}
|
||||||
|
break :blk result;
|
||||||
|
};
|
||||||
|
|
||||||
test "Property wrapper and Data" {
|
test "Property wrapper and Data" {
|
||||||
const p = Property{ .data = .{ .opacity = 0.5 } };
|
const p = Property{ .data = .{ .opacity = 0.5 } };
|
||||||
@@ -66,8 +70,8 @@ test "Property wrapper and Data" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "common properties" {
|
test "common properties" {
|
||||||
const common = defaultCommonProperties();
|
try std.testing.expect(defaultCommonProperties[0].data == .position);
|
||||||
try std.testing.expect(common[0] == .position);
|
try std.testing.expect(defaultCommonProperties[0].data.position.x == 0);
|
||||||
try std.testing.expect(common[0].position.x == 0);
|
try std.testing.expect(defaultCommonProperties[3].data == .visible);
|
||||||
try std.testing.expect(common[2].visible == true);
|
try std.testing.expect(defaultCommonProperties[3].data.visible == true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
// Test root for `zig build test`.
|
// Корень для `zig build test`. Тесты из импортированных здесь модулей выполняются (в Zig не подтягиваются из транзитивных импортов).
|
||||||
// Import modules here to ensure their `test` blocks are discovered.
|
// Добавляй сюда _ = @import("path/to/module.zig"); для каждого модуля с test-блоками.
|
||||||
|
// Чтобы увидеть список всех тестов: после `zig build test` выполни `./zig-out/bin/test`.
|
||||||
test "module test discovery" {
|
test "discover tests" {
|
||||||
_ = @import("render/CpuRenderEngine.zig");
|
_ = @import("main.zig");
|
||||||
|
_ = @import("models/Property.zig");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Убедиться, что выполнились все ожидаемые тесты: этот тест пройдёт только если до него дошли (т.е. все предыдущие прошли).
|
||||||
|
test "all module tests completed" {
|
||||||
|
const std = @import("std");
|
||||||
|
std.debug.print("\n (все тесты модулей выполнены)\n", .{});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user