Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

const lib_module = &lib.root_module;
const lib_module = lib.root_module;

_ = b.addModule("zigplotlib", .{
.root_source_file = b.path("src/root.zig"),
Expand Down
7 changes: 4 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.{
.name = "zigplotlib",
.version = "0.1.4",
.minimum_zig_version = "0.13.0",
.name = .zigplotlib,
.version = "0.1.5",
.fingerprint = 0x1220c9f9f0e0ce2a,
.minimum_zig_version = "0.14.0",
.dependencies = .{},

.paths = .{
Expand Down
4 changes: 2 additions & 2 deletions example/scatter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn main() !void {
defer _ = gpa.deinit();
const allocator = gpa.allocator();

var xoshiro = std.rand.Xoshiro256.init(100);
var xoshiro = std.Random.Xoshiro256.init(100);
var rand = xoshiro.random();

var x: [28]f32 = undefined;
Expand Down Expand Up @@ -65,4 +65,4 @@ pub fn main() !void {
defer file.close();

try svg.writeTo(file.writer());
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The Zig Plot Lib is a library for plotting data in Zig. It is designed to be eas

**Note:** This library is still in development and is not yet ready for production use.

I'm developping this library with version 0.13.0.
I'm developping this library with version 0.14.1.

## Installation
You can install the library by adding it to the `build.zig.zon` file, either manually like so:
Expand Down
24 changes: 12 additions & 12 deletions src/core/intf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ fn checkFunctionImplementation(
const Function = Field.type;
const function = @typeInfo(Function);

if (function != .Fn) @compileError("The Interface should only contains functions (as field)");
if (function.Fn.is_generic) @compileError("Generic functions are not supported!");
if (function.Fn.is_var_args) @compileError("Variadic functions are not supported!");
if (function != .@"fn") @compileError("The Interface should only contains functions (as field)");
if (function.@"fn".is_generic) @compileError("Generic functions are not supported!");
if (function.@"fn".is_var_args) @compileError("Variadic functions are not supported!");

const actual = @typeInfo(Actual);
if (actual != .Struct) @compileError(comptimePrint("'{s}' should be a struct that implements '{s}'", .{
if (actual != .@"struct") @compileError(comptimePrint("'{s}' should be a struct that implements '{s}'", .{
@typeName(Actual),
@typeName(Interface),
}));

inline for (actual.Struct.decls) |decl| {
inline for (actual.@"struct".decls) |decl| {
if (comptime std.mem.eql(u8, decl.name, Field.name)) {
const decl_ = @field(Actual, decl.name);
const Decl = @TypeOf(decl_);
const decl_info = @typeInfo(Decl);

if (decl_info != .Fn) @compileError(comptimePrint("Invalid Type for '{s}', should be {s}", .{
if (decl_info != .@"fn") @compileError(comptimePrint("Invalid Type for '{s}', should be {s}", .{
Field.name,
@typeName(Function),
}));
if (decl_info.Fn.is_generic or decl_info.Fn.is_var_args) @compileError(comptimePrint("Invalid Type for '{s}', should be {s}", .{
if (decl_info.@"fn".is_generic or decl_info.@"fn".is_var_args) @compileError(comptimePrint("Invalid Type for '{s}', should be {s}", .{
Field.name,
@typeName(Function),
}));

inline for (function.Fn.params, decl_info.Fn.params, 0..) |expected_param, actual_param, i| {
inline for (function.@"fn".params, decl_info.@"fn".params, 0..) |expected_param, actual_param, i| {
if (i == 0) {
if (expected_param.type == *const anyopaque) {
if (actual_param.type != *const Actual) @compileError(comptimePrint("'self' (the 1st argument) should be of type '*const {s}'\nDefinition for '{s}':\n{s}", .{
Expand Down Expand Up @@ -66,7 +66,7 @@ fn checkFunctionImplementation(
}));
}

if (function.Fn.return_type != decl_info.Fn.return_type) @compileError(comptimePrint("Invalid return type for '{s}', should be {s}\nDefinition for '{s}':\n{s}", .{
if (function.@"fn".return_type != decl_info.@"fn".return_type) @compileError(comptimePrint("Invalid return type for '{s}', should be {s}\nDefinition for '{s}':\n{s}", .{
Field.name,
@typeName(Function),
Field.name,
Expand All @@ -93,9 +93,9 @@ pub fn ensureImplement(
) void {
const interface = @typeInfo(Interface);

if (interface != .Struct) @compileError("The Interface should be a struct containing the functions as fields");
if (interface != .@"struct") @compileError("The Interface should be a struct containing the functions as fields");

inline for (interface.Struct.fields) |field| {
inline for (interface.@"struct".fields) |field| {
checkFunctionImplementation(Interface, field, Actual);
}
}
}
5 changes: 3 additions & 2 deletions src/svg/SVG.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const File = std.fs.File;

pub const Line = @import("Line.zig");
pub const Rect = @import("Rect.zig");
Expand Down Expand Up @@ -81,15 +82,15 @@ pub fn addPath(self: *SVG, options: Path.Options) !void {
}

/// The header of the SVG
const SVG_HEADER =
const SVG_HEADER: []const u8 =
\\<?xml version="1.0" encoding="UTF-8" standalone="no"?>
\\<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
\\<svg width="{d}" height="{d}" viewBox="{d} {d} {d} {d}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
\\
;

/// Write the SVG to the given writer
pub fn writeTo(self: *const SVG, writer: anytype) anyerror!void {
pub fn writeTo(self: *const SVG, writer: File.Writer) anyerror!void {
// Write the header
try writer.print(SVG_HEADER, .{
self.width,
Expand Down
4 changes: 2 additions & 2 deletions src/util/range.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn Range(comptime T: type) type {

/// Initialize a range with the minimum and maximum values set to the same value. [-∞; ∞]
pub fn inf() Self {
if (@typeInfo(T) != .Float) @compileError("Only floating point types can have infinite ranges");
if (@typeInfo(T) != .float) @compileError("Only floating point types can have infinite ranges");

return Self{
.min = -std.math.inf(T),
Expand All @@ -28,7 +28,7 @@ pub fn Range(comptime T: type) type {

/// Initialize a range with the minimum and maximum values set to the same value. [∞; -∞]
pub fn invInf() Self {
if (@typeInfo(T) != .Float) @compileError("Only floating point types can have infinite ranges");
if (@typeInfo(T) != .float) @compileError("Only floating point types can have infinite ranges");

return Self{
.min = std.math.inf(T),
Expand Down