struct Cassowary::Strength

Overview

The priority of a constraint.

The solver satisfies every required constraint, then minimizes the violation of the strong components, then the medium ones, then the weak ones: no amount of violation at a lower level outweighs any violation at a higher level. Strengths compare the same way.

Strength::STRONG > Strength.new(0, 1000, 1000) # => true
Strength.new(0, 2, 0) > Strength::MEDIUM       # => true

Included Modules

Defined in:

cassowary/strength.cr

Constant Summary

MEDIUM = new(0, 1, 0)
REQUIRED = new(1000, 1000, 1000)

A constraint the solver must satisfy.

STRONG = new(1, 0, 0)
WEAK = new(0, 0, 1)

Constructors

Instance Method Summary

Constructor Detail

def self.new(strong : Number, medium : Number, weak : Number, weight : Number = 1.0) #

Creates a strength from its strong, medium and weak components, each multiplied by weight.

Each weighted component is clamped to 0..1000.


[View source]

Instance Method Detail

def <=>(other : Strength) : Int32 #
Description copied from module Comparable(Cassowary::Strength)

The comparison operator. Returns 0 if the two objects are equal, a negative number if this object is considered less than other, a positive number if this object is considered greater than other, or nil if the two objects are not comparable.

Subclasses define this method to provide class-specific ordering.

The comparison operator is usually used to sort values:

# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]

# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]

[View source]
def inspect(io : IO) : Nil #
Description copied from struct Struct

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"

[View source]
def medium : Float64 #

Returns the weighted, clamped medium component.


[View source]
def required? : Bool #

[View source]
def strong : Float64 #

Returns the weighted, clamped strong component.


[View source]
def to_s(io : IO) : Nil #

Writes the preset name (#strong) or the components (Strength(0, 5, 0)).


[View source]
def weak : Float64 #

Returns the weighted, clamped weak component.


[View source]