Giter Club home page Giter Club logo

haxe-kiwi's Introduction

Project logo

haxe-kiwi is a port of Kiwi and Kiwi Java, implementations of the Cassowary constraint solving algorithm. Run the demo in your browser.

Features

Supports:

  • Solving systems of linear constraint equations.
  • String parsing for constraint creation.
  • Edit variables.

Doesn't support:

  • Stay constraints.

Usage

haxe-kiwi depends on assertion library Sure, install that first:

haxelib install sure

Include the library through Project.xml:

<include path="lib/haxe-kiwi/include.xml" />

See the demo code, the unit tests, or run the demo in the browser for usage examples.

Screenshot of demo app

// Basic usage
var solver = new Solver();

// Constraints are written in the form: a [==|<=|>=] b [*/] c [+-] d
var problem:String = '{"inequalities":["x == 20", "x == y + 10", "z == y + 30", "q == z + x", "foo == z + x", "bar == foo + x", "baz == foo * 10", "boz == x / 10 + y / 10 + x * 5"]}';
var structure:{inequalities:Array<String>} = Json.parse(problem);

var resolver:VarResolver = new VarResolver(); // Simple map wrapper that caches variables so that duplicates aren't added to the solver
for (inequality in structure.inequalities) {
    var constraint = ConstraintParser.parseConstraint(inequality, resolver, "required");
    solver.addConstraint(constraint);
}
solver.updateVariables(); // Update the values of the external solver variables

// Trace the value of external solver variable x (expect 20)
var x = resolver.resolveVariable("x");
trace("x = " + x.value);

resolver.traceVariables(); // Trace all the variables captured by the resolver

Notes

  • There is a unit test repository for the library here.
  • All Haxe targets are supported.

Acknowledgement

  • haxe-kiwi is a port of the Kiwi UI constraint solver v0.1.3. Kiwi was written by Chris Colbert, lead of the Nucleic Development Team. Their core team that coordinates development on GitHub can be found here: https://github.com/nucleic.
  • Parts of this port were adapted from Kiwi.js, a JavaScript port of Kiwi, which is also written by the Nucleic Development Team.
  • String parsing code for constraints and some tests were ported from kiwi-java, a Java port of Kiwi by Alex Birkett.

haxe-kiwi's People

Contributors

tw1ddle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

haxe-kiwi's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.