Skip to content

Commit

Permalink
all: update @Fabs to @abs and fix one type error (#38)
Browse files Browse the repository at this point in the history
* fabs to abs
  • Loading branch information
jeremy-coleman authored Oct 11, 2023
1 parent f79ae39 commit 5e80883
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/algorithms/brezenham.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn process(start: [2]f32, end: [2]f32) ![][2]f32 {
var x2 = end[0];
var y2 = end[1];

const steep = @fabs(y2 - y1) > @fabs(x2 - x1);
const steep = @abs(y2 - y1) > @abs(x2 - x1);
if (steep) {
std.mem.swap(f32, &x1, &y1);
std.mem.swap(f32, &x2, &y2);
Expand All @@ -21,7 +21,7 @@ pub fn process(start: [2]f32, end: [2]f32) ![][2]f32 {
}

const dx: f32 = x2 - x1;
const dy: f32 = @fabs(y2 - y1);
const dy: f32 = @abs(y2 - y1);

var err: f32 = dx / 2.0;
var ystep: i32 = if (y1 < y2) 1 else -1;
Expand Down
8 changes: 4 additions & 4 deletions src/deps/zig-gamedev/zmath/src/zmath.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ pub inline fn sqrt(v: anytype) @TypeOf(v) {
}

pub inline fn abs(v: anytype) @TypeOf(v) {
return @fabs(v); // load, andps
return @abs(v); // load, andps
}

pub inline fn select(mask: anytype, v0: anytype, v1: anytype) @TypeOf(v0, v1) {
Expand Down Expand Up @@ -3612,7 +3612,7 @@ test "zmath.sincos32" {
}

fn asin32(v: f32) f32 {
const x = @fabs(v);
const x = @abs(v);
var omx = 1.0 - x;
if (omx < 0.0) {
omx = 0.0;
Expand Down Expand Up @@ -3666,7 +3666,7 @@ test "zmath.asin32" {
}

fn acos32(v: f32) f32 {
const x = @fabs(v);
const x = @abs(v);
var omx = 1.0 - x;
if (omx < 0.0) {
omx = 0.0;
Expand Down Expand Up @@ -3721,7 +3721,7 @@ test "zmath.acos32" {

pub fn modAngle32(in_angle: f32) f32 {
const angle = in_angle + math.pi;
var temp: f32 = @fabs(angle);
var temp: f32 = @abs(angle);
temp = temp - (2.0 * math.pi * @as(f32, @floatFromInt(@as(i32, @intFromFloat(temp / math.pi)))));
temp = temp - math.pi;
if (angle < 0.0) {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/artboard/flipbook/canvas.zig
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn draw(file: *pixi.storage.Internal.Pixi) void {
const src_x = column * tile_width;
const src_y = row * tile_height;

const sprite_scale = std.math.clamp(0.5 / @fabs(@as(f32, @floatFromInt(i)) + (file.flipbook_scroll / tile_width / 1.1)), 0.5, 1.0);
const sprite_scale = std.math.clamp(0.5 / @abs(@as(f32, @floatFromInt(i)) + (file.flipbook_scroll / tile_width / 1.1)), 0.5, 1.0);
const src_rect: [4]f32 = .{ src_x, src_y, tile_width, tile_height };
var dst_x: f32 = canvas_center_offset[0] + file.flipbook_scroll + @as(f32, @floatFromInt(i)) * tile_width * 1.1 - (tile_width * sprite_scale / 2.0);
var dst_y: f32 = canvas_center_offset[1] + ((1.0 - sprite_scale) * (tile_height / 2.0));
Expand Down
2 changes: 1 addition & 1 deletion src/editor/explorer/tools.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn draw() void {
pixi.state.colors.height = @as(u8, @intCast(std.math.clamp(height, 0, 255)));
}
} else {
var primary: [4]f32 = if (pixi.state.tools.current == .heightmap) .{} else .{
var primary: [4]f32 = if (pixi.state.tools.current == .heightmap) .{255,255,255,255} else .{
@as(f32, @floatFromInt(pixi.state.colors.primary[0])) / 255.0,
@as(f32, @floatFromInt(pixi.state.colors.primary[1])) / 255.0,
@as(f32, @floatFromInt(pixi.state.colors.primary[2])) / 255.0,
Expand Down
6 changes: 3 additions & 3 deletions src/gfx/camera.zig
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ pub const Camera = struct {
var nearest_zoom_index: usize = 0;
var nearest_zoom_step: f32 = pixi.state.settings.zoom_steps[nearest_zoom_index];
for (pixi.state.settings.zoom_steps, 0..) |step, i| {
const step_difference = @fabs(camera.zoom - step);
const current_difference = @fabs(camera.zoom - nearest_zoom_step);
const step_difference = @abs(camera.zoom - step);
const current_difference = @abs(camera.zoom - nearest_zoom_step);
if (step_difference < current_difference) {
nearest_zoom_step = step;
nearest_zoom_index = i;
Expand Down Expand Up @@ -326,7 +326,7 @@ pub const Camera = struct {
const i = file.selected_sprite_index;
const tile_width = @as(f32, @floatFromInt(file.tile_width));
const tile_height = @as(f32, @floatFromInt(file.tile_height));
const sprite_scale = std.math.clamp(0.5 / @fabs(@as(f32, @floatFromInt(i)) + (file.flipbook_scroll / tile_width / 1.1)), 0.5, 1.0);
const sprite_scale = std.math.clamp(0.5 / @abs(@as(f32, @floatFromInt(i)) + (file.flipbook_scroll / tile_width / 1.1)), 0.5, 1.0);
var dst_x: f32 = options.sprite_position[0] + file.flipbook_scroll + @as(f32, @floatFromInt(i)) * tile_width * 1.1 - (tile_width * sprite_scale / 2.0);
var dst_y: f32 = options.sprite_position[1] + ((1.0 - sprite_scale) * (tile_height / 2.0));
var dst_width: f32 = tile_width * sprite_scale;
Expand Down
8 changes: 4 additions & 4 deletions src/math/direction.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub const Direction = enum(u8) {
4 => {
var d: u8 = 0;

const absx = @fabs(vx);
const absy = @fabs(vy);
const absx = @abs(vx);
const absy = @abs(vy);

if (absy < absx * sqrt2) {
//x
Expand All @@ -40,8 +40,8 @@ pub const Direction = enum(u8) {
8 => {
var d: u8 = 0;

const absx = @fabs(vx);
const absy = @fabs(vy);
const absx = @abs(vx);
const absy = @abs(vy);

if (absy < absx * (sqrt2 + 1.0)) {
// x
Expand Down

0 comments on commit 5e80883

Please sign in to comment.