Skip to content

Commit

Permalink
Update all examples to Rust 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMajeri authored and gnzlbg committed Sep 14, 2018
1 parent cafc4ce commit 1e725f1
Show file tree
Hide file tree
Showing 71 changed files with 146 additions and 223 deletions.
1 change: 1 addition & 0 deletions examples/aobench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "aobench"
version = "0.1.0"
authors = ["gnzlbg <[email protected]>"]
autobenches = false
edition = "2018"

[[bin]]
name = "aobench"
Expand Down
9 changes: 2 additions & 7 deletions examples/aobench/benches/ambient_occlusion.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//! Benchmarks intersection between rays and planes
#![feature(stdsimd)]

extern crate aobench_lib;

#[macro_use]
extern crate criterion;

use aobench_lib::*;
use criterion::*;
use intersection::Isect;
Expand All @@ -17,7 +12,7 @@ fn hit_scalar(c: &mut Criterion) {
"scalar",
Benchmark::new("ao_hit", move |b| {
b.iter(|| {
let mut isect = Isect::new();
let mut isect = Isect::default();
let isect = black_box(&mut isect);
let s = black_box(&mut scene);
let mut v = ambient_occlusion::scalar(s, isect);
Expand All @@ -34,7 +29,7 @@ fn hit_vector(c: &mut Criterion) {
"vector",
Benchmark::new("ao_hit", move |b| {
b.iter(|| {
let mut isect = Isect::new();
let mut isect = Isect::default();
let isect = black_box(&mut isect);
let s = black_box(&mut scene);
let mut v = ambient_occlusion::vector(s, isect);
Expand Down
17 changes: 6 additions & 11 deletions examples/aobench/benches/isec_plane.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
//! Benchmarks intersection between rays and planes
#![feature(stdsimd)]

extern crate aobench_lib;

#[macro_use]
extern crate criterion;

use criterion::*;

use aobench_lib::*;
use geometry::{f32xN, Plane, Ray, RayxN, V3DxN, V3D};
use intersection::{Intersect, Isect, IsectxN};
use crate::geometry::{f32xN, Plane, Ray, RayxN, V3DxN, V3D};
use crate::intersection::{Intersect, Isect, IsectxN};

fn hit_scalar(c: &mut Criterion) {
let mut s = Plane {
Expand Down Expand Up @@ -42,7 +37,7 @@ fn hit_scalar(c: &mut Criterion) {
"scalar",
Benchmark::new("isec_plane_hit", move |b| {
b.iter(|| {
let mut isect = Isect::new();
let mut isect = Isect::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down Expand Up @@ -84,7 +79,7 @@ fn miss_scalar(c: &mut Criterion) {
"scalar",
Benchmark::new("isec_plane_miss", move |b| {
b.iter(|| {
let mut isect = Isect::new();
let mut isect = Isect::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down Expand Up @@ -126,7 +121,7 @@ fn hit_vector(c: &mut Criterion) {
"vector",
Benchmark::new("isec_plane_hit", move |b| {
b.iter(|| {
let mut isect = IsectxN::new();
let mut isect = IsectxN::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down Expand Up @@ -168,7 +163,7 @@ fn miss_vector(c: &mut Criterion) {
"vector",
Benchmark::new("isec_plane_miss", move |b| {
b.iter(|| {
let mut isect = IsectxN::new();
let mut isect = IsectxN::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down
18 changes: 7 additions & 11 deletions examples/aobench/benches/isec_sphere.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
//! Benchmarks intersection between rays and spheres
#![feature(stdsimd)]

extern crate aobench_lib;

#[macro_use]
extern crate criterion;

use test::*;
use aobench_lib::*;
use criterion::*;
use geometry::{f32xN, Ray, RayxN, Sphere, V3DxN, V3D};
use intersection::{Intersect, Isect, IsectxN};
use crate::geometry::{f32xN, Ray, RayxN, Sphere, V3DxN, V3D};
use crate::intersection::{Intersect, Isect, IsectxN};

fn hit_scalar(c: &mut Criterion) {
let mut s = Sphere {
Expand Down Expand Up @@ -38,7 +34,7 @@ fn hit_scalar(c: &mut Criterion) {
"scalar",
Benchmark::new("isec_sphere_hit", move |b| {
b.iter(|| {
let mut isect = Isect::new();
let mut isect = Isect::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down Expand Up @@ -76,7 +72,7 @@ fn miss_scalar(c: &mut Criterion) {
"scalar",
Benchmark::new("isec_sphere_miss", move |b| {
b.iter(|| {
let mut isect = Isect::new();
let mut isect = Isect::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down Expand Up @@ -114,7 +110,7 @@ fn hit_vector(c: &mut Criterion) {
"vector",
Benchmark::new("isec_sphere_hit", move |b| {
b.iter(|| {
let mut isect = IsectxN::new();
let mut isect = IsectxN::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down Expand Up @@ -152,7 +148,7 @@ fn miss_vector(c: &mut Criterion) {
"vector",
Benchmark::new("isec_sphere_miss", move |b| {
b.iter(|| {
let mut isect = IsectxN::new();
let mut isect = IsectxN::default();
let isect = black_box(&mut isect);
let s = black_box(&mut s);
let r = black_box(&mut r);
Expand Down
5 changes: 0 additions & 5 deletions examples/aobench/benches/random.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//! Benchmarks PNRG
#![feature(stdsimd)]

extern crate aobench_lib;

#[macro_use]
extern crate criterion;

use aobench_lib::geometry::f32xN;
use aobench_lib::random;
use criterion::*;
Expand Down
3 changes: 0 additions & 3 deletions examples/aobench/benches/scanlines.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![feature(test)]

extern crate aobench_lib;

extern crate test;
use test::{black_box, Bencher};

#[bench]
Expand Down
3 changes: 0 additions & 3 deletions examples/aobench/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "ispc")]
extern crate ispc;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

Expand Down
12 changes: 6 additions & 6 deletions examples/aobench/src/ambient_occlusion.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Ambient Occlusion implementations

use geometry::{f32xN, Ray, RayxN, Selectable, V3DxN, V3D};
use intersection::{Intersect, Isect, IsectxN};
use scene::Scene;
use crate::geometry::{f32xN, Ray, RayxN, Selectable, V3DxN, V3D};
use crate::intersection::{Intersect, Isect, IsectxN};
use crate::scene::Scene;
use std::f32::consts::PI;

/// Scalar ambient occlusion algorithm
Expand Down Expand Up @@ -128,11 +128,11 @@ pub fn vector_tiled<S: Scene>(scene: &mut S, isect: &IsectxN) -> f32xN {
#[cfg(test)]
mod tests {
use super::*;
use geometry::V3D;
use crate::geometry::V3D;

#[test]
fn sanity_hit() {
let scene = ::scene::Test::default();
let scene = crate::scene::Test::default();
let mut scene_scalar = scene.clone();
let mut scene_vector = scene.clone();
let ray = Ray {
Expand All @@ -159,7 +159,7 @@ mod tests {

#[test]
fn sanity_miss() {
let scene = ::scene::Test::default();
let scene = crate::scene::Test::default();
let mut scene_scalar = scene.clone();
let mut scene_vector = scene.clone();

Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/geometry/plane.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Plane

use geometry::V3D;
use crate::geometry::V3D;

#[derive(Copy, Clone, Debug)]
pub struct Plane {
Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/geometry/ray.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A ray

use geometry::V3D;
use crate::geometry::V3D;

/// Ray starting at `origin` in `dir` direction.
#[derive(Copy, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/geometry/rayxN.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Four packed rays

use geometry::{Ray, V3DxN};
use crate::geometry::{Ray, V3DxN};

/// Four packed rays starting at `origin` in `dir` direction.
#[derive(Copy, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/geometry/sphere.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Sphere

use geometry::V3D;
use crate::geometry::V3D;

#[derive(Copy, Clone, Debug)]
pub struct Sphere {
Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/geometry/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Mul<V3D> for M3x3 {
/// Vector dot product
pub trait Dot<O> {
type Output;
fn dot(self, O) -> Self::Output;
fn dot(self, _: O) -> Self::Output;
}

impl Dot<V3D> for V3D {
Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/geometry/vecxN.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::ops::*;

use geometry::{f32xN, m32xN, Dot, M3x3, V3D};
use crate::geometry::{f32xN, m32xN, Dot, M3x3, V3D};

#[derive(Copy, Clone, Debug)]
pub struct V3DxN {
Expand Down
4 changes: 2 additions & 2 deletions examples/aobench/src/intersection/packet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! SIMD intersection result

use geometry::{f32xN, m32xN, V3DxN};
use intersection::Isect;
use crate::geometry::{f32xN, m32xN, V3DxN};
use crate::intersection::Isect;

/// Intersection result
#[derive(Copy, Clone, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions examples/aobench/src/intersection/ray_plane.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Intersection of a ray with a plane

use geometry::{f32xN, Dot, Plane, Ray, RayxN, Selectable};
use intersection::{Intersect, Isect, IsectxN};
use crate::geometry::{f32xN, Dot, Plane, Ray, RayxN, Selectable};
use crate::intersection::{Intersect, Isect, IsectxN};

// Scalar ray-plane intersection
impl Intersect<Plane> for Ray {
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Intersect<Plane> for RayxN {
#[cfg(test)]
mod tests {
use super::*;
use geometry::{m32xN, V3DxN, V3D};
use crate::geometry::{m32xN, V3DxN, V3D};

#[test]
fn sanity() {
Expand Down
6 changes: 3 additions & 3 deletions examples/aobench/src/intersection/ray_sphere.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Intersection of a ray with a sphere.

use geometry::{f32xN, Dot, Ray, RayxN, Selectable, Sphere};
use intersection::{Intersect, Isect, IsectxN};
use crate::geometry::{f32xN, Dot, Ray, RayxN, Selectable, Sphere};
use crate::intersection::{Intersect, Isect, IsectxN};

// Scalar ray-sphere intersection
impl Intersect<Sphere> for Ray {
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Intersect<Sphere> for RayxN {
#[cfg(test)]
mod tests {
use super::*;
use geometry::{m32xN, V3DxN, V3D};
use crate::geometry::{m32xN, V3DxN, V3D};

#[test]
fn sanity() {
Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/intersection/single.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Scalar intersection result

use geometry::V3D;
use crate::geometry::V3D;

/// Intersection result
#[derive(Copy, Clone, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions examples/aobench/src/ispc_.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Includes the ISPC implementations.
use *;
use crate::*;

ispc_module!(aobench);

pub fn ao<S: Scene>(_scene: &mut S, nsubsamples: usize, img: &mut ::Image) {
pub fn ao<S: Scene>(_scene: &mut S, nsubsamples: usize, img: &mut crate::Image) {
let (w, h) = img.size();
unsafe {
aobench::ao_ispc(
Expand All @@ -18,7 +18,7 @@ pub fn ao<S: Scene>(_scene: &mut S, nsubsamples: usize, img: &mut ::Image) {
pub fn ao_tasks<S: Scene>(
_scene: &mut S,
nsubsamples: usize,
img: &mut ::Image,
img: &mut crate::Image,
) {
let (w, h) = img.size();
unsafe {
Expand Down
12 changes: 1 addition & 11 deletions examples/aobench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Based on [aobench](https://code.google.com/archive/p/aobench/) by Syoyo
//! Fujita.
#![deny(warnings)]
#![deny(warnings, rust_2018_idioms)]
#![allow(non_snake_case, non_camel_case_types)]
#![cfg_attr(feature = "cargo-clippy", feature(tool_lints))]
#![cfg_attr(
Expand All @@ -19,16 +19,6 @@
)
)]

#[macro_use]
extern crate cfg_if;
extern crate failure;
extern crate packed_simd;
extern crate png;
extern crate rayon;
#[cfg(feature = "ispc")]
#[macro_use]
extern crate ispc;

pub mod ambient_occlusion;
pub mod geometry;
pub mod image;
Expand Down
6 changes: 1 addition & 5 deletions examples/aobench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
//!
//! Based on [aobench](https://code.google.com/archive/p/aobench/) by Syoyo
//! Fujita.
#![deny(warnings)]

extern crate aobench_lib;
extern crate structopt;
extern crate time;
#![deny(warnings, rust_2018_idioms)]

use aobench_lib::*;
use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion examples/aobench/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub mod scalar {

/// Vector pseudo random number generator
pub mod vector {
use geometry::{f32xN, u32xN, IncrV};
use crate::geometry::{f32xN, u32xN, IncrV};
use std::cell::UnsafeCell;
use std::rc::Rc;
struct RngT(u32xN, u32xN, u32xN, u32xN);
Expand Down
Loading

0 comments on commit 1e725f1

Please sign in to comment.