cassowary-rs
cassowary-rs copied to clipboard
Support domain specific variable type
- adds a type parameter to many types, representing a solver variable type
- removes
Variable
in favor of tools for writing your own domain specific variable types - adds some chain/builder-style functions for creating constraints
- moves some other things around where they found better homes
- moves a bunch of trait implementations into a macro
- removes all instances of
Arc
,Rc
andRefCell
in favor ofOrderedFloat
andOption
-Solver
can now safely be passed between threads withSend
andSync
- generalizes
Solver::optimise
and removesSolver.artificial
as its no longer needed - bumps the version to 0.4
This provides library users with the ability to specify their own variables. All the structs associated with constructing constraint syntax now take a type variable that represents the domain specific variable type. Variable
itself is removed as its trivial to derive it. The tests provide an example. There's a new module derive_syntax
for automatically deriving the necessary machinery to write constraints and expressions using the domain specific variable type.
This has two good effects:
- There's no need for maintaining a
HashMap<MyType, Variable>
mapping from meaning to cassowary variable. - It's now very easy to run
n
separate solvers - one for each dimension - and not have the types mix. For example:
pub struct Entity {...}
pub enum XVariable {
Left(Entity), Width(Entity), Right(Entity)
}
derive_syntax_for!(XVariable);
pub enum YVariable {
Top(Entity), Height(Entity), Bottom(Entity)
}
derive_syntax_for!(YVariable);
type XSolver = Solver<XVariable>;
type YSolver = Solver<YVariable>;
^ Here you can't mix constraints from the two axes without triggering a compile time error, which I think I like. Anyway - there's only a couple tests really, so YMMV.
This is currently a draft PR until I update the documentation.