All Projects → sile-typesetter → cassowary.lua

sile-typesetter / cassowary.lua

Licence: Apache-2.0 license
A Lua port of the cassowary constraint solver engine

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to cassowary.lua

ciao
Ciao is a modern Prolog implementation that builds up from a logic-based simple kernel designed to be portable, extensible, and modular.
Stars: ✭ 190 (+458.82%)
Mutual labels:  constraints
casso
A Go implementation of the Cassowary constraint solving algorithm.
Stars: ✭ 75 (+120.59%)
Mutual labels:  cassowary
GHOST
General meta-Heuristic Optimization Solving Toolkit
Stars: ✭ 28 (-17.65%)
Mutual labels:  constraints
PyMiniSolvers
A Python API for the MiniSat and MiniCard constraint solvers.
Stars: ✭ 18 (-47.06%)
Mutual labels:  constraints
jasper
Haxe port of Kiwi's implementation of the cassowary algorithm.
Stars: ✭ 22 (-35.29%)
Mutual labels:  cassowary
VanillaConstraints
🍦 Simplified and chainable AutoLayout constraints for iOS.
Stars: ✭ 42 (+23.53%)
Mutual labels:  constraints
StoryboardConstraint
A simple way to use programmatically Autolayout Constraint created in Storyboard.
Stars: ✭ 25 (-26.47%)
Mutual labels:  constraints
ljdns
A contemporary DNS library using LuaJIT FFI.
Stars: ✭ 26 (-23.53%)
Mutual labels:  luarocks
SuperPuperDuperLayout
Super puper duper mega easy awesome wrapper over auto layout!!111!!1!!!1!!!11111!!!1!!
Stars: ✭ 14 (-58.82%)
Mutual labels:  constraints
Cassowary
High performance swift implement of constraint solving algorithm cassowary
Stars: ✭ 45 (+32.35%)
Mutual labels:  cassowary
Formidable
The PHP pragmatic forms library
Stars: ✭ 116 (+241.18%)
Mutual labels:  constraints
django-db-constraints
Add database table-level constraints to your Django model's Meta
Stars: ✭ 43 (+26.47%)
Mutual labels:  constraints
Driftwood
Driftwood is a DSL to make Auto Layout easy on iOS, tvOS and macOS.
Stars: ✭ 14 (-58.82%)
Mutual labels:  constraints
mv-postgresql
Postgresql constraints in migrations similiar to ActiveRecord validations
Stars: ✭ 19 (-44.12%)
Mutual labels:  constraints
clpsmt-miniKanren
CLP(SMT) on top of miniKanren
Stars: ✭ 31 (-8.82%)
Mutual labels:  constraints
conjure
Conjure: The Automated Constraint Modelling Tool
Stars: ✭ 84 (+147.06%)
Mutual labels:  constraints
sqlite.lua
SQLite LuaJIT binding with a very simple api.
Stars: ✭ 291 (+755.88%)
Mutual labels:  luarocks
csb
A cloth and soft body simulation library, using position based dynamics.
Stars: ✭ 29 (-14.71%)
Mutual labels:  constraints
loverocks
LÖVE + Luarocks
Stars: ✭ 80 (+135.29%)
Mutual labels:  luarocks
Flask-Validator
Validator for SQLAlchemy Models
Stars: ✭ 27 (-20.59%)
Mutual labels:  constraints

Cassowary

Luacheck Busted Coverage Status GitHub tag (latest SemVer) Luarocks

This is a Lua port of the cassowary constraint solving toolkit. It allows you to use Lua to solve algebraic equations and inequalities and find the values of unknown variables which satisfy those inequalities.

This port is a fairly dumb, bug-for-bug translation of the Javascript version of cassowary. From that project's description:

Cassowary and other hierarchial constraint toolkits add a unique mechanism for deciding between sets of rules that might conflict in determining which of a set of possible solutions are "better". By allowing constraint authors to specify weights for the constraints, the toolkit can decide in terms of stronger constraints over weaker ones, allowing for more optimal solutions. These sorts of situations arise all the time in UI programming; e.g.: "I'd like this to be it's natural width, but only if that's smaller than 600px, and never let it get smaller than 200px". Constraint solvers offer a way out of the primordial mess of nasty conditionals and brittle invalidations.

Getting started

Cassowary.lua is distributed through LuaRocks. Once installed:

cassowary = require("cassowary")

-- Create a new solver object
local solver = cassowary.SimplexSolver();

-- Create lua variables to represent x and y
local x = cassowary.Variable({ name = 'x' });
local y = cassowary.Variable({ name = 'y' });

-- Let's encode some expressions:

--    x < y
solver:addConstraint(cassowary.Inequality(x, "<=", y))

--    y = x + 3
solver:addConstraint(cassowary.Equation(y, cassowary.plus(x, 3)))

--    either x = 10 or y = 10
solver:addConstraint(cassowary.Equation(x, 10, cassowary.Strength.weak))
solver:addConstraint(cassowary.Equation(y, 10, cassowary.Strength.weak))

-- The solver automatically tries to resolve the current situation
-- whenever constraints are added, so all we need to do is look
-- at the values:

print("x = "..x.value)
print("y = "..y.value)

Depending on the phase of the moon, you will either see:

x=7
y=10

or

x=10
y=13

For further examples, see the test suite.

Licence

This is a derived work of the Javascript port; I've chosen to licensed it similarly under the Apache 2.0 license.

Author

Simon Cozens, [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].