Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Import

Export

Viewer

Camera Controller

Customizable Lights

Dimensioning Concept

Legend

UI Concept

Plugins

Packet Manager

Code Formatter

LSP Server

Completion

Go To References

Support More Editors

Language Features

Layers

Introspection

Result Type Declaration

For better diagnosis and better readability functions in microcad shall have return type declarations similar to Rust:

fn f() -> Integer { 1 }
fn f(n: Bool) -> Integer { "1" } // error

Project Structure

Tuple Matching

Enums & Match

E.g. simple enums can be useful when functions or workbenches have different modes:

enum Alignment {
    /// Do not align
    FIX,
    /// Align at left, top or front 
    NEAR,
    /// Align at center
    CENTER
    /// ALign at right, bottom or back
    FAR,
}

Those may then be used in if statements:

// get X, Y, Z
use std::math::*

op align(axis: Vec3, align: Alignment ) {
    if align == Alignment::FIX {
        ...
    } else if align == Alignment::NEAR {
        ...
    } ...
}

s.align(X, CENTER).align(Y, FAR);

Consequences

The enum type will be the first user defined type. This must be integrated in our static type system.

Match

Having enums leads to wanting a match statement:

match align {
    Alignment::FIX => ...,
    Alignment::NEAR => ...,
    Alignment::CENTER => ...,
    Alignment::FAR => ...,
}

Consequences

The match statement alone is a big syntax construct that should be made to make enums most effective. A check of all enum variants are used within a match might be quite easy with enums but then must also be done with other types. These must have a possibility to match other cases or different patterns, similar to Rust:

a = 1;
match a {
    1 => ...,
    2..3 => ...,
    4.. => ...,
    _ => ...,
}

Paths

Paths are define a Line in a sketch or part.

They can be made out of arrays:

// three point 2D path
p = [(0mm,0mm),(1mm,0mm),(1mm,1mm)];

Additionally a function can define the path. In this case we need a new syntax construct which addresses the different parameters:

path spiral(radius: Length, pitch: Scalar, turns: Scalar) {
    // will be the first `t`
    prop first = 0turns;
    // will be the last `t`
    prop last = turns * 1turn;
    // gets t and returns a coordinate
    fn eval(t: Angle) { (2mm*cos(t), 2,0mm* sin(t), pitch * t * 1,0mm) }
}
p = spiral(radius=2cm, pitch=0.5, turns=1.0);

// `p` can be used to generate points for the path at any desired resolution
p(resolution = 0.5turns);
// or just with a list of values
p([0.0, 0.5, 1.0]turns);

Both calls of p will generate an array of points which lay on the given path p.

This construct may need some more syntactic sugar which is open to discussion.

Assembly Benches

Currently µcad produces 2D sketches and 3D parts. We would like to create another abstraction layer above sketches & parts: assembly benches Assembly benches put together parts. You may put a screw into a screw thread (maybe with constrains?) or assemble a case which is made out of several parts. Also you may use connectors and joints (from specialized libraries) to put them together.

Materials

Addressing of Corners & Edges

The idea behind this is that we can identify corners and edges by the viewer which automatically displays stable names for all edges or corners of a model so you can use them within the code.

use std::geo2d::*;
Rect(10cm).corner(a).round(1mm);  // round one corner
Rect(10cm).edge(a).fillet(1mm); // create a fillet at one edge

This might also be done with multiplicity:

use std::geo2d::*;
Rect(10cm).corner([a,b]).round(1mm);  // round two corners
Rect(10cm).edge([a..c]).fillet(1mm); // create a fillet at three edges

Consequences

It will be hard to stick the names to edges so that the relation fixed.

Test List