Skip to content
Daynlight edited this page Dec 13, 2025 · 1 revision

Math Library (MathLib)

Graphite includes a built-in math library for 2D/3D visualization and scripting. It provides essential types and functions for geometry, plotting, and mathematical operations.

TOC

Main Classes

Point

Point class is used inside script for drawing single point. It is than added to plot.

namespace Graphite::Math {
	class Point {
		Point(std::array<float, 2> pos, std::array<float, 3> color);
		std::array<float, 2> getPos();
		void setPos(std::array<float, 2> pos);
		std::array<float, 3> getColor();
		void setColor(std::array<float, 3> color);
	};
};

Main Features

  • 2D/3D point representation.
  • Color management for points.

Plot2D

Plot is our 2D canvas where we draw elements. We add others Math classes to cells.

namespace Graphite::Math{
class Plot2D{
public:
  std::unordered_map<std::string, Graphite::Math::Point> point_cell;

private:
  void drawPoint(Graphite::Math::Point point);

public:
  Plot2D();
  ~Plot2D();

  void draw();

};
};

Main Features

  • Creating plot and adding points.

Example Usage

// Graphite
// Copyright 2025 Daynlight
// Licensed under the Apache License, Version 2.0.
// See LICENSE file for details.


#define  BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.h>

#include <stdio.h>
#include <math.h>


class Script : ScriptInterface{

  Graphite::Math::Plot2D plot;


  void Init(){
    plot["1"] = Graphite::Math::Point({0.2f, 0.1f});
  };

  void Update(){
    
  };

  void Draw(){
    plot.draw();
  };

  void Destroy(){

  };
};



extern "C" ScriptInterface* SCRIPT_API GetScript() {
  Script* script = new Script();
  return (ScriptInterface*)script;
};

extern "C" void SCRIPT_API DeleteScript(ScriptInterface* script) {
  Script* temp_script = (Script*)script;
  delete temp_script;
};

Extending MathLib

You can add your own math types and functions by creating packages (in future) or extending the library in your scripts. Also you can add any header files to scripts.

Graphite Wiki Sidebar

Getting Started

References

Project & Versions

Community

Clone this wiki locally