Giter Site home page Giter Site logo

sml's Introduction

Slippy's Math Library

A simple C++ math library without overuse of templates. Made for the purpose of making game engines, though it is not particularly optimized.

Any suggestions or contributions on making this better are welcome.

This library was made for readability, ease of use, and easy debugging. Rather than efficiency and flexibility, I preferred to make something I could read and improve on demand. C++ is already a pretty hard language to debug โ€“ creating tons of templates and macros only worsens that fact.

Usage details

This library has some peculiarities that should be useful for development.

Mutability & Immutability

All structures have copy-return immutable methods and operators as well as their inline mutable counterparts. I differentiate them by using imperative verbs for mutable methods (non const) and past-participle-tense for immutable ones (const).

Example:

Vec3 a{1, 2, 3};
Vec3 b{4, 5, 6};

// Both of these return a new Vec3 by copy.
// They don't alter 'a' or 'b' in any way.

Vec3 c = a + b; // 'c' is not 'a' nor 'b'
Vec3 d = a.translated(b); // 'd' is not 'a nor b'

// These, however, alter 'a' and 'b'.
// They also return their references so you can chain them.

Vec3& a_ref = a.translate(b); // returns 'a&'
Vec3& c_ref = c.translate(d).scale(2); // returns 'c&'
Vec3& b_ref = (b += c); // returns 'b&'

/* 

// You also can't use mutable methods in const objects (obviously)

const Vec3 immutable_zero{0, 0, 0};

// This line won't compile.
immutable_zero.translate(Vec3{1, 0, 0});

// This line, however, will.
const Vec3 immutable_x = immutable_zero.translated(Vec3{1, 0, 0}); 

*/

sml's People

Contributors

aki-cat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.