Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. pub fn interpolate_rectilinear(width: u32, height: u32, mut min_x: f64, mut max_x: f64, mut min_y: f64, mut max_y: f64)
  2. -> Box<Fn(u32, u32) -> Complex64 + Send + Sync + 'static> { ... }
  3.  
  4. pub fn interpolate_stretch(width: u32, height: u32, mut min_x: f64, mut max_x: f64, mut min_y: f64, mut max_y: f64)
  5. -> Box<Fn(u32, u32) -> Complex64 + Send + Sync + 'static> { ... }
  6.  
  7. pub fn parallel_image<F>(width: u32, height: u32, function: &F, interpolate: &Box<Fn(u32, u32) -> Complex64 + Send + Sync>, threshold: f64)
  8. -> ImageBuffer<image::Luma<u8>, Vec<u8>>
  9. where F: Sync + Fn(Complex64) -> Complex64
  10. { ... }
  11.  
  12. pub fn sequential_image<F>(width: u32, height: u32, function: &F, interpolate: &Box<Fn(u32, u32) -> Complex64>, threshold: f64)
  13. -> ImageBuffer<image::Luma<u8>, Vec<u8>>
  14. where F: Fn(Complex64) -> Complex64
  15. { ... }
  16.  
  17. let interpolate = interpolate_rectilinear(width, height, -1.0, 1.0, -1.0, 1.0);
  18. let image = parallel_image(width * 2, height * 2, &default_julia, &interpolate, 2.0);
  19.  
  20. #[test]
  21. fn test_serial_parallel_agree() {
  22. let (width, height) = (200, 200);
  23. let threshold = 2.0;
  24. let interpolate = interpolate_stretch(width, height, -1.0, 1.0, -1.0, 1.0);
  25.  
  26. assert!(parallel_image(width, height, &default_julia, &interpolate, threshold)
  27. .pixels()
  28. .zip(sequential_image(width, height, &default_julia, &interpolate, threshold)
  29. .pixels())
  30. .all(|(p, s)| p == s));
  31. }
  32.  
  33. > cargo test
  34. Compiling julia-set v0.3.0
  35. src/lib.rs:231:66: 231:78 error: mismatched types [E0308]
  36. src/lib.rs:231 .zip(sequential_image(width, height, &default_julia, &interpolate, threshold)
  37. ^~~~~~~~~~~~
  38. src/lib.rs:229:9: 233:36 note: in this expansion of assert! (defined in <std macros>)
  39. src/lib.rs:231:66: 231:78 help: run `rustc --explain E0308` to see a detailed explanation
  40. src/lib.rs:231:66: 231:78 note: expected type `&Box<std::ops::Fn(u32, u32) -> num::Complex<f64> + 'static>`
  41. src/lib.rs:231:66: 231:78 note: found type `&Box<std::ops::Fn(u32, u32) -> num::Complex<f64> + Send + Sync>`
  42. error: aborting due to previous error
  43. Build failed, waiting for other jobs to finish...
  44. error: Could not compile `julia-set`.
  45.  
  46. pub fn sequential_image<F>(
  47. ...,
  48. interpolate: &Box<Fn(u32, u32) -> Complex64>,
  49. ...) -> ...
  50.  
  51. sequential_image(width, height, &default_julia,
  52. &(interpolate as Box<Fn(u32, u32) -> Complex64>),
  53. threshold)
  54.  
  55. pub fn sequential_image<F>(
  56. ...,
  57. interpolate: &Fn(u32, u32) -> Complex64,
  58. ...) -> ...
  59.  
  60. sequential_image(width, height, &default_julia,
  61. &*interpolate,
  62. threshold)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement