C++ or Objective-C implementations of Cassowary?

186 views
Skip to first unread message

Bruce Cohen

unread,
Aug 21, 2014, 6:39:51 PM8/21/14
to overcon...@googlegroups.com
I'm developing a Mac OSX dynamic geometry application that needs a constraint solver to track constraints like distance, tangency, and intersection between the geometric objects. My plan is to use Swift as the primary implementation language, which would allow me to easily link to constraint code in Objective-C, or in C++ with an Objective-C adaptor layer. I've downloaded the Cassowary C++ code and attempted to build it, but have not been able to get past many configuration and compiler errors. I don't know much about autoconf and automate, and the documentation looks formidable enough that I'd rather get some help with these problems than spend a couple of weeks becoming proficient in them.

So I'm looking for anyone who has a C++ or Objective-C implementation of Cassowary (or another linear constraint solver) running on a recent version of Mac OS to give me advice or assistance. If one of the implementors of the Apple Cocoa autolayout constraint solver is listening, maybe you can give me some pointers.

Thanks in advance,

Bruce Cohen

Russell Keith-Magee

unread,
Aug 21, 2014, 7:06:48 PM8/21/14
to overcon...@googlegroups.com
Hi Bruce,

I can't help you directly with a C++ or Objective-C implementation; but I can give you some advice - don't rule out implementing it yourself.

I recently implemented Cassowary in Python (http://pybee.org/cassowary), and it was surprisingly easy, using the Java and Javascript implementations as a point of reference. It took maybe 2 weeks of tinkering in my spare time to get it fully working.

I've only had a cursory look at Swift as a language, but it looks like it shares a lot of commonalities with other dynamic languages (including Python); a native Swift implementation of Cassowary might not be as hard as you may think.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "overconstrained" group.
To unsubscribe from this group and stop receiving emails from it, send an email to overconstrain...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg Badros

unread,
Aug 21, 2014, 7:28:54 PM8/21/14
to overcon...@googlegroups.com
I've never tried it, but you could look at Rhea, which is a clean-up of Cassowary for contemporary C++ language changes and compilers: https://github.com/Nocte-/rhea

Greg


--

Ken Ferry

unread,
Aug 21, 2014, 8:32:03 PM8/21/14
to overcon...@googlegroups.com
On Thu, Aug 21, 2014 at 3:39 PM, Bruce Cohen <brucec...@gmail.com> wrote:
If one of the implementors of the Apple Cocoa autolayout constraint solver is listening, maybe you can give me some pointers.

That's me, but I don't have any direct suggestions… auto layout's core solver started out as an Objective-C port of the Smalltalk implementation of Cassowary. 

I'm developing a Mac OSX dynamic geometry application that needs a constraint solver to track constraints like distance, tangency, and intersection between the geometric objects.

Greg's suggestion of Rhea sounds as good to me as anything. Someone else mentioned to me that they'd had good luck with https://github.com/wisaruthk/MyGLPK 

You shouldn't use this, but you might be amused: For fun and as a Swift exercise I bootstrapped a "general" linear programming solver off of native auto layout:


let engine = Engine()

let a = LPExpression.Var("a")

let b = LPExpression.Var("b")

let c = LPExpression.Var("c")


engine.addConstraint(a + b == 2*(c + b))

engine.addConstraint(c >= 100)

engine.addConstraint((a == 30).atPriority(300))

engine.addConstraint((b == 60).atPriority(400))


//println(engine)

println(engine.valueForExpression(a))

println(engine.valueForExpression(b))

println(engine.valueForExpression(c))


It takes the equations, turns them into a view hierarchy, lays it out, and reads back view geometry. :-)

It's not really general though… auto layout produces pixel-integral layouts, and if you try to bootstrap up to a general solver that just means weird quasi-answers.
 
-ken

Bruce Cohen

unread,
Aug 24, 2014, 7:19:49 PM8/24/14
to overcon...@googlegroups.com
Thanks for the info, all. I'm going to see if a Swift implementation of Rhea will do what I need. This will take a little bit of time, as this is a part-time project. I'll post something here if it works.

Tzu-ping Chung

unread,
Oct 14, 2014, 11:23:06 PM10/14/14
to overcon...@googlegroups.com
It’s not an Objective-C implementation, but one way to get Cassowary on OS X is to run cassowary.js with JavaScriptCore. Not that it’s particularly efficient, but you can get Cassowary working very quickly with a simple wrapper. Might be worth a try in the initial phase of the project (and worry about performance, possibly a real port, later).
Reply all
Reply to author
Forward
0 new messages