Skip to content

Working on the Light Struct#2

Open
hannydevelop wants to merge 1 commit into
AeroRust:mainfrom
hannydevelop:main
Open

Working on the Light Struct#2
hannydevelop wants to merge 1 commit into
AeroRust:mainfrom
hannydevelop:main

Conversation

@hannydevelop

Copy link
Copy Markdown

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.

@elpiel elpiel left a comment

Copy link
Copy Markdown
Member

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.

Comment thread sdformat/src/lib.rs
#[derive(Debug, Serialize, Deserialize)]
pub struct Light {}
pub struct Light {
// A unique name for the light

Copy link
Copy Markdown
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.

Comment thread sdformat/src/lib.rs
pub struct Light {
// A unique name for the light
name: String,
// The light type: point, directional spot

Copy link
Copy Markdown
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

Comment thread sdformat/src/lib.rs
// A unique name for the light
name: String,
// The light type: point, directional spot
#[serde(default)]

@elpiel elpiel Oct 2, 2021

Copy link
Copy Markdown
Member

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

Comment thread sdformat/src/lib.rs
cast_shadows: Option<bool>,
// Scale factor to set the relative power of a light
#[serde(default)]
intensity: Option<f64>,

Copy link
Copy Markdown
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 thread sdformat/src/lib.rs
Comment on lines +199 to +202
diffuse: Option<Color>,
// Specular light color
#[serde(default)]
specular: Option<Color>,

Copy link
Copy Markdown
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()

Comment thread sdformat/src/lib.rs
attenuation: Vec<Attenuation>,
// Direction of light, only applicable for spot and directional light
#[serde(default)]
direction: Vec<i32>,

Copy link
Copy Markdown
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 thread sdformat/src/lib.rs
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
Copy Markdown
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.

Comment thread sdformat/src/lib.rs

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

Copy link
Copy Markdown
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

elpiel commented Oct 3, 2021

Copy link
Copy Markdown
Member

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