struct
Cassowary::Strength
- Cassowary::Strength
- Struct
- Value
- Object
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
- Comparable(Cassowary::Strength)
Defined in:
cassowary/strength.crConstant 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
-
.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.
Instance Method Summary
-
#<=>(other : Strength) : Int32
The comparison operator.
-
#inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
-
#medium : Float64
Returns the weighted, clamped medium component.
- #required? : Bool
-
#strong : Float64
Returns the weighted, clamped strong component.
- #to_s(io : IO) : Nil
-
#weak : Float64
Returns the weighted, clamped weak component.
Constructor Detail
Creates a strength from its strong, medium and weak components, each multiplied by weight.
Each weighted component is clamped to 0..1000.
Instance Method Detail
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]
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)"