GithubHelp home page GithubHelp logo

bradparks / haxe-kiwi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tw1ddle/haxe-kiwi

0.0 2.0 0.0 46 KB

:bird: Haxe port of Kiwi, an implementation of the Cassowary constraint solving algorithm

Home Page: http://samcodes.co.uk/code/

License: Other

Haxe 99.88% Batchfile 0.12%

haxe-kiwi's Introduction

haxe-kiwi

haxe-kiwi is a port of Kiwi and Kiwi Java, implementations of the Cassowary constraint solving algorithm.

Visit Overconstrained and join the Slack group to find out more or to get involved.

Also try 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 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

  • All Haxe targets are supported.
  • More work on the test suite is needed.

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: http://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

Watchers

 avatar  avatar

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.