Skip to content

Improve ergonomics of working with powers of base values #542

@sww1235

Description

@sww1235

I have a project where I need to calculate the square of a Length value without turning it into an Area.

The code I have written currently is simplified as follows:

fn calc_score(ideal_width: Length, line_length: Length) -> Length{

let mut score = (ideal_width - line_length);
score.value = score.value * score.value;
score
}

As you can see, I need to square the value of the unit, without changing the unit.

Is the way I accomplished this, the best way currently, or is there something I am missing within the documentation that will let me accomplish this in a more ergonomic way.

Thanks!


Score is used in a paragraph breaking algorithm which is why it is technically a length.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions