mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Address PR feedback on #181
This commit is contained in:
parent
bddf6cfd03
commit
0c493d9e7a
4 changed files with 36 additions and 41 deletions
|
@ -82,7 +82,7 @@
|
|||
}
|
||||
|
||||
- (instancetype) initEditConstraintWithVariable: (GSCSVariable *)variable
|
||||
stength: (GSCSStrength *)strength
|
||||
strength: (GSCSStrength *)strength
|
||||
{
|
||||
GSCSLinearExpression *expression =
|
||||
[[GSCSLinearExpression alloc] initWithVariable: variable
|
||||
|
@ -137,29 +137,23 @@
|
|||
|
||||
+ (GSCSConstraint *) constraintWithLeftVariable: (GSCSVariable *)lhs
|
||||
operator: (GSCSConstraintOperator) operator
|
||||
rightVariable: (GSCSVariable *)rhsVariable
|
||||
rightVariable: (GSCSVariable *)rhs
|
||||
{
|
||||
if (operator== GSCSConstraintOperatorEqual)
|
||||
if (operator == GSCSConstraintOperatorEqual)
|
||||
{
|
||||
GSCSLinearExpression *expression =
|
||||
[[GSCSLinearExpression alloc] initWithVariable: lhs];
|
||||
[expression addVariable: rhsVariable coefficient: -1];
|
||||
|
||||
RELEASE(expression);
|
||||
|
||||
return AUTORELEASE([[GSCSConstraint alloc]
|
||||
initLinearConstraintWithExpression: expression]);
|
||||
initWithLhsVariable: lhs equalsRhsVariable: rhs]);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSCSLinearExpression *rhsExpression =
|
||||
[[GSCSLinearExpression alloc] initWithVariable: rhsVariable];
|
||||
if (operator== GSCSConstraintOperationGreaterThanOrEqual)
|
||||
[[GSCSLinearExpression alloc] initWithVariable: rhs];
|
||||
if (operator == GSCSConstraintOperationGreaterThanOrEqual)
|
||||
{
|
||||
[rhsExpression multiplyConstantAndTermsBy: -1];
|
||||
[rhsExpression addVariable: lhs];
|
||||
}
|
||||
else if (operator== GSCSConstraintOperatorLessThanOrEqual)
|
||||
else if (operator == GSCSConstraintOperatorLessThanOrEqual)
|
||||
{
|
||||
[rhsExpression addVariable: lhs coefficient: -1];
|
||||
}
|
||||
|
@ -177,7 +171,7 @@ operator: (GSCSConstraintOperator) operator
|
|||
{
|
||||
GSCSLinearExpression *expression;
|
||||
GSCSConstraint *constraint;
|
||||
if (operator== GSCSConstraintOperatorEqual)
|
||||
if (operator == GSCSConstraintOperatorEqual)
|
||||
{
|
||||
expression = [[GSCSLinearExpression alloc] init];
|
||||
[expression addVariable: lhs coefficient: 1];
|
||||
|
@ -192,12 +186,12 @@ operator: (GSCSConstraintOperator) operator
|
|||
{
|
||||
expression =
|
||||
[[GSCSLinearExpression alloc] initWithConstant: rhs];
|
||||
if (operator== GSCSConstraintOperationGreaterThanOrEqual)
|
||||
if (operator == GSCSConstraintOperationGreaterThanOrEqual)
|
||||
{
|
||||
[expression multiplyConstantAndTermsBy: -1];
|
||||
[expression addVariable: lhs coefficient: 1.0];
|
||||
}
|
||||
else if (operator== GSCSConstraintOperatorLessThanOrEqual)
|
||||
else if (operator == GSCSConstraintOperatorLessThanOrEqual)
|
||||
{
|
||||
[expression addVariable: lhs coefficient: -1.0];
|
||||
}
|
||||
|
@ -216,7 +210,7 @@ operator: (GSCSConstraintOperator) operator
|
|||
{
|
||||
GSCSLinearExpression *lhsExpression =
|
||||
[[GSCSLinearExpression alloc] initWithVariable: lhs];
|
||||
GSCSConstraint *constraint = [self constraintWithLeftExpression:lhsExpression operator:operator rightExpression:rhs];
|
||||
GSCSConstraint *constraint = [self constraintWithLeftExpression: lhsExpression operator: operator rightExpression: rhs];
|
||||
RELEASE(lhsExpression);
|
||||
return constraint;
|
||||
}
|
||||
|
@ -229,7 +223,7 @@ operator: (GSCSConstraintOperator) operator
|
|||
[[GSCSLinearExpression alloc] initWithConstant: lhs];
|
||||
|
||||
GSCSConstraint *constraint = nil;
|
||||
if (operator== GSCSConstraintOperatorEqual)
|
||||
if (operator == GSCSConstraintOperatorEqual)
|
||||
{
|
||||
[valueExpression addVariable: rhs coefficient: -1.0];
|
||||
constraint = [[GSCSConstraint alloc]
|
||||
|
@ -237,11 +231,11 @@ operator: (GSCSConstraintOperator) operator
|
|||
}
|
||||
else
|
||||
{
|
||||
if (operator== GSCSConstraintOperationGreaterThanOrEqual)
|
||||
if (operator == GSCSConstraintOperationGreaterThanOrEqual)
|
||||
{
|
||||
[valueExpression addVariable: rhs coefficient: -1.0];
|
||||
}
|
||||
else if (operator== GSCSConstraintOperatorLessThanOrEqual)
|
||||
else if (operator == GSCSConstraintOperatorLessThanOrEqual)
|
||||
{
|
||||
[valueExpression multiplyConstantAndTermsBy: -1];
|
||||
[valueExpression addVariable: rhs coefficient: 1.0];
|
||||
|
@ -261,7 +255,9 @@ operator: (GSCSConstraintOperator) operator
|
|||
{
|
||||
GSCSLinearExpression *rhsExpression =
|
||||
[[GSCSLinearExpression alloc] initWithVariable: rhs];
|
||||
return [self constraintWithLeftExpression:lhs operator:operator rightExpression:rhsExpression];
|
||||
GSCSConstraint *constraint = [self constraintWithLeftExpression: lhs operator: operator rightExpression: rhsExpression];
|
||||
RELEASE(rhsExpression);
|
||||
return constraint;
|
||||
}
|
||||
|
||||
+ (GSCSConstraint *) constraintWithLeftExpression: (GSCSLinearExpression *)lhs
|
||||
|
@ -270,7 +266,7 @@ operator: (GSCSConstraintOperator) operator
|
|||
{
|
||||
GSCSLinearExpression *expression = [rhs copy];
|
||||
GSCSConstraint *constraint;
|
||||
if (operator== GSCSConstraintOperatorEqual)
|
||||
if (operator == GSCSConstraintOperatorEqual)
|
||||
{
|
||||
[expression addExpression: lhs multiplier: -1];
|
||||
constraint = [[GSCSConstraint alloc]
|
||||
|
@ -278,12 +274,12 @@ operator: (GSCSConstraintOperator) operator
|
|||
}
|
||||
else
|
||||
{
|
||||
if (operator== GSCSConstraintOperationGreaterThanOrEqual)
|
||||
if (operator == GSCSConstraintOperationGreaterThanOrEqual)
|
||||
{
|
||||
[expression multiplyConstantAndTermsBy: -1];
|
||||
[expression addExpression: lhs];
|
||||
}
|
||||
else if (operator== GSCSConstraintOperatorLessThanOrEqual)
|
||||
else if (operator == GSCSConstraintOperatorLessThanOrEqual)
|
||||
{
|
||||
[expression addExpression: lhs multiplier: -1];
|
||||
}
|
||||
|
@ -302,7 +298,7 @@ operator: (GSCSConstraintOperator) operator
|
|||
{
|
||||
GSCSLinearExpression *rhsExpression =
|
||||
[[GSCSLinearExpression alloc] initWithConstant: rhs];
|
||||
GSCSConstraint *constraint = [self constraintWithLeftExpression:lhs operator:operator rightExpression:rhsExpression];
|
||||
GSCSConstraint *constraint = [self constraintWithLeftExpression: lhs operator: operator rightExpression: rhsExpression];
|
||||
RELEASE(rhsExpression);
|
||||
return constraint;
|
||||
}
|
||||
|
@ -311,7 +307,7 @@ operator: (GSCSConstraintOperator) operator
|
|||
{
|
||||
return AUTORELEASE([[self alloc]
|
||||
initEditConstraintWithVariable: variable
|
||||
stength: [GSCSStrength strengthStrong]]);
|
||||
strength: [GSCSStrength strengthStrong]]);
|
||||
}
|
||||
|
||||
- (BOOL) isRequired
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
{
|
||||
CGFloat reciprocal = 1.0 / [self coefficientForTerm: subject];
|
||||
|
||||
[self multiplyConstantAndTermsBy:-reciprocal];
|
||||
[self multiplyConstantAndTermsBy: -reciprocal];
|
||||
|
||||
[self removeVariable: subject];
|
||||
return reciprocal;
|
||||
|
@ -157,7 +157,7 @@
|
|||
|
||||
- (void) normalize
|
||||
{
|
||||
[self multiplyConstantAndTermsBy:-1];
|
||||
[self multiplyConstantAndTermsBy: -1];
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
|
@ -297,7 +297,7 @@
|
|||
- (void) addExpression: (GSCSLinearExpression *)expression
|
||||
multiplier: (CGFloat)multiplier
|
||||
{
|
||||
[self setConstant: [self constant] + expression.constant * multiplier];
|
||||
[self setConstant: [self constant] + [expression constant] * multiplier];
|
||||
NSArray *termVariables = [expression termVariables];
|
||||
FOR_IN(GSCSVariable *, term, termVariables)
|
||||
CGFloat termCoefficient =
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
|
||||
@implementation GSCSStrength
|
||||
|
||||
const float GSCSStrengthRequired = 1000;
|
||||
const float GSCSStrengthStrong = 750;
|
||||
const float GSCSStrengthMedium = 500;
|
||||
const float GSCSStrengthWeak = 250;
|
||||
|
||||
- (instancetype) initWithName: (NSString *)name strength: (double)strength;
|
||||
{
|
||||
if (self = [super init])
|
||||
|
@ -37,22 +42,22 @@
|
|||
|
||||
+ (instancetype) strengthRequired
|
||||
{
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"<Required>" strength: 1000]);
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"<Required>" strength: GSCSStrengthRequired]);
|
||||
}
|
||||
|
||||
+ (instancetype) strengthStrong
|
||||
{
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"strong" strength: 750]);
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"strong" strength: GSCSStrengthStrong]);
|
||||
}
|
||||
|
||||
+ (instancetype) strengthMedium
|
||||
{
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"medium" strength: 500]);
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"medium" strength: GSCSStrengthMedium]);
|
||||
}
|
||||
|
||||
+ (instancetype) strengthWeak
|
||||
{
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"weak" strength: 250]);
|
||||
return AUTORELEASE([[GSCSStrength alloc] initWithName: @"weak" strength: GSCSStrengthWeak]);
|
||||
}
|
||||
|
||||
- (BOOL) isEqualToStrength: (GSCSStrength *)strength
|
||||
|
@ -81,7 +86,7 @@
|
|||
{
|
||||
return [GSCSFloatComparator
|
||||
isApproxiatelyEqual: _strength
|
||||
b: [[GSCSStrength strengthRequired] strength]];
|
||||
b: GSCSStrengthRequired];
|
||||
}
|
||||
|
||||
- (double) strength
|
||||
|
|
|
@ -26,13 +26,7 @@
|
|||
|
||||
- (instancetype) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
_type = GSCSVaraibleTypeVariable;
|
||||
}
|
||||
|
||||
return self;
|
||||
return [self initWithName: nil type: GSCSVaraibleTypeVariable];
|
||||
}
|
||||
|
||||
- (instancetype) initWithName: (NSString *)name
|
||||
|
|
Loading…
Reference in a new issue