Style Guide

This document provides a guide to the style used in this project.

Code Formatting

We utilize ClangFormat to automate code formatting. Please format your code before pushing and/or creating a pull request.

  • The project uses the root .clang-format (80 columns, WebKit-based).

  • Under tests/, tests/.clang-format inherits that style and sets SortIncludes: false.

  • CI runs ClangFormat version 20; format with the same version locally to avoid formatting check failures (e.g. clang-format -i using version 20, or use the pre-commit hook from Tools for Developers).

  • clang-tidy uses the same style via FormatStyle: file (see .clang-tidy).

Additionally, ensure that your code adheres to the project’s linting rules. Use the provided linting tools to check for any issues before committing your changes.

Naming conventions

General

In general, we stick to the following naming conventions:

  • snake_case for variables, functions, and filenames

  • PascalCase for classes and structs

  • ALL_CAPS for constants and enum members

  • m_ prefix for class member variables (if the member is not public)

  • member() to get a class member variable (if the member is not public)

  • set_member() to set a class member variable (if the member is not public)

  • _ prefix for function parameters that would otherwise shadow a member or another name in scope (e.g., _dim for a parameter that initializes the member dim); .clang-tidy exempts these names from the naming checks

    • Always put the underscore first, never last (e.g., _p, not p_).

    • Follow the underscore with a lowercase letter. A leading underscore before an uppercase letter (e.g., _V) is reserved by the C++ standard, so pick a different name instead.

    • Do not use a p_ prefix for this. In geometry code p is conventionally a point, so names like p_t0 (the point at time t0) and p_x (the x component of p) already have a meaning.

Specific

  • Vertex positions: vertices or positions

  • Vertex displacements: displacements

  • Vertex rest positions/material coordinates: rest_positions

  • Vertex velocities: velocities

  • Mesh edge matrix: edges

  • Mesh face matrix: faces

  • Element vertices: Use a numeral suffix (e.g., e0 and e1 for the end-points of an edge).

  • Edge-edge pairings: Use suffixes a and b.

  • CUDA device pointers: Use the d_ prefix (e.g., d_vertex_boxes, d_box_min) to tell device memory apart from its host counterpart.

  • Continuous collision detection pairs: Use the suffix _t0 for starting values and _t1 for end values.

  • Favor the term “collision” over “contact” (but this is not a hard rule).

  • Prefer the term “potential” over “constraint” when referring to collisions and friction.

Documentation

We use Doxygen to generate documentation. Please document your code before pushing and/or creating a pull request.