Skip to content
nucleicPublic

About

Efficient C++ implementation of the Cassowary constraint solving algorithm

Resources

Stars

786 stars

Watchers

27 watching

Forks

Repository files navigation

Welcome to Kiwi

Continuous Integration Documentation building codecov Documentation Status

Kiwi is an efficient C++ implementation of the Cassowary constraint solving algorithm. Kiwi is an implementation of the algorithm based on the seminal Cassowary paper. It is not a refactoring of the original C++ solver. Kiwi has been designed from the ground up to be lightweight and fast. Kiwi ranges from 10x to 500x faster than the original Cassowary solver with typical use cases gaining a 40x improvement. Memory savings are consistently > 5x.

In addition to the C++ solver, Kiwi ships with hand-rolled Python bindings.

How to use

C++ with CMake

Write the following in your CMakeLists.txt to include Kiwi as a dependency:

include(FetchContent)

FetchContent_Declare(
    kiwi
    GIT_REPOSITORY https://github.com/nucleic/kiwi
    GIT_TAG        {release name}
)

FetchContent_MakeAvailable(kiwi)

target_link_libraries(your_target PRIVATE kiwi::kiwi)

C++ code example:

#include <kiwi/kiwi.h>
#include <iostream>

int main() {
    // initialize the solver
    kiwi::Solver solver;
    // initialize the variables
    kiwi::Variable x = kiwi::Variable("x");
    kiwi::Variable y = kiwi::Variable("y");
    solver.addConstraint(x + y == 10);
    solver.addConstraint(x - y == 4);
    // solve the system of equations
    solver.updateVariables();
    std::cout << "x: " << x.value() << ", y: " << y.value() << std::endl;
    // Output: x: 7, y: 3
    return 0;
}

You can also use tests to see more examples of how to use the solver: SimlpexTest and SolverTest.

About

Efficient C++ implementation of the Cassowary constraint solving algorithm

Resources

Stars

786 stars

Watchers

27 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages