public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 1) { throw new InvalidOperationException("toString must be called with 1 arg!"); } if (args[0] is VecInt valueI) { return(new VecString(valueI.Value.ToString())); } else if (args[0] is VecFloat valueF) { return(new VecString(valueF.Value.ToString())); } else if (args[0] is VecBool valueB) { return(new VecString(valueB.Value.ToString())); } else if (args[0] is VecString valueS) { return(valueS); } else { throw new InvalidOperationException("toString: null not supported!"); } }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 2) { throw new InvalidOperationException("setup must be called with 2 args!"); } if (args[0] is VecInt width) { if (args[1] is VecInt height) { context.AddSvgStart(width, height); } else { throw new InvalidOperationException("setup: height must be int!"); } } else { throw new InvalidOperationException("setup: width must be int!"); } return(VecNull.Value); }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 1) { throw new InvalidOperationException("length must be called with one argument!"); } if (args[0] is IVecContainer container) { return(new VecInt(container.Size)); } else { throw new InvalidOperationException("length: value must be an array!"); } }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 1) { throw new InvalidOperationException("toString must be called with 1 arg!"); } if (args[0].TryConvertToFloat(out var value)) { return(new VecFloat((float)Math.Sqrt(value.Value))); } else { throw new InvalidOperationException("sqrt: value must be int or float!"); } }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 1) { throw new InvalidOperationException("setStroke must be called with 1 arg!"); } if (args[0] is VecString color) { context.SetStyle(stroke: color.Value); } else { throw new InvalidOperationException("setStroke: color must be string!"); } return(VecNull.Value); }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 1) { throw new InvalidOperationException("setFontSize must be called with 1 arg!"); } if (args[0] is VecInt size) { context.SetStyle(fontSize: size.Value); } else { throw new InvalidOperationException("setFontSize: size must be int!"); } return(VecNull.Value); }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 1) { throw new InvalidOperationException("setStrokeWidth must be called with 1 arg!"); } if (args[0].TryConvertToFloat(out var width)) { context.SetStyle(strokeWidth: width.Value); } else { throw new InvalidOperationException("setStrokeWidth: width must be int or float!"); } return(VecNull.Value); }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 4) { throw new InvalidOperationException("line must be called with 4 args!"); } if (args[0].TryConvertToFloat(out var x1)) { if (args[1].TryConvertToFloat(out var y1)) { if (args[2].TryConvertToFloat(out var x2)) { if (args[3].TryConvertToFloat(out var y2)) { context.AddSvgElement("line", includeStyleAttrs: true, ("x1", x1), ("y1", y1), ("x2", x2), ("y2", y2) ); } else { throw new InvalidOperationException("line: y2 must be int or float!"); } } else { throw new InvalidOperationException("line: x2 must be int or float!"); } } else { throw new InvalidOperationException("line: y1 must be int or float!"); } } else { throw new InvalidOperationException("line: x1 must be int or float!"); } return(VecNull.Value); }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 3) { throw new InvalidOperationException("text must be called with 3 args!"); } if (args[0].TryConvertToFloat(out var x)) { if (args[1].TryConvertToFloat(out var y)) { if (args[2] is VecString text) { context.AddSvgElement("text", includeStyleAttrs: true, content: text, ("x", x), ("y", y) ); } else { throw new InvalidOperationException("text: text must be string!"); } } else { throw new InvalidOperationException("text: y must be int!"); } } else { throw new InvalidOperationException("text: x must be int!"); } return(VecNull.Value); }
public override IVecValue Call(IVecValue[] args, BuiltInFunctionContext context) { if (args.Length != 3) { throw new InvalidOperationException("circle must be called with 3 args!"); } if (args[0].TryConvertToFloat(out var cx)) { if (args[1].TryConvertToFloat(out var cy)) { if (args[2].TryConvertToFloat(out var radius)) { context.AddSvgElement("circle", includeStyleAttrs: true, ("cx", cx), ("cy", cy), ("r", radius) ); } else { throw new InvalidOperationException("circle: radius must be int or float!"); } } else { throw new InvalidOperationException("circle: cy must be int or float!"); } } else { throw new InvalidOperationException("circle: cx must be int or float!"); } return(VecNull.Value); }