1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

math: add a pure V math.mathutil, with generic min, max and abs functions (#9176), and use it consistently

This commit is contained in:
Lukas Neubert
2021-03-12 10:28:04 +01:00
committed by GitHub
parent 530b981765
commit a67d49050c
15 changed files with 193 additions and 125 deletions

View File

@@ -9,6 +9,7 @@ import sokol.sapp
import sokol.sgl
import sokol.gfx
import math
import math.mathutil as mu
// import time
pub type FNCb = fn (x voidptr)
@@ -538,13 +539,6 @@ pub fn (gg &Context) end() {
*/
}
fn abs(a f32) f32 {
if a >= 0 {
return a
}
return -a
}
pub fn (mut ctx Context) resize(width int, height int) {
ctx.width = width
ctx.height = height
@@ -556,8 +550,8 @@ pub fn (ctx &Context) draw_line(x f32, y f32, x2 f32, y2 f32, c gx.Color) {
}
if ctx.scale > 1 {
// Make the line more clear on hi dpi screens: draw a rectangle
mut width := abs(x2 - x)
mut height := abs(y2 - y)
mut width := mu.abs(x2 - x)
mut height := mu.abs(y2 - y)
if width == 0 {
width = 1
} else if height == 0 {

View File

@@ -232,4 +232,4 @@ fn test_proj() {
assert m4.mul_vec(ort, m4.Vec4{[ f32(150), 100, 0, 1]!}) == m4.Vec4{[ f32(0), 0, 0, 1]!}
assert m4.mul_vec(ort, m4.Vec4{[ f32(0), 0, 0, 1]!}) == m4.Vec4{[ f32(-1), -1, 0, 1]!}
assert m4.mul_vec(ort, m4.Vec4{[ f32(300), 200, 0, 1]!}) == m4.Vec4{[ f32(1), 1, 0, 1]!}
}
}