bresenham
を使いたい
座標値がまとまったものをbresenham.bresenham
に突っ込みたかったがbresenham
はint型しか受け付けていなかった。
truncateは0方向に丸める関数
検証
計測はGoogleColabを使用
前準備として読み込みとかをする
base.py
import math
import numpy as np
foo = [0.0001* i for i in range(1000000)]
int(num)
%%timeit
for i in foo:
tmp = int(i)
=>10 loops, best of 3: 105 ms per loop
---
type(tmp)
=>int
math.trunc(num)
%%timeit
for i in foo:
tmp = math.trunc(i)
=>10 loops, best of 3: 107 ms per loop
---
type(tmp)
=>int
np.trunc(num)
%%timeit
for i in foo:
tmp = np.trunc(i)
=>1 loop, best of 3: 831 ms per loop
---
type(tmp)
=>numpy.float64
結果
int(num) ≒ math.trunc(num) >> np.trunc(num)
と考えて良さそう