Commit 3bd8bc33 authored by Hixie's avatar Hixie

Improve asserts around BoxConstraints

Negative constraints never make sense, so catch those too.

Make RenderObject.layout's isNormalized assert use the newer more fancy
debug version of isNormalized.
parent 96405fb4
...@@ -39,6 +39,10 @@ class SectorConstraints extends Constraints { ...@@ -39,6 +39,10 @@ class SectorConstraints extends Constraints {
bool get isTight => minDeltaTheta >= maxDeltaTheta && minDeltaTheta >= maxDeltaTheta; bool get isTight => minDeltaTheta >= maxDeltaTheta && minDeltaTheta >= maxDeltaTheta;
bool get isNormalized => minDeltaRadius <= maxDeltaRadius && minDeltaTheta <= maxDeltaTheta; bool get isNormalized => minDeltaRadius <= maxDeltaRadius && minDeltaTheta <= maxDeltaTheta;
bool get debugAssertIsNormalized {
assert(isNormalized);
return isNormalized;
}
} }
class SectorDimensions { class SectorDimensions {
......
...@@ -272,12 +272,21 @@ class BoxConstraints extends Constraints { ...@@ -272,12 +272,21 @@ class BoxConstraints extends Constraints {
/// normalized and have undefined behavior when they are not. In /// normalized and have undefined behavior when they are not. In
/// checked mode, many of these APIs will assert if the constraints /// checked mode, many of these APIs will assert if the constraints
/// are not normalized. /// are not normalized.
bool get isNormalized => minWidth <= maxWidth && minHeight <= maxHeight; bool get isNormalized {
return minWidth >= 0.0 &&
minWidth <= maxWidth &&
minHeight >= 0.0 &&
minHeight <= maxHeight;
}
/// Same as [isNormalized] but, in checked mode, throws an exception
/// if isNormalized is false.
bool get debugAssertIsNormalized { bool get debugAssertIsNormalized {
assert(() { assert(() {
if (minWidth < 0.0 && minHeight < 0.0)
throw new RenderingError('BoxConstraints has both a negative minimum width and a negative minimum height.\n$this');
if (minWidth < 0.0)
throw new RenderingError('BoxConstraints has a negative minimum width.\n$this');
if (minHeight < 0.0)
throw new RenderingError('BoxConstraints has a negative minimum height.\n$this');
if (maxWidth < minWidth && maxHeight < minHeight) if (maxWidth < minWidth && maxHeight < minHeight)
throw new RenderingError('BoxConstraints has both width and height constraints non-normalized.\n$this'); throw new RenderingError('BoxConstraints has both width and height constraints non-normalized.\n$this');
if (maxWidth < minWidth) if (maxWidth < minWidth)
......
...@@ -353,6 +353,10 @@ abstract class Constraints { ...@@ -353,6 +353,10 @@ abstract class Constraints {
/// Whether the constraint is expressed in a consistent manner. /// Whether the constraint is expressed in a consistent manner.
bool get isNormalized; bool get isNormalized;
/// Same as [isNormalized] but, in checked mode, throws an exception
/// if isNormalized is false.
bool get debugAssertIsNormalized;
} }
typedef void RenderObjectVisitor(RenderObject child); typedef void RenderObjectVisitor(RenderObject child);
...@@ -975,7 +979,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -975,7 +979,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
/// implemented here) to return early if the child does not need to do any /// implemented here) to return early if the child does not need to do any
/// work to update its layout information. /// work to update its layout information.
void layout(Constraints constraints, { bool parentUsesSize: false }) { void layout(Constraints constraints, { bool parentUsesSize: false }) {
assert(constraints.isNormalized); assert(constraints.debugAssertIsNormalized);
assert(!_debugDoingThisResize); assert(!_debugDoingThisResize);
assert(!_debugDoingThisLayout); assert(!_debugDoingThisLayout);
final RenderObject parent = this.parent; final RenderObject parent = this.parent;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment