mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
math: move the math.mathutil generic min/max/abs fns to math (#13042)
This commit is contained in:
@@ -15,7 +15,6 @@ module ttf
|
||||
**********************************************************************/
|
||||
import encoding.utf8
|
||||
import math
|
||||
import math.mathutil as mu
|
||||
|
||||
pub struct BitMap {
|
||||
pub mut:
|
||||
@@ -227,7 +226,7 @@ pub fn (mut bmp BitMap) aline(in_x0 int, in_y0 int, in_x1 int, in_y1 int, c u32)
|
||||
|
||||
dist := f32(0.4)
|
||||
|
||||
if mu.abs(dx) > mu.abs(dy) {
|
||||
if math.abs(dx) > math.abs(dy) {
|
||||
if x1 < x0 {
|
||||
tmp = x0
|
||||
x0 = x1
|
||||
@@ -247,18 +246,18 @@ pub fn (mut bmp BitMap) aline(in_x0 int, in_y0 int, in_x1 int, in_y1 int, c u32)
|
||||
mut x := x0
|
||||
for x <= x1 + 0.5 {
|
||||
y := m * (x - x0) + y0
|
||||
e := 1 - mu.abs(y - 0.5 - int(y))
|
||||
e := 1 - math.abs(y - 0.5 - int(y))
|
||||
bmp.plot(int(x), int(y), color_multiply_alpha(c, e * 0.75))
|
||||
|
||||
ys1 := y + dist
|
||||
if int(ys1) != int(y) {
|
||||
v1 := mu.abs(ys1 - y) / dist * (1 - e)
|
||||
v1 := math.abs(ys1 - y) / dist * (1 - e)
|
||||
bmp.plot(int(x), int(ys1), color_multiply_alpha(c, v1))
|
||||
}
|
||||
|
||||
ys2 := y - dist
|
||||
if int(ys2) != int(y) {
|
||||
v2 := mu.abs(y - ys2) / dist * (1 - e)
|
||||
v2 := math.abs(y - ys2) / dist * (1 - e)
|
||||
bmp.plot(int(x), int(ys2), color_multiply_alpha(c, v2))
|
||||
}
|
||||
|
||||
@@ -284,18 +283,18 @@ pub fn (mut bmp BitMap) aline(in_x0 int, in_y0 int, in_x1 int, in_y1 int, c u32)
|
||||
mut y := y0
|
||||
for y <= y1 + 0.5 {
|
||||
x := n * (y - y0) + x0
|
||||
e := f32(1 - mu.abs(x - 0.5 - int(x)))
|
||||
e := f32(1 - math.abs(x - 0.5 - int(x)))
|
||||
bmp.plot(int(x), int(y), color_multiply_alpha(c, f32(e * 0.75)))
|
||||
|
||||
xs1 := x + dist
|
||||
if int(xs1) != int(x) {
|
||||
v1 := mu.abs(xs1 - x) / dist * (1 - e)
|
||||
v1 := math.abs(xs1 - x) / dist * (1 - e)
|
||||
bmp.plot(int(xs1), int(y), color_multiply_alpha(c, f32(v1)))
|
||||
}
|
||||
|
||||
xs2 := x - dist
|
||||
if int(xs2) != int(x) {
|
||||
v2 := mu.abs(x - xs1) / dist * (1 - e)
|
||||
v2 := math.abs(x - xs1) / dist * (1 - e)
|
||||
bmp.plot(int(xs2), int(y), color_multiply_alpha(c, f32(v2)))
|
||||
}
|
||||
y += 1.0
|
||||
@@ -336,9 +335,9 @@ pub fn (mut bmp BitMap) line(in_x0 int, in_y0 int, in_x1 int, in_y1 int, c u32)
|
||||
mut x := x0
|
||||
mut y := y0
|
||||
|
||||
dx := mu.abs(x1 - x0)
|
||||
dx := math.abs(x1 - x0)
|
||||
sx := if x0 < x1 { 1 } else { -1 }
|
||||
dy := -mu.abs(y1 - y0)
|
||||
dy := -math.abs(y1 - y0)
|
||||
sy := if y0 < y1 { 1 } else { -1 }
|
||||
|
||||
// verical line
|
||||
@@ -412,8 +411,8 @@ pub fn (mut bmp BitMap) quadratic(in_x0 int, in_y0 int, in_x1 int, in_y1 int, in
|
||||
cy := int(in_cy)
|
||||
|
||||
mut division := f64(1.0)
|
||||
dx := mu.abs(x0 - x1)
|
||||
dy := mu.abs(y0 - y1)
|
||||
dx := math.abs(x0 - x1)
|
||||
dy := math.abs(y0 - y1)
|
||||
|
||||
// if few pixel draw a simple line
|
||||
// if dx == 0 && dy == 0 {
|
||||
@@ -521,10 +520,10 @@ pub fn (mut bmp BitMap) get_chars_bbox(in_string string) []int {
|
||||
x_min, x_max, _, _ := bmp.tf.read_glyph_dim(c_index)
|
||||
//-----------------
|
||||
|
||||
width := int((mu.abs(x_max + x_min) + ax) * bmp.scale)
|
||||
width := int((math.abs(x_max + x_min) + ax) * bmp.scale)
|
||||
// width := int((cw+ax) * bmp.scale)
|
||||
w += width + div_space_cw
|
||||
h := int(mu.abs(int(bmp.tf.y_max - bmp.tf.y_min)) * bmp.scale)
|
||||
h := int(math.abs(int(bmp.tf.y_max - bmp.tf.y_min)) * bmp.scale)
|
||||
res << w
|
||||
res << h
|
||||
|
||||
@@ -592,7 +591,7 @@ pub fn (mut bmp BitMap) get_bbox(in_string string) (int, int) {
|
||||
// x_max := 2
|
||||
//-----------------
|
||||
|
||||
width := int((mu.abs(x_max + x_min) + ax) * bmp.scale)
|
||||
width := int((math.abs(x_max + x_min) + ax) * bmp.scale)
|
||||
// width := int((cw+ax) * bmp.scale)
|
||||
w += width + div_space_cw
|
||||
|
||||
@@ -601,7 +600,7 @@ pub fn (mut bmp BitMap) get_bbox(in_string string) (int, int) {
|
||||
|
||||
// dprintln("y_min: $bmp.tf.y_min y_max: $bmp.tf.y_max res: ${int((bmp.tf.y_max - bmp.tf.y_min)*buf.scale)} width: ${int( (cw) * buf.scale)}")
|
||||
// buf.box(0,y_base - int((bmp.tf.y_min)*buf.scale), int( (x_max) * buf.scale), y_base-int((bmp.tf.y_max)*buf.scale), u32(0xFF00_0000) )
|
||||
return w, int(mu.abs(int(bmp.tf.y_max - bmp.tf.y_min)) * bmp.scale)
|
||||
return w, int(math.abs(int(bmp.tf.y_max - bmp.tf.y_min)) * bmp.scale)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -621,7 +620,7 @@ fn (mut bmp BitMap) draw_notdef_glyph(in_x int, in_w int) {
|
||||
bmp.ch_matrix[7] = int(y1)
|
||||
x, y := bmp.trf_ch(p)
|
||||
|
||||
y_h := mu.abs(bmp.tf.y_max - bmp.tf.y_min) * bmp.scale * 0.5
|
||||
y_h := math.abs(bmp.tf.y_max - bmp.tf.y_min) * bmp.scale * 0.5
|
||||
|
||||
bmp.box(int(x), int(y), int(x - in_w), int(y - y_h), bmp.color)
|
||||
bmp.line(int(x), int(y), int(x - in_w), int(y - y_h), bmp.color)
|
||||
@@ -690,7 +689,7 @@ pub fn (mut bmp BitMap) draw_text(in_string string) (int, int) {
|
||||
// x_max := 2
|
||||
//-----------------
|
||||
|
||||
mut width := int((mu.abs(x_max + x_min) + ax) * bmp.scale)
|
||||
mut width := int((math.abs(x_max + x_min) + ax) * bmp.scale)
|
||||
if bmp.use_font_metrics {
|
||||
width = int((cw + ax) * bmp.scale)
|
||||
}
|
||||
@@ -700,7 +699,7 @@ pub fn (mut bmp BitMap) draw_text(in_string string) (int, int) {
|
||||
|
||||
// dprintln("y_min: $bmp.tf.y_min y_max: $bmp.tf.y_max res: ${int((bmp.tf.y_max - bmp.tf.y_min)*buf.scale)} width: ${int( (cw) * buf.scale)}")
|
||||
// buf.box(0,y_base - int((bmp.tf.y_min)*buf.scale), int( (x_max) * buf.scale), y_base-int((bmp.tf.y_max)*buf.scale), u32(0xFF00_0000) )
|
||||
return w, int(mu.abs(int(bmp.tf.y_max - bmp.tf.y_min)) * bmp.scale)
|
||||
return w, int(math.abs(int(bmp.tf.y_max - bmp.tf.y_min)) * bmp.scale)
|
||||
}
|
||||
|
||||
pub fn (mut bmp BitMap) draw_glyph(index u16) (int, int) {
|
||||
|
||||
@@ -215,15 +215,15 @@ fn test_main() {
|
||||
fn get_raw_data(data string) []byte {
|
||||
mut buf := []byte{}
|
||||
mut c := 0
|
||||
mut b := 0
|
||||
mut b := u32(0)
|
||||
for ch in data {
|
||||
if ch >= `0` && ch <= `9` {
|
||||
b = b << 4
|
||||
b += int(ch - `0`)
|
||||
b += u32(ch - `0`)
|
||||
c++
|
||||
} else if ch >= `a` && ch <= `f` {
|
||||
b = b << 4
|
||||
b += int(ch - `a` + 10)
|
||||
b += u32(ch - `a` + 10)
|
||||
c++
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user