Basic Class Structure

Basic Class Structure#

C++ Classes#

@startuml classes_cpp

package func_sketch {
    class Real <<typedef>> {
        using Real = double
    }

    class Complex <<typedef>> <<future-implementation>> {
        using Complex = std::complex<double>
    }

    class Integer <<typedef>> {
        using Integer = int32_t
    }

    class Number <<typedef>> {
        using Number = std::variant<Integer, Real, Complex>
    }

    enum ParameterType <<future-implementation>> {
        x
        t
    }

    package utilities {
        class Any {
            + Any(object : T)
            + get<T>() : const T&
        }
    }

    package math {
        class UnaryOperator {
            + operator()(arg : Number, result : Number&)
        }
        UnaryOperator o-- Any

        class BinaryOperator {
            + operator()(left : Number, right : Number, result : Number&)
        }
        BinaryOperator o-- Any

        class MathFunction {
            + operator()(args : std::vector<Number>, result : Number&)
        }
        MathFunction o-- Any

        class MathFunctionList {
            + emplace(function : MathFunction)
            + get(name : std::string) : std::optional<MathFunction>
        }
        MathFunctionList o-- MathFunction

        class ConstantList {
            + emplace(name : std::string, value : Number)
            + get(name : std::string) : std::optional<Number>
        }

        note as math_functions_note
            Actual mathematical functions and operators
            are implemented here too.
        end note
    }

    package expressions {
        class Expression {
            - expression_ : std::variant<ConstantExpression, ParameterExpression, UnaryExpression, BinaryExpression, FunctionCallExpression>
        }

        struct ConstantExpression {
            + value : Number
        }
        Expression <..> ConstantExpression

        struct ParameterExpression {
            + type : ParameterType
        }
        Expression <..> ParameterExpression
        ParameterExpression o-- ParameterType

        struct UnaryExpression {
            + target : Expression*
            + operator_object : UnaryOperator
        }
        Expression <..> UnaryExpression
        UnaryExpression o-- UnaryOperator

        struct BinaryExpression {
            + left : Expression*
            + right : Expression*
            + operator_object : BinaryOperator
        }
        Expression <..> BinaryExpression
        BinaryExpression o-- BinaryOperator

        struct FunctionCallExpression {
            + arguments : std::vector<Expression*>
            + function : MathFunction
        }
        Expression <..> FunctionCallExpression
        FunctionCallExpression o-- MathFunction

        class ExpressionMemoryPool {
            + create<T>(args...) : Expression*
        }
        ExpressionMemoryPool ..> Expression

        class ExpressionEvaluator {
            + operator()(expression : const Expression&, parameter : Real, result : Real&)
        }

        class ExpressionPtr
        ExpressionPtr o-- Expression
        ExpressionPtr o-- ExpressionMemoryPool
    }

    package parser {
        class ExpressionParser {
            + operator()(expression_str : std::string) : ExpressionPtr
        }
        ExpressionParser o-- MathFunctionList
        ExpressionParser o-- ConstantList
        ExpressionParser ..> ExpressionPtr
    }

    package plotter {
        struct RGBColor {
            + r : uint8_t
            + g : uint8_t
            + b : uint8_t
        }

        struct Point {
            + x : Real
            + y : Real
        }

        class Image <<typedef>> {
            using Image = cv::Mat
        }

        class PlotRange {
            + x_range() : std::pair<Real, Real>
            + y_range() : std::pair<Real, Real>
        }

        struct PlotConfig

        class FunctionSampler {
            + range(value : PlotRange)
            + config(value : PlotConfig)
            + operator()(function : ExpressionPtr) : std::vector<Point>
        }
        FunctionSampler o-- PlotRange
        FunctionSampler o-- PlotConfig
        FunctionSampler ...> ExpressionPtr
        FunctionSampler ..> Point

        class Plotter {
            + range(value : PlotRange)
            + config(value : PlotConfig)
            + write_background(image : Image&)
            + write_curve(samples : std::vector<Point>, color : RGBColor, image : Image&)
        }
        Plotter o-- PlotRange
        Plotter o-- PlotConfig
        Plotter ..> Point
        Plotter ..> RGBColor
        Plotter ..> Image
    }
}

@enduml

Python Classes#

@startuml classes_python

package func_sketch {
    package _cpp {
        class Expression

        class ExpressionParser {
            + __call__(expression_str: str) : Expression
        }
        ExpressionParser ..> Expression

        class RGBColor {
            + r : int
            + g : int
            + b : int
        }

        class Point {
            + x : float
            + y : float
        }

        class PointList {
            + points : List[Point]
        }
        PointList ..> Point

        class PlotRange {
            + x_range : tuple[float, float]
            + y_range : tuple[float, float]
        }

        class PlotConfig

        class FunctionSampler {
            + __init__(range: PlotRange, config: PlotConfig)
            + range : PlotRange
            + config : PlotConfig
            + __call__(function: Expression) : PointList
        }
        FunctionSampler o-- PlotRange
        FunctionSampler o-- PlotConfig
        FunctionSampler ..> Expression
        FunctionSampler ..> PointList

        class Plotter {
            + __init__(range: PlotRange, config: PlotConfig)
            + range : PlotRange
            + config : PlotConfig
            + write_background(image: numpy.ndarray)
            + write_curve(samples: PointList, color: RGBColor, image: numpy.ndarray)
        }
        Plotter o-- PlotRange
        Plotter o-- PlotConfig
        Plotter ..> PointList
        Plotter ..> RGBColor
    }

    package _impl {
        class CurveConfig {
            + function_expression_str : str
            + color : RGBColor
        }
        CurveConfig o-- RGBColor

        class SampledCurve {
            + samples : PointList
            + color : RGBColor
        }
        SampledCurve o-- PointList
        SampledCurve o-- RGBColor

        class CurveSampler {
            + __init__(plot_range: PlotRange, config: PlotConfig)
            + plot_range : PlotRange
            + config : PlotConfig
            + __call__(curve_config: CurveConfig) : SampledCurve
        }
        CurveSampler o-- ExpressionParser
        CurveSampler o-- FunctionSampler
        CurveSampler ..> CurveConfig
        CurveSampler ..> SampledCurve

        class Plotter {
            + __init__(plot_range: PlotRange, config: PlotConfig)
            + plot_range : PlotRange
            + config : PlotConfig
            + __call__(sampled_curves: list[SampledCurve], image: numpy.ndarray)
        }
        Plotter o-- func_sketch._cpp.Plotter
        Plotter ..> SampledCurve
    }
}

func_sketch._impl .[hidden].. func_sketch._cpp

@enduml