{"id":9195,"date":"2022-09-21T19:00:00","date_gmt":"2022-09-21T10:00:00","guid":{"rendered":"https:\/\/taki-lab.site\/bocci\/?p=9195"},"modified":"2022-09-19T09:37:56","modified_gmt":"2022-09-19T00:37:56","slug":"rust%e5%8b%89%e5%bc%b7%e4%b8%ad%e3%80%819-19%e3%81%ae%e7%a9%8d%e3%81%bf%e4%b8%8a%e3%81%92","status":"publish","type":"post","link":"https:\/\/taki-lab.site\/bocci\/?p=9195","title":{"rendered":"RUST\u52c9\u5f37\u4e2d\u30019\/19\u306e\u7a4d\u307f\u4e0a\u3052?"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f wp-block-embed-\u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"21tRTdcybH\"><a href=\"https:\/\/taki-lab.site\/bocci\/?p=9154\">RUST\u52c9\u5f37\u4e2d\u30019\/11\u306e\u7a4d\u307f\u4e0a\u3052?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;RUST\u52c9\u5f37\u4e2d\u30019\/11\u306e\u7a4d\u307f\u4e0a\u3052?&#8221; &#8212; \u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f\" src=\"https:\/\/taki-lab.site\/bocci\/?p=9154&#038;embed=true#?secret=l6Bq3zrzmq#?secret=21tRTdcybH\" data-secret=\"21tRTdcybH\" width=\"474\" height=\"267\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u30de\u30f3\u30c7\u30eb\u30d6\u30ed\u96c6\u5408\u306e\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u3041\u3001\u3053\u306e\u51e6\u7406\u306f\u96e3\u89e3\u306a\u306e\u3067\u3001\u3053\u3053\u306f\u30c6\u30ad\u30b9\u30c8\u3092\u5199\u7d4c\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u76ee\u6a19\u306f\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u30d1\u30b9\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fn get_n_driverged(x0: f64, y0: f64, max_iter: usize) -> u8 {\r\n    let mut xn = 0.0;\r\n    let mut yn = 0.0;\r\n    for i in 1..max_iter {\r\n        let x_next = xn * xn - yn * yn + x0;\r\n        let y_next = 2.0 * xn * yn + y0;\r\n        xn = x_next;\r\n        yn = y_next;\r\n        if yn * yn + xn * xn > 4.0 {\r\n            return i as u8;\r\n        }\r\n    }\r\n    max_iter as u8\r\n}\r\n\r\npub fn generate_mandalbrot_set(\r\n    canvas_w: usize,\r\n    canvas_h: usize,\r\n    x_min: f64,\r\n    x_max: f64,\r\n    y_min: f64,\r\n    y_max: f64,\r\n    max_iter: usize,\r\n) -> Vec&lt;u8> {\r\n    let canvas_w_f64 = canvas_w as f64;\r\n    let canvas_h_f64 = canvas_h as f64;\r\n    let mut data = vec!&#91;];\r\n    for i in 0..canvas_h {\r\n        let i_f64 = i as f64;\r\n        let y = y_min + (y_max - y_min) * i_f64 \/ canvas_h_f64;\r\n        for j in 0..canvas_w {\r\n            let x = x_min + (x_max - x_min) * j as f64 \/ canvas_w_f64;\r\n            let iter_index = get_n_driverged(x, y, max_iter);\r\n            let v = iter_index % 8 * 32;\r\n            data.push(v);\r\n            data.push(v);\r\n            data.push(v);\r\n            data.push(255);\r\n        }\r\n    }\r\n    data\r\n}\r\n\r\n#&#91;cfg(test)]\r\nmod tests {\r\n    use super::*;\r\n    #&#91;test]\r\n    fn test_get_n_diverged() {\r\n        let max_iter = 10;\r\n        assert_eq!(get_n_driverged(1.0, 0.0, max_iter), 3);\r\n        assert_eq!(get_n_driverged(0.0, 0.0, max_iter), max_iter as u8);\r\n        assert_eq!(get_n_driverged(0.0, 1.0, max_iter), max_iter as u8);\r\n    }\r\n    #&#91;test]\r\n    fn test_generate_mandelbrot_set() {\r\n        let canvas_w = 2;\r\n        let canvas_h = 2;\r\n        let x_min = -1.0;\r\n        let x_max = 1.0;\r\n        let y_min = -1.0;\r\n        let y_max = 1.0;\r\n        let max_iter = 8;\r\n        assert_eq!(\r\n            generate_mandalbrot_set(canvas_w, canvas_h, x_min, x_max, y_min, y_max, max_iter),\r\n            vec!&#91;96, 96, 96, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255]\r\n        );\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>:~\/rust\/mandelbrot$ cargo test\r\n   Compiling mandelbrot v0.1.0 (\/home\/taki\/rust\/mandelbrot)\r\nwarning: function `set_panic_hook` is never used\r\n --> src\/utils.rs:1:8\r\n  |\r\n1 | pub fn set_panic_hook() {\r\n  |        ^^^^^^^^^^^^^^\r\n  |\r\n  = note: `#&#91;warn(dead_code)]` on by default\r\n\r\nwarning: function `get_n_driverged` is never used\r\n --> src\/logic.rs:1:4\r\n  |\r\n1 | fn get_n_driverged(x0: f64, y0: f64, max_iter: usize) -> u8 {\r\n  |    ^^^^^^^^^^^^^^^\r\n\r\nwarning: function `generate_mandalbrot_set` is never used\r\n  --> src\/logic.rs:16:8\r\n   |\r\n16 | pub fn generate_mandalbrot_set(\r\n   |        ^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nwarning: `mandelbrot` (lib) generated 3 warnings\r\nwarning: `mandelbrot` (lib test) generated 1 warning (1 duplicate)\r\n    Finished test &#91;unoptimized + debuginfo] target(s) in 0.46s\r\n     Running unittests src\/lib.rs (target\/debug\/deps\/mandelbrot-c2f466aeb790a116)\r\n\r\nrunning 2 tests\r\ntest logic::tests::test_generate_mandelbrot_set ... ok\r\ntest logic::tests::test_get_n_diverged ... ok\r\n\r\ntest result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\r\n\r\n     Running tests\/web.rs (target\/debug\/deps\/web-ca9c3937d615c7ed)\r\n\r\nrunning 0 tests\r\n\r\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\r\n\r\n   Doc-tests mandelbrot\r\n\r\nrunning 0 tests\r\n\r\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\r\n\r<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30de\u30f3\u30c7\u30eb\u30d6\u30ed\u96c6\u5408\u306e\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u307e\u3041\u3001\u3053\u306e\u51e6\u7406\u306f\u96e3\u89e3\u306a\u306e\u3067\u3001\u3053\u3053\u306f\u30c6\u30ad\u30b9\u30c8\u3092\u5199\u7d4c\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u76ee\u6a19\u306f\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u30d1\u30b9\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[2542,3],"tags":[],"class_list":["post-9195","post","type-post","status-publish","format-standard","hentry","category-rust","category-3"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8SDbY-2oj","jetpack-related-posts":[{"id":9335,"url":"https:\/\/taki-lab.site\/bocci\/?p=9335","url_meta":{"origin":9195,"position":0},"title":"RUST\u52c9\u5f37\u4e2d\u300110\/9\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e7410\u670810\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=9271 \u524d\u56de\u306e\u7d9a\u304d\u3067\u3001Rust\u5074\u306e\u5b9f\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":9573,"url":"https:\/\/taki-lab.site\/bocci\/?p=9573","url_meta":{"origin":9195,"position":1},"title":"RUST\u52c9\u5f37\u4e2d\u300111\/17\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e7411\u670818\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=9480 \u30dc\u30bf\u30f3\u51e6\u7406\u306e\u5b9f\u88c5\u3092\u884c\u3063\u3066\u3044\u304d\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/11\/ice_video_20221117-091004_edit_0.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/11\/ice_video_20221117-091004_edit_0.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/11\/ice_video_20221117-091004_edit_0.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":9271,"url":"https:\/\/taki-lab.site\/bocci\/?p=9271","url_meta":{"origin":9195,"position":2},"title":"RUST\u52c9\u5f37\u4e2d\u300110\/2\u306e\u7a4d\u307f\u4e0a\u3052?","author":"taki","date":"2022\u5e7410\u67084\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=9195 \u524d\u56de\u306e\u7d9a\u304d www\/inde\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9984,"url":"https:\/\/taki-lab.site\/bocci\/?p=9984","url_meta":{"origin":9195,"position":3},"title":"RUST\u52c9\u5f37\u4e2d\u30011\/17\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2023\u5e741\u670817\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=9573 \u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u51e6\u7406\u3092\u5b9f\u88c5\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/ice_video_20230117-110203.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/ice_video_20230117-110203.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/ice_video_20230117-110203.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":9480,"url":"https:\/\/taki-lab.site\/bocci\/?p=9480","url_meta":{"origin":9195,"position":4},"title":"RUST\u52c9\u5f37\u4e2d\u300111\/3\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e7411\u67083\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=9411 \u4eca\u56de\u306fGUI\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/11\/f1db73e69b455977b100f57fb9a1e2b0.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8208,"url":"https:\/\/taki-lab.site\/bocci\/?p=8208","url_meta":{"origin":9195,"position":5},"title":"RUST\u52c9\u5f37\u4e2d\u30014\/23\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e744\u670826\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=8084 \u524d\u56de\u306e\u7d9a\u304d\u3002 \u9006\u30dd\u30fc\u30e9\u30f3\u30c9\u8a18\u2026","rel":"","context":"\u51fa\u6765\u4e8b","block_context":{"text":"\u51fa\u6765\u4e8b","link":"https:\/\/taki-lab.site\/bocci\/?cat=9"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/9195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9195"}],"version-history":[{"count":1,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/9195\/revisions"}],"predecessor-version":[{"id":9197,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/9195\/revisions\/9197"}],"wp:attachment":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}