Skip to main content

CalcNode

Type Alias CalcNode 

Source
pub type CalcNode = GenericCalcNode<Leaf>;
Expand description

A calc node representation for specified values.

Aliased Type§

#[repr(u8)]
pub enum CalcNode {
Show 25 variants Leaf(Leaf), Negate(Box<GenericCalcNode<Leaf>>), Invert(Box<GenericCalcNode<Leaf>>), Sum(OwnedSlice<GenericCalcNode<Leaf>>), Product(OwnedSlice<GenericCalcNode<Leaf>>), MinMax(OwnedSlice<GenericCalcNode<Leaf>>, MinMaxOp), Clamp { min: Box<GenericCalcNode<Leaf>>, center: Box<GenericCalcNode<Leaf>>, max: Box<GenericCalcNode<Leaf>>, }, Round { strategy: RoundingStrategy, value: Box<GenericCalcNode<Leaf>>, step: Box<GenericCalcNode<Leaf>>, }, ModRem { dividend: Box<GenericCalcNode<Leaf>>, divisor: Box<GenericCalcNode<Leaf>>, op: ModRemOp, }, Sin(Box<GenericCalcNode<Leaf>>), Cos(Box<GenericCalcNode<Leaf>>), Tan(Box<GenericCalcNode<Leaf>>), Asin(Box<GenericCalcNode<Leaf>>), Acos(Box<GenericCalcNode<Leaf>>), Atan(Box<GenericCalcNode<Leaf>>), Atan2(Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>), Pow(Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>), Sqrt(Box<GenericCalcNode<Leaf>>), Hypot(OwnedSlice<GenericCalcNode<Leaf>>), Log(Box<GenericCalcNode<Leaf>>, Optional<Box<GenericCalcNode<Leaf>>>), Exp(Box<GenericCalcNode<Leaf>>), Abs(Box<GenericCalcNode<Leaf>>), Sign(Box<GenericCalcNode<Leaf>>), Anchor(Box<GenericAnchorFunction<Box<GenericCalcNode<Leaf>>, Box<GenericAnchorFunctionFallback<Leaf>>>>), AnchorSize(Box<GenericAnchorSizeFunction<Box<GenericAnchorFunctionFallback<Leaf>>>>),
}

Variants§

§

Leaf(Leaf)

A leaf node.

§

Negate(Box<GenericCalcNode<Leaf>>)

A node that negates its child, e.g. Negate(1) == -1.

§

Invert(Box<GenericCalcNode<Leaf>>)

A node that inverts its child, e.g. Invert(10) == 1 / 10 == 0.1. The child must always resolve to a number unit.

§

Sum(OwnedSlice<GenericCalcNode<Leaf>>)

A sum node, representing a + b + c where a, b, and c are the arguments.

§

Product(OwnedSlice<GenericCalcNode<Leaf>>)

A product node, representing a * b * c where a, b, and c are the arguments.

§

MinMax(OwnedSlice<GenericCalcNode<Leaf>>, MinMaxOp)

A min or max function.

§

Clamp

A clamp() function.

Fields

§min: Box<GenericCalcNode<Leaf>>

The minimum value.

§center: Box<GenericCalcNode<Leaf>>

The central value.

§max: Box<GenericCalcNode<Leaf>>

The maximum value.

§

Round

A round() function.

Fields

§strategy: RoundingStrategy

The rounding strategy.

§value: Box<GenericCalcNode<Leaf>>

The value to round.

§step: Box<GenericCalcNode<Leaf>>

The step value.

§

ModRem

A mod() or rem() function.

Fields

§dividend: Box<GenericCalcNode<Leaf>>

The dividend calculation.

§divisor: Box<GenericCalcNode<Leaf>>

The divisor calculation.

§op: ModRemOp

Is the function mod or rem?

§

Sin(Box<GenericCalcNode<Leaf>>)

A sin() function.

§

Cos(Box<GenericCalcNode<Leaf>>)

A cos() function.

§

Tan(Box<GenericCalcNode<Leaf>>)

A tan() function.

§

Asin(Box<GenericCalcNode<Leaf>>)

An asin() function.

§

Acos(Box<GenericCalcNode<Leaf>>)

An acos() function.

§

Atan(Box<GenericCalcNode<Leaf>>)

An atan() function.

§

Atan2(Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>)

An atan2() function.

§

Pow(Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>)

A pow() function.

§

Sqrt(Box<GenericCalcNode<Leaf>>)

A sqrt() function.

§

Hypot(OwnedSlice<GenericCalcNode<Leaf>>)

A hypot() function

§

Log(Box<GenericCalcNode<Leaf>>, Optional<Box<GenericCalcNode<Leaf>>>)

A log() function.

§

Exp(Box<GenericCalcNode<Leaf>>)

An exp() function.

§

Abs(Box<GenericCalcNode<Leaf>>)

An abs() function.

§

Sign(Box<GenericCalcNode<Leaf>>)

A sign() function.

§

Anchor(Box<GenericAnchorFunction<Box<GenericCalcNode<Leaf>>, Box<GenericAnchorFunctionFallback<Leaf>>>>)

An anchor() function.

§

AnchorSize(Box<GenericAnchorSizeFunction<Box<GenericAnchorFunctionFallback<Leaf>>>>)

An anchor-size() function.

Implementations§

Source§

impl CalcNode

Source

fn parse_one<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Tries to parse a single element in the expression, that is, a <length>, <angle>, <time>, <percentage>, <resolution>, etc.

May return a “complex” CalcNode, in the presence of a parenthesized expression, for example.

Source

pub fn parse<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Parse a top-level calc expression, with all nested sub-expressions.

This is in charge of parsing, for example, 2 + 3 * 100%.

Source

fn parse_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Source

fn parse_product<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Parse a top-level calc expression, and all the products that may follow, and stop as soon as a non-product expression is found.

This should parse correctly:

  • 2
  • 2 * 2
  • 2 * 2 + 2 (but will leave the + 2 unparsed).
Source

pub fn resolve_computed<F>( &self, context: Option<&Context<'_>>, leaf_to_output_fn: F, ) -> Result<Leaf, ()>
where F: Fn(&Leaf) -> Result<Leaf, ()>,

Resolves this calc tree into a leaf node, using the computed context if provided for any nodes that require it. Additional node mapping can be provided using leaf_to_output_fn. Returns Err(()) if the calc tree could not be resolved for any reason.

Source

pub fn into_length_or_percentage( self, clamping_mode: AllowedNumericType, ) -> Result<CalcLengthPercentage, ()>

Tries to simplify this expression into a <length> or <percentage> value.

Source

fn into_time(self, clamping_mode: AllowedNumericType) -> Result<CalcNumeric, ()>

Tries to simplify this expression into a <time> value.

Source

fn into_resolution(self) -> Result<CalcNumeric, ()>

Tries to simplify this expression into a <resolution> value.

Source

fn into_angle( self, clamping_mode: AllowedNumericType, ) -> Result<CalcNumeric, ()>

Tries to simplify this expression into a CalcNumeric value.

Source

fn into_number( self, clamping_mode: AllowedNumericType, ) -> Result<CalcNumeric, ()>

Tries to convert this expression into a CalcNumeric, keeping the AST for later evaluation at computed-value time.

Source

fn into_percentage( self, clamping_mode: AllowedNumericType, ) -> Result<CalcNumeric, ()>

Tries to convert this expression into a CalcNumeric, keeping the AST for later evaluation at computed-value time.

Source

pub fn math_function<'i>( _: &ParserContext<'_>, name: &CowRcStr<'i>, location: SourceLocation, ) -> Result<MathFunction, ParseError<'i>>

Given a function name, and the location from where the token came from, return a mathematical function corresponding to that name or an error.

Source

pub fn parse_length_or_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, allow_anchor: AllowAnchorPositioningFunctions, ) -> Result<CalcLengthPercentage, ParseError<'i>>

Convenience parsing function for <length> | <percentage>, and, optionally, anchor().

Source

pub fn parse_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<CalcNumeric, ParseError<'i>>

Convenience parsing function for percentages.

Source

pub fn parse_length<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<CalcLengthPercentage, ParseError<'i>>

Convenience parsing function for <length>.

Source

pub fn parse_number<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<CalcNumeric, ParseError<'i>>

Convenience parsing function for <number>.

Source

pub fn parse_angle<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CalcNumeric, ParseError<'i>>

Convenience parsing function for <angle>.

Source

pub fn parse_time<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<CalcNumeric, ParseError<'i>>

Convenience parsing function for <time>.

Source

pub fn parse_resolution<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CalcNumeric, ParseError<'i>>

Convenience parsing function for <resolution>.