zz
This commit is contained in:
parent
800eb68134
commit
f993b9d7ec
7 changed files with 115 additions and 19 deletions
19
assignment-1c/Cargo.lock
generated
19
assignment-1c/Cargo.lock
generated
|
@ -4,9 +4,9 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.68"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
|
||||
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
|
@ -24,6 +24,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"base64",
|
||||
"clap",
|
||||
"csci5607-macros",
|
||||
"derivative",
|
||||
"nalgebra",
|
||||
"num",
|
||||
|
@ -150,6 +151,16 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csci5607-macros"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derivative"
|
||||
version = "2.2.0"
|
||||
|
@ -478,9 +489,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.50"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
|
|
@ -4,6 +4,9 @@ authors = ["Michael Zhang <zhan4854@umn.edu>"]
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[workspace]
|
||||
members = ["csci5607-macros"]
|
||||
|
||||
# For profiling with flamegraphs
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
@ -22,6 +25,7 @@ path = "src/main.rs"
|
|||
anyhow = "1.0.68"
|
||||
base64 = "0.21.0"
|
||||
clap = { version = "4.1.4", features = ["cargo", "derive"] }
|
||||
csci5607-macros = { path = "./csci5607-macros" }
|
||||
derivative = "2.2.0"
|
||||
nalgebra = "0.32.1"
|
||||
num = { version = "0.4.0", features = ["serde"] }
|
||||
|
|
13
assignment-1c/csci5607-macros/Cargo.toml
Normal file
13
assignment-1c/csci5607-macros/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "csci5607-macros"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.69"
|
||||
proc-macro2 = "1.0.51"
|
||||
quote = "1.0.23"
|
||||
syn = "1.0.107"
|
65
assignment-1c/csci5607-macros/src/lib.rs
Normal file
65
assignment-1c/csci5607-macros/src/lib.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
#[macro_use]
|
||||
extern crate anyhow;
|
||||
|
||||
use anyhow::Result;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
use syn::{Data, DataStruct, DeriveInput, Field};
|
||||
|
||||
#[proc_macro_derive(Csci5607Parser)]
|
||||
pub fn derive_answer_fn(tokens: TokenStream) -> TokenStream {
|
||||
let tokens: TokenStream2 = tokens.into();
|
||||
match derive_answer_fn_impl(tokens) {
|
||||
Ok(v) => v.into(),
|
||||
Err(e) => {
|
||||
eprintln!("Error: {e}");
|
||||
panic!("{e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_answer_fn_impl(tokens: TokenStream2) -> Result<TokenStream2> {
|
||||
let derive_input: DeriveInput = syn::parse2(tokens)?;
|
||||
|
||||
// Only defined on structs
|
||||
let struct_input: DataStruct = match derive_input.data {
|
||||
Data::Struct(v) => v,
|
||||
_ => bail!("Only defined on structs."),
|
||||
};
|
||||
let struct_ident = derive_input.ident;
|
||||
|
||||
// Gather struct fields
|
||||
let mut initializers = TokenStream2::default();
|
||||
let mut final_constructor = TokenStream2::default();
|
||||
for field in struct_input.fields {
|
||||
let field_ident = field.ident;
|
||||
initializers.extend(quote! { let #field_ident = todo!(); });
|
||||
final_constructor.extend(quote! { #field_ident, });
|
||||
|
||||
// Check if this field is a vec
|
||||
}
|
||||
|
||||
Ok(
|
||||
quote! {
|
||||
impl std::str::FromStr for #struct_ident {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#initializers
|
||||
|
||||
for line in contents.lines() {
|
||||
let mut parts = line.split_whitespace();
|
||||
let keyword = match parts.next() {
|
||||
Some(v) => v,
|
||||
None => continue,
|
||||
};
|
||||
}
|
||||
|
||||
Ok(#struct_ident { #final_constructor })
|
||||
}
|
||||
}
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
}
|
|
@ -5,12 +5,13 @@ pub mod input_file;
|
|||
pub mod sphere;
|
||||
|
||||
use nalgebra::Vector3;
|
||||
use csci5607_macros::Csci5607Parser;
|
||||
|
||||
use crate::{image::Color, Point};
|
||||
|
||||
use self::data::{Attenuation, DepthCueing, Light, Material, Object};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Csci5607Parser)]
|
||||
pub struct Scene {
|
||||
pub eye_pos: Vector3<f64>,
|
||||
pub view_dir: Vector3<f64>,
|
||||
|
|
24
flake.lock
24
flake.lock
|
@ -6,11 +6,11 @@
|
|||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1674240251,
|
||||
"narHash": "sha256-AVMmf/CtcGensTZmMicToDpOwySEGNKYgRPC7lu3m8w=",
|
||||
"lastModified": 1676907239,
|
||||
"narHash": "sha256-x/NG2pzLef1e8aXQfAwKECYYF0+lAQu+MD+Z0PtIJX4=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "d8067f4d1d3d30732703209bec5ca7d62aaececc",
|
||||
"rev": "c3f4f35c2add975dd1f40a07cfbb758a049b20d2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -21,11 +21,11 @@
|
|||
},
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1667395993,
|
||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||
"lastModified": 1676283394,
|
||||
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -35,11 +35,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1673796341,
|
||||
"narHash": "sha256-1kZi9OkukpNmOaPY7S5/+SlCDOuYnP3HkXHvNDyLQcc=",
|
||||
"lastModified": 1676721149,
|
||||
"narHash": "sha256-mN2EpTGxxVNnFZLoLWRwh6f7UWhXy4qE+wO2CZyrXps=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "6dccdc458512abce8d19f74195bb20fdb067df50",
|
||||
"rev": "5f4e07deb7c44f27d498f8df9c5f34750acf52d2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -73,11 +73,11 @@
|
|||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1674162026,
|
||||
"narHash": "sha256-iY0bxoVE7zAZmp0BB/m5hZW5pWHUfgntDvc1m2zyt/U=",
|
||||
"lastModified": 1676584162,
|
||||
"narHash": "sha256-8h0sV0fmMSB7KydJJD5Iz1kJxR3YzYa3iJ71VD2zePk=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "6e52c64031825920983515b9e975e93232739f7f",
|
||||
"rev": "a6603fc21d50b3386a488c96225b2d1fd492e533",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -9,12 +9,15 @@
|
|||
overlays = [ fenix.overlays.default ];
|
||||
};
|
||||
|
||||
toolchain = pkgs.fenix.stable;
|
||||
# toolchain = pkgs.fenix.stable;
|
||||
toolchain = pkgs.fenix.complete;
|
||||
in rec {
|
||||
devShell = pkgs.mkShell {
|
||||
packages = (with pkgs; [
|
||||
|
||||
cargo-deny
|
||||
cargo-edit
|
||||
cargo-expand
|
||||
cargo-flamegraph
|
||||
cargo-watch
|
||||
imagemagick
|
||||
|
@ -23,7 +26,6 @@
|
|||
texlive.combined.scheme-full
|
||||
unzip
|
||||
zip
|
||||
|
||||
(python310.withPackages (p: with p; [ numpy ]))
|
||||
]) ++ (with toolchain; [
|
||||
cargo
|
||||
|
|
Loading…
Reference in a new issue