Skip to content

Add error checking for other serializable objects #23

@connorkuehl

Description

@connorkuehl

MoirePrimitive and PolygonPrimitive enforce their invariants when they're being serialized.

Like this:

impl<W: Write> PartialGerberCode<W> for PolygonPrimitive {
    fn serialize_partial(&self, writer: &mut W) -> GerberResult<()> {
        // Vertice count invariants
        if self.vertices < 3 {
            return Err(GerberError::MissingDataError("There must be at least 3 vertices in a polygon".into()));
        }
        if self.vertices > 12 {
            return Err(GerberError::RangeError("The maximum number of vertices in a polygon is 12".into()));
        }
        if self.diameter.is_negative() {
            return Err(GerberError::RangeError("The diameter must not be negative".into()));
        }

Other types (like VectorLinePrimitive, etc.) should do this too 😃

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions