CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Constraint::ConstraintStrength Class Referencefinal

Every constraint has a strength that determines where it sits in the hierarchy; strong constraints are always satisfied in preference to weaker ones. More...

#include <CeresEngine/Foundation/Constraint/ConstraintStrength.hpp>

Public Member Functions

constexpr ConstraintStrength (const ConstraintSymbolicWeight &symbolicWeight, const double w)
 
constexpr ConstraintStrength (const double a, const double b, const double c, const double w=1.0)
 Construct a strength from three weight factors.
 
bool isRequired () const
 Check if this strength signals a required constraint.
 
const ConstraintSymbolicWeightgetSymbolicWeight () const
 Get the 3-tuple symbolic weight.
 
double getWeight () const
 Get the 3-tuple symbolic weight.
 
double getAdjustedWeight () const
 Gets the adjusted weight as a double.
 

Static Public Attributes

static const ConstraintStrength required
 Constraints with this strength must be satisfied.
 
static const ConstraintStrength strong {1, 0, 0}
 The default strength for edit constraints.
 
static const ConstraintStrength medium {0, 1, 0}
 Medium constraint strength.
 
static const ConstraintStrength weak {0, 0, 1}
 The default strength for stay constraints.
 

Private Attributes

ConstraintSymbolicWeight mSymbolicWeight
 
double mWeight = 1.0
 

Friends

bool operator== (const ConstraintStrength &lhs, const ConstraintStrength &rhs)
 
bool operator!= (const ConstraintStrength &lhs, const ConstraintStrength &rhs)
 
bool operator<= (const ConstraintStrength &lhs, const ConstraintStrength &rhs)
 
bool operator< (const ConstraintStrength &lhs, const ConstraintStrength &rhs)
 
bool operator>= (const ConstraintStrength &lhs, const ConstraintStrength &rhs)
 
bool operator> (const ConstraintStrength &lhs, const ConstraintStrength &rhs)
 
ConstraintStrength operator* (ConstraintStrength lhs, double w)
 

Detailed Description

Every constraint has a strength that determines where it sits in the hierarchy; strong constraints are always satisfied in preference to weaker ones.

Since we want to be able to express preferences as well as requirements in the constraint system, we need a specification for how conflicting preferences are to be traded off. In a constraint hierarchy each constraint has a strength. The 'required' strength is special, in that required constraints must be satisfied. The other strengths all label non- required constraints.

A constraint of a given strength completely dominates any constraint with a weaker strength. In the hierarchy theory, a comparator is used to compare different possible solutions to the constraints and select among them. Within this framework a number of variations are possible.

One decision is whether we only compare solutions on a constraint-by-constraint basis (a local comparator), or whether we take some aggregate measure of the unsatisfied constraints of a given strength (a global comparator). A second choice is whether we are concerned only whether a constraint is satisfied or not (a predicate comparator), or whether we also want to know how nearly satisfied it is (a metric comparator).

Constraints whose domain is a metric space, for example the reals, can have an associated error function. The error in satisfying a constraint is zero if and only if the constraint is satisfied, and becomes larger the less nearly satisfied it is. For a given collection of constraints, Cassowary finds a locally-error-better or a weighted-sum-better solution.

Constructor & Destructor Documentation

◆ ConstraintStrength() [1/2]

constexpr CeresEngine::Constraint::ConstraintStrength::ConstraintStrength ( const ConstraintSymbolicWeight symbolicWeight,
const double  w 
)
inlineconstexpr

◆ ConstraintStrength() [2/2]

constexpr CeresEngine::Constraint::ConstraintStrength::ConstraintStrength ( const double  a,
const double  b,
const double  c,
const double  w = 1.0 
)
inlineconstexpr

Construct a strength from three weight factors.

Parameters
a'Strong' weight
b'Medium weight
c'Weak' weight
wThe weight factor.

Member Function Documentation

◆ getAdjustedWeight()

double CeresEngine::Constraint::ConstraintStrength::getAdjustedWeight ( ) const
inline

Gets the adjusted weight as a double.

◆ getSymbolicWeight()

const ConstraintSymbolicWeight & CeresEngine::Constraint::ConstraintStrength::getSymbolicWeight ( ) const
inline

Get the 3-tuple symbolic weight.

◆ getWeight()

double CeresEngine::Constraint::ConstraintStrength::getWeight ( ) const
inline

Get the 3-tuple symbolic weight.

◆ isRequired()

bool CeresEngine::Constraint::ConstraintStrength::isRequired ( ) const
inline

Check if this strength signals a required constraint.

Friends And Related Symbol Documentation

◆ operator!=

◆ operator*

◆ operator<

◆ operator<=

bool operator<= ( const ConstraintStrength lhs,
const ConstraintStrength rhs 
)
friend

◆ operator==

bool operator== ( const ConstraintStrength lhs,
const ConstraintStrength rhs 
)
friend

◆ operator>

◆ operator>=

bool operator>= ( const ConstraintStrength lhs,
const ConstraintStrength rhs 
)
friend

Member Data Documentation

◆ medium

const ConstraintStrength CeresEngine::Constraint::ConstraintStrength::medium {0, 1, 0}
inlinestatic

Medium constraint strength.

◆ mSymbolicWeight

ConstraintSymbolicWeight CeresEngine::Constraint::ConstraintStrength::mSymbolicWeight
private

◆ mWeight

double CeresEngine::Constraint::ConstraintStrength::mWeight = 1.0
private

◆ required

const ConstraintStrength CeresEngine::Constraint::ConstraintStrength::required
inlinestatic
Initial value:
{
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
}

Constraints with this strength must be satisfied.

Used by default for constraints provided by the programmer.

◆ strong

const ConstraintStrength CeresEngine::Constraint::ConstraintStrength::strong {1, 0, 0}
inlinestatic

The default strength for edit constraints.

◆ weak

const ConstraintStrength CeresEngine::Constraint::ConstraintStrength::weak {0, 0, 1}
inlinestatic

The default strength for stay constraints.


The documentation for this class was generated from the following file: