Anvil
Anvil.API.Cassowary Class Reference

Represents a Cassowary engine structure.
A Cassowary is a type of solver. NWN uses them internally to resize the newer GUI window. More...

+ Inheritance diagram for Anvil.API.Cassowary:
+ Collaboration diagram for Anvil.API.Cassowary:

Public Member Functions

 Cassowary ()
 Creates a new Cassowary solver. More...
 
void AddConstraint (string constraintExpression, float strength=CassowaryStrength.Required)
 Adds a constraint to the system.
You cannot multiply or divide variables and expressions with each other.
Doing so will result in a error when attempting to add the constraint.
(You can, of course, multiply or divide by constants).
More...
 
float GetValue (string varName)
 Gets the value for the specified variable. More...
 
void Reset ()
 Clear out this solver, removing all state, constraints and suggestions. More...
 
void SuggestValue (string varName, float value, float strength=CassowaryStrength.Strong)
 Suggests a value to the solver. More...
 
- Public Member Functions inherited from Anvil.API.EngineStructure
void Dispose ()
 

Static Public Member Functions

static implicit operator Cassowary? (IntPtr intPtr)
 
- Static Public Member Functions inherited from Anvil.API.EngineStructure
static implicit operator IntPtr (EngineStructure engineStructure)
 

Properties

string DebugState [get]
 Gets a printable debug state of this solver, which may help you debug complex systems. More...
 
override int StructureId [get]
 
- Properties inherited from Anvil.API.EngineStructure
bool IsValid [get]
 Gets if this object is valid. More...
 
abstract int StructureId [get]
 

Additional Inherited Members

- Protected Member Functions inherited from Anvil.API.EngineStructure
 EngineStructure (IntPtr handle, bool memoryOwn)
 

Detailed Description

Represents a Cassowary engine structure.
A Cassowary is a type of solver. NWN uses them internally to resize the newer GUI window.

Examples

/*
* Examples for creating and using Cassowary solvers.
*/
using Anvil.API;
using NLog;
namespace NWN.Anvil.Samples
{
[ServiceBinding(typeof(CassowaryExamples))]
public class CassowaryExamples
{
// Gets the server log. By default, this reports to "anvil.log"
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
// Based on https://nwnlexicon.com/index.php?title=Cassowary & https://cassowary.readthedocs.io/en/latest/topics/theory.html
public CassowaryExamples()
{
// Create an empty cassowary solver.
Cassowary cTest = new Cassowary();
// Add some constraints
cTest.AddConstraint("middle == (left + right) / 2");
cTest.AddConstraint("right == left + 10");
cTest.AddConstraint("right <= 100");
cTest.AddConstraint("left >= 0");
// Results should be 90, 95 and 100
Log.Info($"Solution 1: Left: {cTest.GetValue("left")}, Middle: {cTest.GetValue("middle")}, Right: {cTest.GetValue("right")}");
// Suggest middle is 45
cTest.SuggestValue("middle", 45f);
// Results should now be 40, 45 and 50
Log.Info($"Solution 2: Left: {cTest.GetValue("left")}, Middle: {cTest.GetValue("middle")}, Right: {cTest.GetValue("right")}");
}
}
}

Constructor & Destructor Documentation

◆ Cassowary()

Anvil.API.Cassowary.Cassowary ( )
inline

Creates a new Cassowary solver.

Member Function Documentation

◆ AddConstraint()

void Anvil.API.Cassowary.AddConstraint ( string  constraintExpression,
float  strength = CassowaryStrength.Required 
)
inline

Adds a constraint to the system.
You cannot multiply or divide variables and expressions with each other.
Doing so will result in a error when attempting to add the constraint.
(You can, of course, multiply or divide by constants).

Parameters
constraintExpressionThe constraint expression. Needs to be a valid comparison equation, one of: >=, ==, <=.
strengthA value >= CASSOWARY_STRENGTH_WEAK && <= CASSOWARY_STRENGTH_REQUIRED.

◆ GetValue()

float Anvil.API.Cassowary.GetValue ( string  varName)
inline

Gets the value for the specified variable.

Parameters
varNameThe variable to query.
Returns
The value of the specified variable, otherwise 0.0 on an error.

◆ Reset()

void Anvil.API.Cassowary.Reset ( )
inline

Clear out this solver, removing all state, constraints and suggestions.

◆ SuggestValue()

void Anvil.API.Cassowary.SuggestValue ( string  varName,
float  value,
float  strength = CassowaryStrength.Strong 
)
inline

Suggests a value to the solver.

Parameters
varNameThe variable to suggest a value.
valueThe suggested value.
strengthA value >= CASSOWARY_STRENGTH_WEAK && <= CASSOWARY_STRENGTH_REQUIRED.

Property Documentation

◆ DebugState

string Anvil.API.Cassowary.DebugState
get

Gets a printable debug state of this solver, which may help you debug complex systems.


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