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 Targeta cell or sheet as a value (GetRef, SheetRef(), SETATREF targets)sheet: SheetRef-- the sheetaddr: Option<CellAddr>-- the cell (None: the sheet itself)
enum Vala computed valueNum(f64)-- a number in internal units; also truth values (1, 0)Str(Rc<str>)-- a stringColor(Color)-- a colourPoint(f64, f64)-- a point (PNT, PAR, LOC)Err(CellError)-- an error valueThemed(Rc<Val>)-- a value that comes from the theme: V stores "Themed", formulas use the value insideShape(Rc<str>)-- a NURBS(...) or POLYLINE(...) result as V writes itFont(Rc<str>)-- a font (FONT("Calibri")): a Font cell stores the nameTarget(Target)-- a reference to a cell or sheetMissing-- an empty argument
enum Axiswhich coordinate of a point a cell takesX-- X, BeginX, PinX, LocPinX, TxtPinX, XDyn ... (also the default)Y-- Y, BeginY, PinY, YDyn ...
impl Axis
fn of(cell: &str) -> Axisthe axis of a cell name: Y when the name has a Y and no X
impl Val
fn bool(b: bool) -> Vala truth valuefn str(s: &str) -> Vala string valuefn plain(&self) -> &Valthe value without its Themed wrapperfn is_err(&self) -> boolwhether it is an error valuefn err(&self) -> Option<CellError>the error, if it is onefn from_value(value: Value, error: Option<&str>, strings: &Strings) -> Vala 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) -> Storedwhat V stores for this result in cellcell-> (V as text or number, error); None value: keep V as it isenum Storedwhat a result stores in VNum(f64)-- a numberText(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) -> boolwhether a stored V (with its E) equals this result: numbers withintolrelative (and 1e-12 absolute), texts exactly (colours in any case)fn close(a: f64, b: f64, tol: f64) -> boolwhether two numbers agree withintolrelative or 1e-12 absolute