Skip to content

Commit

Permalink
Cleaned up the fixed function logic a little bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Oct 27, 2023
1 parent 3692dff commit 9061151
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ public interface IColorNamedValue : INamedValue, IColorFactor {
IColorValue ColorValue { get; }
}

public interface IColorIdentifiedValue<TIdentifier>
public interface IColorIdentifiedValue<out TIdentifier>
: IIdentifiedValue<TIdentifier>,
IColorFactor {
IColorValue ColorValue { get; }
}

public interface IColorInput<TIdentifier>
public interface IColorInput<out TIdentifier>
: IColorIdentifiedValue<TIdentifier> {
IColorConstant DefaultValue { get; }
IColorConstant? CustomValue { get; set; }
}

public interface IColorOutput<TIdentifier>
public interface IColorOutput<out TIdentifier>
: IColorIdentifiedValue<TIdentifier> { }

public enum ColorSwizzle {
Expand All @@ -24,7 +24,7 @@ public enum ColorSwizzle {
B,
}

public interface IColorNamedValueSwizzle<TIdentifier> : IScalarFactor {
public interface IColorNamedValueSwizzle<out TIdentifier> : IScalarFactor {
IColorIdentifiedValue<TIdentifier> Source { get; }
ColorSwizzle SwizzleType { get; }
}
Expand All @@ -36,7 +36,7 @@ public interface IColorValueSwizzle : IScalarFactor {


public interface IColorValue
: IValue<IColorValue, IColorTerm, IColorExpression> {
: IValue<IColorValue, IColorConstant, IColorTerm, IColorExpression> {
IScalarValue? Intensity { get; }
IScalarValue R { get; }
IScalarValue G { get; }
Expand All @@ -47,15 +47,18 @@ public interface IColorValue

public interface IColorTerm
: IColorValue,
ITerm<IColorValue, IColorTerm, IColorExpression> { }
ITerm<IColorValue, IColorConstant, IColorTerm, IColorExpression> { }

public interface IColorExpression
: IColorValue,
IExpression<IColorValue, IColorTerm, IColorExpression> { }
IExpression<IColorValue, IColorConstant, IColorTerm,
IColorExpression> { }

public interface IColorFactor : IColorValue { }

public interface IColorConstant : IColorFactor {
public interface IColorConstant
: IColorFactor,
IConstant<IColorValue, IColorConstant, IColorTerm, IColorExpression> {
double? IntensityValue { get; }
double RValue { get; }
double GValue { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ IColorOutput<TIdentifier> CreateColorOutput(
bool DoOutputsDependOn(TIdentifier[] outputIdentifiers, IValue value);
}

public interface IIdentifiedValue<TIdentifier> : IValue {
public interface IIdentifiedValue<out TIdentifier> : IValue {
TIdentifier Identifier { get; }
}

Expand All @@ -79,17 +79,20 @@ public interface INamedValue : IValue {
// Simple
public interface IValue { }

public interface IConstant : IValue { }

public interface ITerm : IValue { }

public interface IExpression : IValue { }


// Typed
public interface IValue<in TValue, out TTerm, out TExpression>
public interface IValue<in TValue, TConstant, out TTerm, out TExpression>
: IValue
where TValue : IValue<TValue, TTerm, TExpression>
where TTerm : ITerm<TValue, TTerm, TExpression>
where TExpression : IExpression<TValue, TTerm, TExpression> {
where TValue : IValue<TValue, TConstant, TTerm, TExpression>
where TConstant : IConstant<TValue, TConstant, TTerm, TExpression>, TValue
where TTerm : ITerm<TValue, TConstant, TTerm, TExpression>, TValue
where TExpression : IExpression<TValue, TConstant, TTerm, TExpression>, TValue {
TExpression Add(TValue term1, params TValue[] terms);
TExpression Subtract(TValue term1, params TValue[] terms);
TTerm Multiply(TValue factor1, params TValue[] factors);
Expand All @@ -101,20 +104,29 @@ public interface IValue<in TValue, out TTerm, out TExpression>
TTerm Divide(IScalarValue factor1, params IScalarValue[] factors);
}

public interface ITerm<TValue, out TTerm, out TExpression>
: ITerm, IValue<TValue, TTerm, TExpression>
where TValue : IValue<TValue, TTerm, TExpression>
where TTerm : ITerm<TValue, TTerm, TExpression>
where TExpression : IExpression<TValue, TTerm, TExpression> {
public interface IConstant<in TValue, TConstant, out TTerm, out TExpression>
: IConstant, IValue<TValue, TConstant, TTerm, TExpression>
where TValue : IValue<TValue, TConstant, TTerm, TExpression>
where TConstant : IConstant<TValue, TConstant, TTerm, TExpression>, TValue
where TTerm : ITerm<TValue, TConstant, TTerm, TExpression>, TValue
where TExpression : IExpression<TValue, TConstant, TTerm, TExpression>, TValue;

public interface ITerm<TValue, TConstant, out TTerm, out TExpression>
: ITerm, IValue<TValue, TConstant, TTerm, TExpression>
where TValue : IValue<TValue, TConstant, TTerm, TExpression>
where TConstant : IConstant<TValue, TConstant, TTerm, TExpression>, TValue
where TTerm : ITerm<TValue, TConstant, TTerm, TExpression>, TValue
where TExpression : IExpression<TValue, TConstant, TTerm, TExpression>, TValue {
IReadOnlyList<TValue> NumeratorFactors { get; }
IReadOnlyList<TValue>? DenominatorFactors { get; }
}

public interface IExpression<TValue, out TTerm, out TExpression>
: IExpression, IValue<TValue, TTerm, TExpression>
where TValue : IValue<TValue, TTerm, TExpression>
where TTerm : ITerm<TValue, TTerm, TExpression>
where TExpression : IExpression<TValue, TTerm, TExpression> {
public interface IExpression<TValue, TConstant, out TTerm, out TExpression>
: IExpression, IValue<TValue, TConstant, TTerm, TExpression>
where TValue : IValue<TValue, TConstant, TTerm, TExpression>
where TConstant : IConstant<TValue, TConstant, TTerm, TExpression>, TValue
where TTerm : ITerm<TValue, TConstant, TTerm, TExpression>, TValue
where TExpression : IExpression<TValue, TConstant, TTerm, TExpression>, TValue {
IReadOnlyList<TValue> Terms { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ public interface IScalarNamedValue : INamedValue, IScalarFactor {
IScalarValue ScalarValue { get; }
}

public interface IScalarIdentifiedValue<TIdentifier> :
public interface IScalarIdentifiedValue<out TIdentifier> :
IIdentifiedValue<TIdentifier>,
IScalarFactor {
IScalarValue ScalarValue { get; }
}

public interface
IScalarInput<TIdentifier> : IScalarIdentifiedValue<TIdentifier> {
public interface IScalarInput<out TIdentifier>
: IScalarIdentifiedValue<TIdentifier> {
IScalarConstant DefaultValue { get; }
IScalarConstant? CustomValue { get; set; }
}

public interface IScalarOutput<TIdentifier>
public interface IScalarOutput<out TIdentifier>
: IScalarIdentifiedValue<TIdentifier> { }


public interface IScalarValue
: IValue<IScalarValue, IScalarTerm, IScalarExpression> {
: IValue<IScalarValue, IScalarConstant, IScalarTerm, IScalarExpression> {
bool Clamp { get; set; }

IColorValueTernaryOperator TernaryOperator(
Expand All @@ -32,16 +32,20 @@ IColorValueTernaryOperator TernaryOperator(

public interface IScalarTerm
: IScalarValue,
ITerm<IScalarValue, IScalarTerm, IScalarExpression> { }
ITerm<IScalarValue, IScalarConstant, IScalarTerm, IScalarExpression> { }

public interface IScalarExpression
: IScalarValue,
IExpression<IScalarValue, IScalarTerm, IScalarExpression> { }
IExpression<IScalarValue, IScalarConstant, IScalarTerm,
IScalarExpression> { }


public interface IScalarFactor : IScalarValue { }

public interface IScalarConstant : IScalarFactor {
public interface IScalarConstant
: IScalarFactor,
IConstant<IScalarValue, IScalarConstant, IScalarTerm,
IScalarExpression> {
double Value { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ public class FixedFunctionOpsConstants {
public const bool SIMPLIFY = true;
}

public interface IFixedFunctionOps<TValue, TTerm, TExpression>
where TValue : IValue<TValue, TTerm, TExpression>
where TTerm : ITerm<TValue, TTerm, TExpression>
where TExpression : IExpression<TValue, TTerm, TExpression> {
TValue Zero { get; }
TValue Half { get; }
TValue One { get; }
public interface IFixedFunctionOps<TValue, TConstant, TTerm, TExpression>
where TValue : IValue<TValue, TConstant, TTerm, TExpression>
where TConstant : IConstant<TValue, TConstant, TTerm, TExpression>, TValue
where TTerm : ITerm<TValue, TConstant, TTerm, TExpression>, TValue
where TExpression : IExpression<TValue, TConstant, TTerm, TExpression>, TValue {
TConstant Zero { get; }
TConstant Half { get; }
TConstant One { get; }

bool IsZero(TValue? value) => value == null || value.Equals(this.Zero);

Expand All @@ -23,14 +24,15 @@ public interface IFixedFunctionOps<TValue, TTerm, TExpression>
TValue? MultiplyWithConstant(TValue? lhs, double constant);
}

public abstract class BFixedFunctionOps<TValue, TTerm, TExpression>
: IFixedFunctionOps<TValue, TTerm, TExpression>
where TValue : IValue<TValue, TTerm, TExpression>
where TTerm : ITerm<TValue, TTerm, TExpression>
where TExpression : IExpression<TValue, TTerm, TExpression> {
public abstract TValue Zero { get; }
public abstract TValue Half { get; }
public abstract TValue One { get; }
public abstract class BFixedFunctionOps<TValue, TConstant, TTerm, TExpression>
: IFixedFunctionOps<TValue, TConstant, TTerm, TExpression>
where TValue : IValue<TValue, TConstant, TTerm, TExpression>
where TConstant : IConstant<TValue, TConstant, TTerm, TExpression>, TValue
where TTerm : ITerm<TValue, TConstant, TTerm, TExpression>, TValue
where TExpression : IExpression<TValue, TConstant, TTerm, TExpression>, TValue {
public abstract TConstant Zero { get; }
public abstract TConstant Half { get; }
public abstract TConstant One { get; }

public bool IsZero(TValue? value) => value?.Equals(this.Zero) ?? true;

Expand Down Expand Up @@ -76,12 +78,12 @@ public abstract class BFixedFunctionOps<TValue, TTerm, TExpression>
}

public class ColorFixedFunctionOps
: BFixedFunctionOps<IColorValue, IColorTerm, IColorExpression> {
: BFixedFunctionOps<IColorValue, IColorConstant, IColorTerm, IColorExpression> {
private readonly IFixedFunctionEquations<FixedFunctionSource> equations_;

private readonly IScalarValue scZero_;
private readonly IScalarValue scOne_;
private readonly IScalarValue scMinusOne_;
private readonly IScalarConstant scZero_;
private readonly IScalarConstant scOne_;
private readonly IScalarConstant scMinusOne_;

public ColorFixedFunctionOps(
IFixedFunctionEquations<FixedFunctionSource> equations) {
Expand All @@ -99,9 +101,9 @@ public ColorFixedFunctionOps(
private bool IsZero_(IScalarValue? value)
=> value?.Equals(this.scZero_) ?? true;

public override IColorValue Zero { get; }
public override IColorValue Half { get; }
public override IColorValue One { get; }
public override IColorConstant Zero { get; }
public override IColorConstant Half { get; }
public override IColorConstant One { get; }

public override IColorValue? Add(IColorValue? lhs, IColorValue? rhs) {
if (!FixedFunctionOpsConstants.SIMPLIFY) {
Expand Down Expand Up @@ -236,7 +238,7 @@ private bool IsZero_(IScalarValue? value)
}

public class ScalarFixedFunctionOps
: BFixedFunctionOps<IScalarValue, IScalarTerm, IScalarExpression> {
: BFixedFunctionOps<IScalarValue, IScalarConstant, IScalarTerm, IScalarExpression> {
private readonly IFixedFunctionEquations<FixedFunctionSource> equations_;

private readonly IScalarValue scMinusOne_;
Expand All @@ -251,9 +253,9 @@ public ScalarFixedFunctionOps(
this.scMinusOne_ = equations.CreateScalarConstant(-1);
}

public override IScalarValue Zero { get; }
public override IScalarValue Half { get; }
public override IScalarValue One { get; }
public override IScalarConstant Zero { get; }
public override IScalarConstant Half { get; }
public override IScalarConstant One { get; }

public override IScalarValue? AddWithScalar(
IScalarValue? lhs,
Expand Down

0 comments on commit 9061151

Please sign in to comment.