JFLib

diagram_core/src/formula/val.rs#

Source: lib/diagram_core/src/formula/val.rs

val -- what a formula computes: typed values and how they meet cells (FX-02)

  Val::Num(f64)              a number in internal units (inches, radians, days); TRUE is 1
  Val::Str / Color / Point / Err / Themed / Shape / Font / Target / Missing
  val.to_cell(cell name) -> (Value, Option<CellError>) text   what V stores for it
  Val::from_value(value, error, strings)   a stored V read back as a Val

The stored forms (as Visio writes V): numbers as numbers, an RGB colour "#rrggbb", a colour
index as a number, a theme result "Themed", NURBS(...)/POLYLINE(...) as their text, a point
as its X or Y depending on the cell (PNT in BeginX gives x), strings as they are.  An error
leaves V alone and sets E.
  • struct Target a cell or sheet as a value (GetRef, SheetRef(), SETATREF targets)

    • sheet: SheetRef -- the sheet
    • addr: Option<CellAddr> -- the cell (None: the sheet itself)
  • enum Val a computed value

    • Num(f64) -- a number in internal units; also truth values (1, 0)
    • Str(Rc<str>) -- a string
    • Color(Color) -- a colour
    • Point(f64, f64) -- a point (PNT, PAR, LOC)
    • Err(CellError) -- an error value
    • Themed(Rc<Val>) -- a value that comes from the theme: V stores "Themed", formulas use the value inside
    • Shape(Rc<str>) -- a NURBS(...) or POLYLINE(...) result as V writes it
    • Font(Rc<str>) -- a font (FONT("Calibri")): a Font cell stores the name
    • Target(Target) -- a reference to a cell or sheet
    • Missing -- an empty argument
  • enum Axis which coordinate of a point a cell takes

    • X -- X, BeginX, PinX, LocPinX, TxtPinX, XDyn ... (also the default)
    • Y -- Y, BeginY, PinY, YDyn ...

impl Axis

  • fn of(cell: &str) -> Axis the axis of a cell name: Y when the name has a Y and no X

impl Val

  • fn bool(b: bool) -> Val a truth value

  • fn str(s: &str) -> Val a string value

  • fn plain(&self) -> &Val the value without its Themed wrapper

  • fn is_err(&self) -> bool whether it is an error value

  • fn err(&self) -> Option<CellError> the error, if it is one

  • fn from_value(value: Value, error: Option<&str>, strings: &Strings) -> Val a stored value read back (E set: the error; "Themed" stays text here, the engine computes what is behind it)

  • fn num(&self, axis: Axis) -> Result<f64, CellError> the number of a value for arithmetic (a point gives the axis' coordinate)

  • fn text(&self) -> Result<String, CellError> the text of a value (numbers in their shortest form, colours as "#rrggbb")

  • fn stored(&self, cell: &str) -> Stored what V stores for this result in cell cell -> (V as text or number, error); None value: keep V as it is

  • enum Stored what a result stores in V

    • Num(f64) -- a number
    • Text(String) -- a text ("#rrggbb", "Themed", a string, NURBS(...))
    • Error(CellError) -- an error: V stays, E is set

impl Stored

  • fn matches(&self, value: Value, error: Option<&str>, strings: &Strings, tol: f64) -> bool whether a stored V (with its E) equals this result: numbers within tol relative (and 1e-12 absolute), texts exactly (colours in any case)

  • fn close(a: f64, b: f64, tol: f64) -> bool whether two numbers agree within tol relative or 1e-12 absolute

Source: docs/API.md in the JFLib repository.