21 lines
467 B
Zig
21 lines
467 B
Zig
const std = @import("std");
|
|
|
|
const Position = @This();
|
|
|
|
x: f32,
|
|
y: f32,
|
|
|
|
pub fn parseCommaDelimited(str: []const u8) !Position {
|
|
const comma_index = std.mem.indexOfScalar(u8, str, ',') orelse return error.MissingComma;
|
|
const x_str = str[0..comma_index];
|
|
const y_str = str[(comma_index+1)..];
|
|
|
|
const x = try std.fmt.parseFloat(f32, x_str);
|
|
const y = try std.fmt.parseFloat(f32, y_str);
|
|
|
|
return Position{
|
|
.x = x,
|
|
.y = y
|
|
};
|
|
}
|