Skip to content

barne856/squint

Repository files navigation

SQUINT (Static Quantities in Tensors)

Build and Test Deploy static content to Pages Documentation License

SQUINT is a header-only C++ library designed for compile-time dimensional analysis, unit conversion, and linear algebra operations. It's particularly well-suited for graphics programming and physics simulations, combining a quantity system for handling physical units and dimensions with a tensor system for efficient numerical computations.

Key Features

  • Compile-time dimensional analysis
  • Flexible tensor system supporting both fixed and dynamic shapes
  • Integration of physical quantities with tensor operations
  • Optional runtime error checking
  • Support for common linear algebra operations
  • Useful mathematical and physical constants

Installation

SQUINT is a header-only library. To use it in your project:

  1. Copy the include/squint directory to your project's include path.
  2. Include the necessary headers in your C++ files:
#include <squint/quantity.hpp>
#include <squint/tensor.hpp>
#include <squint/geometry.hpp>

For CMake projects, you can use FetchContent for a more streamlined integration:

include(FetchContent)

FetchContent_Declare(
    squint
    GIT_REPOSITORY https://github.com/barne856/squint.git
    GIT_TAG main  # or a specific tag/commit
)

FetchContent_MakeAvailable(squint)

target_link_libraries(your_target PRIVATE SQUINT::SQUINT)

Examples

SQUINT can be used for common graphics operations:

#include <iostream>
#include <squint/geometry.hpp>
#include <squint/quantity.hpp>
#include <squint/tensor.hpp>

using namespace squint;
using namespace squint::units::literals;

int main() {
    // Define a 3D point
    vec3_t<length> point{
      1.0_m,
      2.0_m,
      3.0_m
    };

    // Create a model matrix
    mat4 model = mat4::eye();

    // Apply transformations
    geometry::translate(
    model,
    vec3_t<length>{
        2.0_m,
        1.0_m,
        0.0_m
    });
    geometry::rotate(
    model,
    math_constants<float>::pi / 4.0f,
    vec3{
        0.0f,
        1.0f,
        0.0f
    });
    geometry::scale(
    model, 
    vec3{
        2.0f,
        2.0f,
        2.0f
    });

    // Transform the point
    vec4_t<length> homogeneous_point{point(0), point(1), point(2), length(1.0f)};
    auto transformed_point = model * homogeneous_point;

    std::cout << "point: " << point << std::endl;
    std::cout << "transformed_point: " << transformed_point << std::endl;

  return 0;
}

SQUINT can be used for physics calculations:

#include <iostream>
#include <squint/quantity.hpp>
#include <squint/tensor.hpp>

using namespace squint;

int main() {
  // Define initial conditions
  auto pos = vec3_t<length>::zeros();
  vec3_t<velocity> vel{velocity(5.0f), velocity(10.0f), velocity(0.0f)};
  vec3_t<acceleration_t<float>> acc{acceleration(0.0f), acceleration(-9.81f),
                                    acceleration(0.0f)};

  // Simulation parameters
  auto dt = squint::units::seconds(0.1f);
  auto total_time = squint::units::seconds(1.0f);

  // Simulation loop
  for (auto t = squint::units::seconds(0.0f); t < total_time; t += dt) {
    // Update position and velocity
    pos += vel * dt + 0.5f * acc * dt * dt;
    vel += acc * dt;

    // Print current state
    std::cout << "Time: " << t << "\nPosition: " << pos
              << "\nVelocity: " << vel << "\n\n";
  }

  return 0;
}

Documentation

For detailed information about SQUINT's features, API reference, and advanced usage, please refer to the full documentation.

License

MIT

About

Static Quantities in Tensors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published