{"action":"created","comment":{"url":"https://api.github.com/repos/alex-eg/rt2/pulls/comments/187808286","pull_request_review_id":119661615,"id":187808286,"diff_hunk":"@@ -1,90 +1,76 @@\n-extern crate num_cpus;\n-extern crate crossbeam_utils;\n-\n-use na::Vector3 as Vec3;\n-use std::f64::INFINITY;\n use camera::Camera;\n use light::Light;\n use object::Object;\n-use std::sync::Arc;\n+use surface::{Division, Surface};\n+\n+use na::Vector3 as Vec3;\n+use scoped_threadpool::Pool;\n+use num_cpus;\n+\n+use std::f64::INFINITY;\n \n pub struct Ray {\n     pub dir: Vec3<f64>,\n     pub origin: Vec3<f64>\n }\n \n pub fn march (cam: &Camera, objects: &Vec<Box<Object>>, lights: &Vec<Box<Light>>)\n-              -> Vec<f64> {\n-    let pixel_num = (cam.height * cam.width * 3) as usize;\n-    let mut pixels: Vec<f64> = Vec::with_capacity(pixel_num);\n-    unsafe {\n-        pixels.set_len(pixel_num);\n-    }\n-    let num_cpus = num_cpus::get();\n-    let t_cam = Arc::new((*cam).clone());\n-    let t_obj = Arc::new((*objects).clone());\n-    let t_lights = Arc::new((*lights).clone());\n-    let mut chunk_num = 0;\n-    for chunk in pixels.chunks_mut(pixel_num / num_cpus) {\n-        let w_cam = t_cam.clone();\n-        let w_obj = t_obj.clone();\n-        let w_lights = t_lights.clone();\n-        let w_num_cpus = num_cpus;\n-        let w_i = chunk_num;\n-        crossbeam_utils::scoped::scope(|scope| {\n-            scope.spawn(move || {\n-                process_part(w_cam, w_obj, w_lights,\n-                             w_num_cpus, w_i, chunk);\n+              -> Vec<u8> {\n+\n+    let mut pool = Pool::new(num_cpus::get() as u32);\n+    let surf = Surface::new(cam.width, cam.height);\n+\n+    pool.scoped(|scope| {\n+        for chunk in surf.divide(32, 32) {\n+            scope.execute(move || {\n+                process_part(cam, objects, lights, chunk);\n             });\n-        });\n-        chunk_num += 1;\n-    }\n-    pixels\n+        }\n+    });\n+    surf.pixels\n }\n \n-fn process_part(cam: Arc<Camera>, objects: Arc<Vec<Box<Object>>>, lights: Arc<Vec<Box<Light>>>,\n-                num_cpus: usize, part_num: usize, pixels: &mut [f64]) {\n+fn process_part(cam: &Camera, objects: &Vec<Box<Object>>, lights: &Vec<Box<Light>>,\n+                chunk: Division) {","path":"src/raytracer.rs","position":67,"original_position":67,"commit_id":"0116d6e800c4daa52fec16b043d7067ebe140ee5","original_commit_id":"0116d6e800c4daa52fec16b043d7067ebe140ee5","user":{"login":"alex-eg","id":574381,"avatar_url":"https://avatars0.githubusercontent.com/u/574381?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-eg","html_url":"https://github.com/alex-eg","followers_url":"https://api.github.com/users/alex-eg/followers","following_url":"https://api.github.com/users/alex-eg/following{/other_user}","gists_url":"https://api.github.com/users/alex-eg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-eg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-eg/subscriptions","organizations_url":"https://api.github.com/users/alex-eg/orgs","repos_url":"https://api.github.com/users/alex-eg/repos","events_url":"https://api.github.com/users/alex-eg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-eg/received_events","type":"User","site_admin":false},"body":"Yep, missed that one.","created_at":"2018-05-13T17:41:11Z","updated_at":"2018-05-13T17:41:11Z","html_url":"https://github.com/alex-eg/rt2/pull/17#discussion_r187808286","pull_request_url":"https://api.github.com/repos/alex-eg/rt2/pulls/17","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/alex-eg/rt2/pulls/comments/187808286"},"html":{"href":"https://github.com/alex-eg/rt2/pull/17#discussion_r187808286"},"pull_request":{"href":"https://api.github.com/repos/alex-eg/rt2/pulls/17"}},"in_reply_to_id":187802815},"pull_request":{"url":"https://api.github.com/repos/alex-eg/rt2/pulls/17","id":187667887,"html_url":"https://github.com/alex-eg/rt2/pull/17","diff_url":"https://github.com/alex-eg/rt2/pull/17.diff","patch_url":"https://github.com/alex-eg/rt2/pull/17.patch","issue_url":"https://api.github.com/repos/alex-eg/rt2/issues/17","number":17,"state":"open","locked":false,"title":"Surface subdivision","user":{"login":"alex-eg","id":574381,"avatar_url":"https://avatars0.githubusercontent.com/u/574381?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-eg","html_url":"https://github.com/alex-eg","followers_url":"https://api.github.com/users/alex-eg/followers","following_url":"https://api.github.com/users/alex-eg/following{/other_user}","gists_url":"https://api.github.com/users/alex-eg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-eg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-eg/subscriptions","organizations_url":"https://api.github.com/users/alex-eg/orgs","repos_url":"https://api.github.com/users/alex-eg/repos","events_url":"https://api.github.com/users/alex-eg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-eg/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-05-13T12:37:56Z","updated_at":"2018-05-13T17:41:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"da48257761b41e2831d25e439300c2cb009057ac","assignee":null,"assignees":[],"requested_reviewers":[{"login":"97nomad","id":18262089,"avatar_url":"https://avatars0.githubusercontent.com/u/18262089?v=4","gravatar_id":"","url":"https://api.github.com/users/97nomad","html_url":"https://github.com/97nomad","followers_url":"https://api.github.com/users/97nomad/followers","following_url":"https://api.github.com/users/97nomad/following{/other_user}","gists_url":"https://api.github.com/users/97nomad/gists{/gist_id}","starred_url":"https://api.github.com/users/97nomad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/97nomad/subscriptions","organizations_url":"https://api.github.com/users/97nomad/orgs","repos_url":"https://api.github.com/users/97nomad/repos","events_url":"https://api.github.com/users/97nomad/events{/privacy}","received_events_url":"https://api.github.com/users/97nomad/received_events","type":"User","site_admin":false},{"login":"fwrs","id":22685239,"avatar_url":"https://avatars3.githubusercontent.com/u/22685239?v=4","gravatar_id":"","url":"https://api.github.com/users/fwrs","html_url":"https://github.com/fwrs","followers_url":"https://api.github.com/users/fwrs/followers","following_url":"https://api.github.com/users/fwrs/following{/other_user}","gists_url":"https://api.github.com/users/fwrs/gists{/gist_id}","starred_url":"https://api.github.com/users/fwrs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fwrs/subscriptions","organizations_url":"https://api.github.com/users/fwrs/orgs","repos_url":"https://api.github.com/users/fwrs/repos","events_url":"https://api.github.com/users/fwrs/events{/privacy}","received_events_url":"https://api.github.com/users/fwrs/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/alex-eg/rt2/pulls/17/commits","review_comments_url":"https://api.github.com/repos/alex-eg/rt2/pulls/17/comments","review_comment_url":"https://api.github.com/repos/alex-eg/rt2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alex-eg/rt2/issues/17/comments","statuses_url":"https://api.github.com/repos/alex-eg/rt2/statuses/0116d6e800c4daa52fec16b043d7067ebe140ee5","head":{"label":"alex-eg:surface-subdivision","ref":"surface-subdivision","sha":"0116d6e800c4daa52fec16b043d7067ebe140ee5","user":{"login":"alex-eg","id":574381,"avatar_url":"https://avatars0.githubusercontent.com/u/574381?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-eg","html_url":"https://github.com/alex-eg","followers_url":"https://api.github.com/users/alex-eg/followers","following_url":"https://api.github.com/users/alex-eg/following{/other_user}","gists_url":"https://api.github.com/users/alex-eg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-eg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-eg/subscriptions","organizations_url":"https://api.github.com/users/alex-eg/orgs","repos_url":"https://api.github.com/users/alex-eg/repos","events_url":"https://api.github.com/users/alex-eg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-eg/received_events","type":"User","site_admin":false},"repo":{"id":56128061,"name":"rt2","full_name":"alex-eg/rt2","owner":{"login":"alex-eg","id":574381,"avatar_url":"https://avatars0.githubusercontent.com/u/574381?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-eg","html_url":"https://github.com/alex-eg","followers_url":"https://api.github.com/users/alex-eg/followers","following_url":"https://api.github.com/users/alex-eg/following{/other_user}","gists_url":"https://api.github.com/users/alex-eg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-eg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-eg/subscriptions","organizations_url":"https://api.github.com/users/alex-eg/orgs","repos_url":"https://api.github.com/users/alex-eg/repos","events_url":"https://api.github.com/users/alex-eg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-eg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alex-eg/rt2","description":"Toy real-time ray tracer","fork":false,"url":"https://api.github.com/repos/alex-eg/rt2","forks_url":"https://api.github.com/repos/alex-eg/rt2/forks","keys_url":"https://api.github.com/repos/alex-eg/rt2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alex-eg/rt2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alex-eg/rt2/teams","hooks_url":"https://api.github.com/repos/alex-eg/rt2/hooks","issue_events_url":"https://api.github.com/repos/alex-eg/rt2/issues/events{/number}","events_url":"https://api.github.com/repos/alex-eg/rt2/events","assignees_url":"https://api.github.com/repos/alex-eg/rt2/assignees{/user}","branches_url":"https://api.github.com/repos/alex-eg/rt2/branches{/branch}","tags_url":"https://api.github.com/repos/alex-eg/rt2/tags","blobs_url":"https://api.github.com/repos/alex-eg/rt2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alex-eg/rt2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alex-eg/rt2/git/refs{/sha}","trees_url":"https://api.github.com/repos/alex-eg/rt2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alex-eg/rt2/statuses/{sha}","languages_url":"https://api.github.com/repos/alex-eg/rt2/languages","stargazers_url":"https://api.github.com/repos/alex-eg/rt2/stargazers","contributors_url":"https://api.github.com/repos/alex-eg/rt2/contributors","subscribers_url":"https://api.github.com/repos/alex-eg/rt2/subscribers","subscription_url":"https://api.github.com/repos/alex-eg/rt2/subscription","commits_url":"https://api.github.com/repos/alex-eg/rt2/commits{/sha}","git_commits_url":"https://api.github.com/repos/alex-eg/rt2/git/commits{/sha}","comments_url":"https://api.github.com/repos/alex-eg/rt2/comments{/number}","issue_comment_url":"https://api.github.com/repos/alex-eg/rt2/issues/comments{/number}","contents_url":"https://api.github.com/repos/alex-eg/rt2/contents/{+path}","compare_url":"https://api.github.com/repos/alex-eg/rt2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alex-eg/rt2/merges","archive_url":"https://api.github.com/repos/alex-eg/rt2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alex-eg/rt2/downloads","issues_url":"https://api.github.com/repos/alex-eg/rt2/issues{/number}","pulls_url":"https://api.github.com/repos/alex-eg/rt2/pulls{/number}","milestones_url":"https://api.github.com/repos/alex-eg/rt2/milestones{/number}","notifications_url":"https://api.github.com/repos/alex-eg/rt2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alex-eg/rt2/labels{/name}","releases_url":"https://api.github.com/repos/alex-eg/rt2/releases{/id}","deployments_url":"https://api.github.com/repos/alex-eg/rt2/deployments","created_at":"2016-04-13T06:49:21Z","updated_at":"2018-05-13T14:40:56Z","pushed_at":"2018-05-13T12:37:56Z","git_url":"git://github.com/alex-eg/rt2.git","ssh_url":"git@github.com:alex-eg/rt2.git","clone_url":"https://github.com/alex-eg/rt2.git","svn_url":"https://github.com/alex-eg/rt2","homepage":"","size":75,"stargazers_count":3,"watchers_count":3,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":1,"open_issues":12,"watchers":3,"default_branch":"master"}},"base":{"label":"alex-eg:master","ref":"master","sha":"ba5500d28cd2918dc767f8fae9e698c8e7169dff","user":{"login":"alex-eg","id":574381,"avatar_url":"https://avatars0.githubusercontent.com/u/574381?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-eg","html_url":"https://github.com/alex-eg","followers_url":"https://api.github.com/users/alex-eg/followers","following_url":"https://api.github.com/users/alex-eg/following{/other_user}","gists_url":"https://api.github.com/users/alex-eg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-eg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-eg/subscriptions","organizations_url":"https://api.github.com/users/alex-eg/orgs","repos_url":"https://api.github.com/users/alex-eg/repos","events_url":"https://api.github.com/users/alex-eg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-eg/received_events","type":"User","site_admin":false},"repo":{"id":56128061,"name":"rt2","full_name":"alex-eg/rt2","owner":{"login":"alex-eg","id":574381,"avatar_url":"https://avatars0.githubusercontent.com/u/574381?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-eg","html_url":"https://github.com/alex-eg","followers_url":"https://api.github.com/users/alex-eg/followers","following_url":"https://api.github.com/users/alex-eg/following{/other_user}","gists_url":"https://api.github.com/users/alex-eg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-eg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-eg/subscriptions","organizations_url":"https://api.github.com/users/alex-eg/orgs","repos_url":"https://api.github.com/users/alex-eg/repos","events_url":"https://api.github.com/users/alex-eg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-eg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alex-eg/rt2","description":"Toy real-time ray tracer","fork":false,"url":"https://api.github.com/repos/alex-eg/rt2","forks_url":"https://api.github.com/repos/alex-eg/rt2/forks","keys_url":"https://api.github.com/repos/alex-eg/rt2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alex-eg/rt2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alex-eg/rt2/teams","hooks_url":"https://api.github.com/repos/alex-eg/rt2/hooks","issue_events_url":"https://api.github.com/repos/alex-eg/rt2/issues/events{/number}","events_url":"https://api.github.com/repos/alex-eg/rt2/events","assignees_url":"https://api.github.com/repos/alex-eg/rt2/assignees{/user}","branches_url":"https://api.github.com/repos/alex-eg/rt2/branches{/branch}","tags_url":"https://api.github.com/repos/alex-eg/rt2/tags","blobs_url":"https://api.github.com/repos/alex-eg/rt2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alex-eg/rt2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alex-eg/rt2/git/refs{/sha}","trees_url":"https://api.github.com/repos/alex-eg/rt2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alex-eg/rt2/statuses/{sha}","languages_url":"https://api.github.com/repos/alex-eg/rt2/languages","stargazers_url":"https://api.github.com/repos/alex-eg/rt2/stargazers","contributors_url":"https://api.github.com/repos/alex-eg/rt2/contributors","subscribers_url":"https://api.github.com/repos/alex-eg/rt2/subscribers","subscription_url":"https://api.github.com/repos/alex-eg/rt2/subscription","commits_url":"https://api.github.com/repos/alex-eg/rt2/commits{/sha}","git_commits_url":"https://api.github.com/repos/alex-eg/rt2/git/commits{/sha}","comments_url":"https://api.github.com/repos/alex-eg/rt2/comments{/number}","issue_comment_url":"https://api.github.com/repos/alex-eg/rt2/issues/comments{/number}","contents_url":"https://api.github.com/repos/alex-eg/rt2/contents/{+path}","compare_url":"https://api.github.com/repos/alex-eg/rt2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alex-eg/rt2/merges","archive_url":"https://api.github.com/repos/alex-eg/rt2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alex-eg/rt2/downloads","issues_url":"https://api.github.com/repos/alex-eg/rt2/issues{/number}","pulls_url":"https://api.github.com/repos/alex-eg/rt2/pulls{/number}","milestones_url":"https://api.github.com/repos/alex-eg/rt2/milestones{/number}","notifications_url":"https://api.github.com/repos/alex-eg/rt2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alex-eg/rt2/labels{/name}","releases_url":"https://api.github.com/repos/alex-eg/rt2/releases{/id}","deployments_url":"https://api.github.com/repos/alex-eg/rt2/deployments","created_at":"2016-04-13T06:49:21Z","updated_at":"2018-05-13T14:40:56Z","pushed_at":"2018-05-13T12:37:56Z","git_url":"git://github.com/alex-eg/rt2.git","ssh_url":"git@github.com:alex-eg/rt2.git","clone_url":"https://github.com/alex-eg/rt2.git","svn_url":"https://github.com/alex-eg/rt2","homepage":"","size":75,"stargazers_count":3,"watchers_count":3,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":1,"open_issues":12,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alex-eg/rt2/pulls/17"},"html":{"href":"https://github.com/alex-eg/rt2/pull/17"},"issue":{"href":"https://api.github.com/repos/alex-eg/rt2/issues/17"},"comments":{"href":"https://api.github.com/repos/alex-eg/rt2/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/alex-eg/rt2/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/alex-eg/rt2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alex-eg/rt2/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/alex-eg/rt2/statuses/0116d6e800c4daa52fec16b043d7067ebe140ee5"}},"author_association":"OWNER"}}
{"actor":{"display_login":"alex-eg"}}