aboutsummaryrefslogtreecommitdiff
path: root/aberth/aberth_kernel.fut
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-04-20 10:26:24 +0200
committertomsmeding <tom.smeding@gmail.com>2019-04-20 10:26:24 +0200
commit3a7e1c80cb28a5d63da056f4889eb207140c0e67 (patch)
treeeed8ff398fcef7c44afea06480fe91b7534e2c7a /aberth/aberth_kernel.fut
parent68d2ce9c59e90bb9a8bee4ad65a0e87185304354 (diff)
Different image bounds layout
Diffstat (limited to 'aberth/aberth_kernel.fut')
-rw-r--r--aberth/aberth_kernel.fut25
1 files changed, 15 insertions, 10 deletions
diff --git a/aberth/aberth_kernel.fut b/aberth/aberth_kernel.fut
index fae1450..58b8838 100644
--- a/aberth/aberth_kernel.fut
+++ b/aberth/aberth_kernel.fut
@@ -128,11 +128,13 @@ let calc_index (value: f64) (left: f64) (right: f64) (steps: i32): i32 =
let point_index
(width: i32) (height: i32)
- (top_left: complex) (bottom_right: complex)
+ (bottom_left: complex) (top_right: complex)
(pt: complex)
: i32 =
- let xi = calc_index (c64.re pt) (c64.re top_left) (c64.re bottom_right) width
- let yi = calc_index (c64.im pt) (c64.im bottom_right) (c64.im top_left) height
+ -- Range for 'yi' is reversed because image coordinates go down in the y
+ -- direction, while complex coordinates go up in the y direction
+ let xi = calc_index (c64.re pt) (c64.re bottom_left) (c64.re top_right) width
+ let yi = calc_index (c64.im pt) (c64.im top_right) (c64.im bottom_left) height
in if 0 <= xi && xi < width && 0 <= yi && yi < height
then width * yi + xi
else -1
@@ -145,16 +147,19 @@ entry main_job
: []i32 =
-- Unnecessary to give each polynomial a different seed
let rng = rand_engine.rng_from_seed [seed]
- let top_left = c64.mk left top
- let bottom_right = c64.mk right bottom
- let indices = filter (\i -> i != -1) (flatten
+ let bottom_left = c64.mk left bottom
+ let top_right = c64.mk right top
+ let indices = flatten
(map (\idx ->
let p = derbyshire_at_index idx
let (_, pts) = aberth.aberth p rng
- let indices = map (point_index width height top_left bottom_right) pts
- in indices)
- (start_index ..< start_index + num_polys)))
- in reduce_by_index (replicate (width * height) 0) (+) 0 indices (replicate (length indices) 1)
+ in map (point_index width height bottom_left top_right) pts)
+ (start_index ..< start_index + num_polys))
+ let filtered = filter (\i -> i != -1) indices
+ in reduce_by_index (replicate (width * height) 0)
+ (+) 0
+ filtered
+ (replicate (length filtered) 1)
entry main_all
(width: i32) (height: i32)