[][src]Module hektor::free_functions

This module contains free function versions of various operations.

In math you write operations as func(arg), something like cos(x). However, all of our operations are defined as methods on each type. If operations are only given as methods then your page of math will say cos(a+b) but you in your code you'll have to write that expression as (a+b).cos(), and then when you look at it you have to flip it around in your head to be sure you wrote the right thing. It's no good.

To assist with this problem, we have provided non-method versions of most of our operations. Since rust doesn't allow direct overloading of methods and functions in the way that Java and C++ do, each function is generic over a trait for just that one operation. To keep the translation as mechanistic and possible the following naming convention is used:

  • Type Method / Operation: foo
  • Function: foo
  • Trait Name: CanFoo
  • Trait Method: foo

The call stack is also kept as simple as possible:

  • The function always just calls the trait method.
  • The trait impl method calls over to the type's method, if available.
  • If the type itself supports the operation but doesn't have a method for it (eg: most float ops, since this is core only) then a call to the correct other function will be used instead of a type method call.

This design is pretty nice because it means that you don't have to import the traits separately, you can just call a function with any type allowed and Rust figures it out for you.

Traits

CanDeterminant

A trait for types that can have a determinant computed.

Functions

determinant

Computes the determinant of a matrix.