Table of Contents

Class Strength

Namespace
Nalu.Cassowary
Assembly
Nalu.Maui.Layouts.dll

Contains useful constants and functions for producing strengths for use in the constraint solver. Each constraint added to the solver has an associated strength specifying the precedence the solver should impose when choosing which constraints to enforce. It will try to enforce all constraints, but if that is impossible the lowest strength constraints are the first to be violated.

public static class Strength
Inheritance
Strength
Inherited Members

Remarks

Strengths are simply real numbers. The strongest legal strength is 1,001,001,000.0. The weakest is 0.0. For convenience constants are declared for commonly used strengths. These are Required, Strong, Medium and Weak. Feel free to multiply these by other values to get intermediate strengths. Note that the solver will clip given strengths to the legal range.

Required signifies a constraint that cannot be violated under any circumstance. Use this special strength sparingly, as the solver will fail completely if it find that not all of the `REQUIRED` constraints can be satisfied. The other strengths represent fallible constraints. These should be the most commonly used strenghts for use cases where violating a constraint is acceptable or even desired.

The solver will try to get as close to satisfying the constraints it violates as possible, strongest first. This behaviour can be used (for example) to provide a "default" value for a variable should no other stronger constraints be put upon it.

Fields

Medium

The medium strength.

public const double Medium = 1000

Field Value

double

Required

The required strength.

public const double Required = 1000000000

Field Value

double

Strong

The strong strengths.

public const double Strong = 1000000

Field Value

double

Weak

The weak strength.

public const double Weak = 1

Field Value

double

Methods

Clip(double)

Clips a strength value to the legal range.

public static double Clip(double strength)

Parameters

strength double

The strength.

Returns

double

The clip value.

Create(double, double, double, double)

Create a constraint as a linear combination of Strong, Medium and Weak strengths, corresponding to a b and c respectively. The result is further multiplied by w.

public static double Create(double a, double b, double c, double w)

Parameters

a double

The strong value.

b double

The medium value.

c double

The weak value.

w double

The multiplied.

Returns

double