mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-21 13:55:45 +00:00
Improve vector math; Make bprint* return string
This commit is contained in:
+9
-9
@@ -151,15 +151,15 @@ aprintf :: proc(fmt: string, args: ..any) -> string {
|
||||
|
||||
// aprint* procedure return a string that was allocated with the current context
|
||||
// They must be freed accordingly
|
||||
bprint :: proc(buf: []byte, args: ..any) -> int {
|
||||
bprint :: proc(buf: []byte, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprint(&sb, ..args);
|
||||
}
|
||||
bprintln :: proc(buf: []byte, args: ..any) -> int {
|
||||
bprintln :: proc(buf: []byte, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprintln(&sb, ..args);
|
||||
}
|
||||
bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> int {
|
||||
bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprintf(&sb, fmt, ..args);
|
||||
}
|
||||
@@ -1047,7 +1047,7 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
|
||||
|
||||
|
||||
|
||||
sbprint :: proc(buf: ^String_Buffer, args: ..any) -> int {
|
||||
sbprint :: proc(buf: ^String_Buffer, args: ..any) -> string {
|
||||
fi: Fmt_Info;
|
||||
fi.buf = buf;
|
||||
|
||||
@@ -1060,10 +1060,10 @@ sbprint :: proc(buf: ^String_Buffer, args: ..any) -> int {
|
||||
fmt_value(&fi, args[i], 'v');
|
||||
prev_string = is_string;
|
||||
}
|
||||
return len(string_buffer_data(buf));
|
||||
return to_string(buf^);
|
||||
}
|
||||
|
||||
sbprintln :: proc(buf: ^String_Buffer, args: ..any) -> int {
|
||||
sbprintln :: proc(buf: ^String_Buffer, args: ..any) -> string {
|
||||
fi: Fmt_Info;
|
||||
fi.buf = buf;
|
||||
|
||||
@@ -1074,10 +1074,10 @@ sbprintln :: proc(buf: ^String_Buffer, args: ..any) -> int {
|
||||
fmt_value(&fi, args[i], 'v');
|
||||
}
|
||||
write_byte(buf, '\n');
|
||||
return len(string_buffer_data(buf));
|
||||
return to_string(buf^);
|
||||
}
|
||||
|
||||
sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ..any) -> int {
|
||||
sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ..any) -> string {
|
||||
fi := Fmt_Info{};
|
||||
end := len(fmt);
|
||||
arg_index := 0;
|
||||
@@ -1207,5 +1207,5 @@ sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ..any) -> int {
|
||||
write_string(b, ")");
|
||||
}
|
||||
|
||||
return len(string_buffer_data(b));
|
||||
return to_string(b^);
|
||||
}
|
||||
|
||||
+9
-9
@@ -120,32 +120,32 @@ mag :: proc(v: Vec2) -> f32 { return sqrt(dot(v, v)); }
|
||||
mag :: proc(v: Vec3) -> f32 { return sqrt(dot(v, v)); }
|
||||
mag :: proc(v: Vec4) -> f32 { return sqrt(dot(v, v)); }
|
||||
|
||||
norm :: proc(v: Vec2) -> Vec2 { return v / Vec2{mag(v)}; }
|
||||
norm :: proc(v: Vec3) -> Vec3 { return v / Vec3{mag(v)}; }
|
||||
norm :: proc(v: Vec4) -> Vec4 { return v / Vec4{mag(v)}; }
|
||||
norm :: proc(v: Vec2) -> Vec2 { return v / mag(v); }
|
||||
norm :: proc(v: Vec3) -> Vec3 { return v / mag(v); }
|
||||
norm :: proc(v: Vec4) -> Vec4 { return v / mag(v); }
|
||||
|
||||
norm0 :: proc(v: Vec2) -> Vec2 {
|
||||
m := mag(v);
|
||||
if m == 0 {
|
||||
return Vec2{0};
|
||||
return 0;
|
||||
}
|
||||
return v / Vec2{m};
|
||||
return v / m;
|
||||
}
|
||||
|
||||
norm0 :: proc(v: Vec3) -> Vec3 {
|
||||
m := mag(v);
|
||||
if m == 0 {
|
||||
return Vec3{0};
|
||||
return 0;
|
||||
}
|
||||
return v / Vec3{m};
|
||||
return v / m;
|
||||
}
|
||||
|
||||
norm0 :: proc(v: Vec4) -> Vec4 {
|
||||
m := mag(v);
|
||||
if m == 0 {
|
||||
return Vec4{0};
|
||||
return 0;
|
||||
}
|
||||
return v / Vec4{m};
|
||||
return v / m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user