38 lines
1.4 KiB
Zig
38 lines
1.4 KiB
Zig
const std = @import("std");
|
|
const Object = @import("../Object.zig");
|
|
const Property = @import("../Property.zig").Property;
|
|
const PropertyData = @import("../Property.zig").Data;
|
|
const Rect_f = @import("../basic_models.zig").Rect_f;
|
|
const shape_mod = @import("shape.zig");
|
|
|
|
/// Свойства фигуры по умолчанию.
|
|
pub const default_shape_properties = [_]Property{
|
|
.{ .data = .{ .end_point = .{ .x = 100, .y = 200 } } },
|
|
};
|
|
|
|
/// Теги обязательных свойств.
|
|
pub fn getRequiredTags() []const std.meta.Tag(PropertyData) {
|
|
return &([_]std.meta.Tag(PropertyData){std.meta.activeTag(default_shape_properties[0].data)});
|
|
}
|
|
|
|
/// Добавляет к объекту свойства по умолчанию для линии.
|
|
pub fn appendDefaultShapeProperties(allocator: std.mem.Allocator, obj: *Object) !void {
|
|
for (default_shape_properties) |prop| try obj.properties.append(allocator, prop);
|
|
}
|
|
|
|
/// Локальные границы: от (0,0) до end_point.
|
|
pub fn getLocalBounds(obj: *const Object) !Rect_f {
|
|
try shape_mod.ensure(obj, .line);
|
|
const ep = obj.getProperty(.end_point).?;
|
|
const min_x = @min(0, ep.end_point.x);
|
|
const max_x = @max(0, ep.end_point.x);
|
|
const min_y = @min(0, ep.end_point.y);
|
|
const max_y = @max(0, ep.end_point.y);
|
|
return .{
|
|
.x = min_x,
|
|
.y = min_y,
|
|
.w = max_x - min_x,
|
|
.h = max_y - min_y,
|
|
};
|
|
}
|