Skip to content

Conversation

@hannydevelop
Copy link

Hey, @elpiel can you take a look at this PR and give comments on what needs improvement? The other two should be ready by the end of today.

Copy link
Member

@elpiel elpiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good progress!
There are a few minor things and a couple of general I'm going to mention here:

  • All structs should be renamed, since they all, by default, start with capital letters (it's a serde/serde_xml impl detail)
  • All fields & structs must be pub
  • I've realised that I've forgotten to add the default values as a documentation, so make sure to include this as well in the docs.
  • Can you also add tests please?
    You can add a raw string of xml deserialized into a struct which will also check for the default values. So the xml won't have the values set but you will expect them in the resulting deserialize struct.

#[derive(Debug, Serialize, Deserialize)]
pub struct Light {}
pub struct Light {
// A unique name for the light
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please use doc comments /// so that the information shows in the documentation.

pub struct Light {
// A unique name for the light
name: String,
// The light type: point, directional spot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • there is a missing comma point, directional, spot

// A unique name for the light
name: String,
// The light type: point, directional spot
#[serde(default)]
Copy link
Member

@elpiel elpiel Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The default should be set up using serde.
  • Use an Enum since the available options are only 3 point, directional, spot
    You might need to use https://crates.io/crates/parse-display for this. I'm not aware how Enums with no data are deserialized so you have to double-check this.
  • Make sure to rename the light_type to type with an serde attribute

cast_shadows: Option<bool>,
// Scale factor to set the relative power of a light
#[serde(default)]
intensity: Option<f64>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The default for this value is 1, right now with serde(default) it is None.

Comment on lines +199 to +202
diffuse: Option<Color>,
// Specular light color
#[serde(default)]
specular: Option<Color>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please add default functions that set the correct values for diffuse (1 1 1 1) & specular (0.1 0.1 0.1 1). This could be achieved by adding associated functions to Color for the default values, like Color::specular_default()

attenuation: Vec<Attenuation>,
// Direction of light, only applicable for spot and directional light
#[serde(default)]
direction: Vec<i32>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vec3 actually means a mathematical vector.
You can use a tuple struct and eventually we might use something like nalgebra's structs but this is not required for the moment

https://docs.rs/nalgebra/0.29.0/nalgebra/base/type.Vector3.html

  • Please add proper default.

Comment on lines +218 to +238
pub struct Attenuation {
range: f64,
linear: Option<f64>,
constant: Option<f64>,
quadratic: Option<f64>,
}

// Spot light parameters
pub struct Spot {
inner_angle: f64,
outer_angle: f64,
falloff: f64,
}

// A position and orientation with respect to the frame named in relative_to attribute
pub struct Pose {
relative_to: Option<String>,
}

// Unit struct for tpe `color`
struct Color(u8, u8, u8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • structs are missing the documentation of the fields.
  • derive Debug, Deser. & Ser.


// A position and orientation with respect to the frame named in relative_to attribute
pub struct Pose {
relative_to: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Pose has value as well
    <pose relative_to="...">value</pose>

@elpiel
Copy link
Member

elpiel commented Oct 3, 2021

I found an example of how to force attributes (will be done in future PRs though as it requires a lot of enums) and use an enum for light_type field:

#[derive(Debug, Serialize, Deserialize, PartialEq)]
enum PitchType { FourSeam, TwoSeam, Changeup, Cutter, Curve, Slider, Knuckle, Pitchout }

You can see the documentation of serde_xml:
https://docs.rs/serde-xml-rs/0.5.1/serde_xml_rs/index.html#repeated-tags

@elpiel elpiel added the Hacktoberfest Issues suitable for Hacktoberfest label Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hacktoberfest Issues suitable for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants