this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix sqrt 3

+22 -10
+22 -10
src/main.zig
··· 9 9 fn calculate_hex_corners(center: Point, size: f32, _i: usize) Point { 10 10 const i: f32 = @floatFromInt(_i); 11 11 const angle_deg = 60.0 * i; 12 - const angle_rad = std.math.degreesToRadians(angle_deg); 12 + const angle_rad = std.math.pi / 180.0 * angle_deg; 13 13 14 14 const x_offset: f32 = size * std.math.cos(angle_rad); 15 15 const y_offset: f32 = size * std.math.sin(angle_rad); ··· 18 18 } 19 19 20 20 fn draw_hex(hex: HexCell) void { 21 + //const center_x: i32 = @intFromFloat(@round(hex.center.x)); 22 + //const center_y: i32 = @intFromFloat(@round(hex.center.y)); 23 + //rl.drawCircle(center_x, center_y, hex.outer_radius, .green); 24 + //rl.drawCircle(center_x, center_y, hex.inner_radius, .red); 25 + 21 26 var corners: [6]Point = undefined; 22 27 for (0..6) |i| { 23 28 const corner = calculate_hex_corners(hex.center, hex.outer_radius, i); 24 29 corners[i] = corner; 25 - //rl.drawCircle(corner.x, corner.y, 5.0, .black); 30 + 31 + //const corner_y: i32 = @intFromFloat(@round(corner.y)); 32 + //const corner_x: i32 = @intFromFloat(@round(corner.x)); 33 + 34 + //rl.drawCircle(corner_x, corner_y, 5.0, .black); 26 35 } 27 36 28 37 for (0..6) |i| { 29 38 const start = corners[i]; 30 39 const end = corners[@mod(i + 1, corners.len)]; 31 40 32 - const start_x: i32 = @intFromFloat(@floor(start.x)); 33 - const start_y: i32 = @intFromFloat(@floor(start.y)); 34 - const end_x: i32 = @intFromFloat(@floor(end.x)); 35 - const end_y: i32 = @intFromFloat(@floor(end.y)); 41 + std.debug.print("sx: {d} sy: {d} ex:{d} ey:{d}\n", .{ start.x, start.y, end.x, end.y }); 42 + 43 + const start_x: i32 = @intFromFloat(@round(start.x)); 44 + const start_y: i32 = @intFromFloat(@round(start.y)); 45 + const end_x: i32 = @intFromFloat(@round(end.x)); 46 + const end_y: i32 = @intFromFloat(@round(end.y)); 36 47 37 48 rl.drawLine(start_x, start_y, end_x, end_y, .black); 38 49 } ··· 69 80 } 70 81 71 82 fn calculate_outer_radius(inner_radius: f32) f32 { 72 - return 2.0 * inner_radius / std.math.sqrt(3); 83 + return 2.0 * inner_radius / std.math.sqrt(3.0); 73 84 } 74 85 fn calculate_inner_radius(outer_radius: f32) f32 { 75 - return outer_radius * std.math.sqrt(3) / 2.0; 86 + return outer_radius / 2.0 * std.math.sqrt(3.0); 76 87 } 77 88 78 89 fn new_hex(outer_radius: f32, center: Point) HexCell { 79 90 const size = outer_radius; 80 91 const inner = calculate_inner_radius(size); 81 - return HexCell{ .inner_radius = inner, .outer_radius = size, .height = std.math.sqrt(3) * size, .width = 2 * size, .center = center }; 92 + return HexCell{ .inner_radius = inner, .outer_radius = size, .height = std.math.sqrt(3.0) * size, .width = 2 * size, .center = center }; 82 93 } 83 94 84 95 pub fn main() anyerror!void { ··· 99 110 //---------------------------------------------------------------------------------- 100 111 // TODO: Update your variables here 101 112 //---------------------------------------------------------------------------------- 102 - const cell = new_hex(40.0, .{ 113 + const cell = new_hex(50.0, .{ 103 114 .x = screenWidth / 2, 104 115 .y = screenHeight / 2, 105 116 }); 117 + std.debug.print("cell : {}", .{cell}); 106 118 107 119 const tl = add_hex(cell, .top_left); 108 120 const tr = add_hex(cell, .top_right);