From 90611515bfc4289ccc4e658389a5e3fc71b50e40 Mon Sep 17 00:00:00 2001 From: MeltyPlayer Date: Thu, 26 Oct 2023 19:16:48 -0500 Subject: [PATCH] Cleaned up the fixed function logic a little bit. --- .../fixedFunction/ColorInterfaces.cs | 19 ++++--- .../FixedFunctionEquationsInterfaces.cs | 42 +++++++++------ .../fixedFunction/ScalarInterfaces.cs | 20 ++++--- .../fixedFunction/impl/FixedFunctionOps.cs | 54 ++++++++++--------- 4 files changed, 78 insertions(+), 57 deletions(-) diff --git a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ColorInterfaces.cs b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ColorInterfaces.cs index f8c96ffd6..19b6f83e7 100644 --- a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ColorInterfaces.cs +++ b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ColorInterfaces.cs @@ -3,19 +3,19 @@ public interface IColorNamedValue : INamedValue, IColorFactor { IColorValue ColorValue { get; } } - public interface IColorIdentifiedValue + public interface IColorIdentifiedValue : IIdentifiedValue, IColorFactor { IColorValue ColorValue { get; } } - public interface IColorInput + public interface IColorInput : IColorIdentifiedValue { IColorConstant DefaultValue { get; } IColorConstant? CustomValue { get; set; } } - public interface IColorOutput + public interface IColorOutput : IColorIdentifiedValue { } public enum ColorSwizzle { @@ -24,7 +24,7 @@ public enum ColorSwizzle { B, } - public interface IColorNamedValueSwizzle : IScalarFactor { + public interface IColorNamedValueSwizzle : IScalarFactor { IColorIdentifiedValue Source { get; } ColorSwizzle SwizzleType { get; } } @@ -36,7 +36,7 @@ public interface IColorValueSwizzle : IScalarFactor { public interface IColorValue - : IValue { + : IValue { IScalarValue? Intensity { get; } IScalarValue R { get; } IScalarValue G { get; } @@ -47,15 +47,18 @@ public interface IColorValue public interface IColorTerm : IColorValue, - ITerm { } + ITerm { } public interface IColorExpression : IColorValue, - IExpression { } + IExpression { } public interface IColorFactor : IColorValue { } - public interface IColorConstant : IColorFactor { + public interface IColorConstant + : IColorFactor, + IConstant { double? IntensityValue { get; } double RValue { get; } double GValue { get; } diff --git a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/FixedFunctionEquationsInterfaces.cs b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/FixedFunctionEquationsInterfaces.cs index 1924c6fcf..c8d75fed6 100644 --- a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/FixedFunctionEquationsInterfaces.cs +++ b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/FixedFunctionEquationsInterfaces.cs @@ -68,7 +68,7 @@ IColorOutput CreateColorOutput( bool DoOutputsDependOn(TIdentifier[] outputIdentifiers, IValue value); } - public interface IIdentifiedValue : IValue { + public interface IIdentifiedValue : IValue { TIdentifier Identifier { get; } } @@ -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 + public interface IValue : IValue - where TValue : IValue - where TTerm : ITerm - where TExpression : IExpression { + where TValue : IValue + where TConstant : IConstant, TValue + where TTerm : ITerm, TValue + where TExpression : IExpression, TValue { TExpression Add(TValue term1, params TValue[] terms); TExpression Subtract(TValue term1, params TValue[] terms); TTerm Multiply(TValue factor1, params TValue[] factors); @@ -101,20 +104,29 @@ public interface IValue TTerm Divide(IScalarValue factor1, params IScalarValue[] factors); } - public interface ITerm - : ITerm, IValue - where TValue : IValue - where TTerm : ITerm - where TExpression : IExpression { + public interface IConstant + : IConstant, IValue + where TValue : IValue + where TConstant : IConstant, TValue + where TTerm : ITerm, TValue + where TExpression : IExpression, TValue; + + public interface ITerm + : ITerm, IValue + where TValue : IValue + where TConstant : IConstant, TValue + where TTerm : ITerm, TValue + where TExpression : IExpression, TValue { IReadOnlyList NumeratorFactors { get; } IReadOnlyList? DenominatorFactors { get; } } - public interface IExpression - : IExpression, IValue - where TValue : IValue - where TTerm : ITerm - where TExpression : IExpression { + public interface IExpression + : IExpression, IValue + where TValue : IValue + where TConstant : IConstant, TValue + where TTerm : ITerm, TValue + where TExpression : IExpression, TValue { IReadOnlyList Terms { get; } } } \ No newline at end of file diff --git a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ScalarInterfaces.cs b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ScalarInterfaces.cs index cb4b1c0fc..9f0d3ed9b 100644 --- a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ScalarInterfaces.cs +++ b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/ScalarInterfaces.cs @@ -3,24 +3,24 @@ public interface IScalarNamedValue : INamedValue, IScalarFactor { IScalarValue ScalarValue { get; } } - public interface IScalarIdentifiedValue : + public interface IScalarIdentifiedValue : IIdentifiedValue, IScalarFactor { IScalarValue ScalarValue { get; } } - public interface - IScalarInput : IScalarIdentifiedValue { + public interface IScalarInput + : IScalarIdentifiedValue { IScalarConstant DefaultValue { get; } IScalarConstant? CustomValue { get; set; } } - public interface IScalarOutput + public interface IScalarOutput : IScalarIdentifiedValue { } public interface IScalarValue - : IValue { + : IValue { bool Clamp { get; set; } IColorValueTernaryOperator TernaryOperator( @@ -32,16 +32,20 @@ IColorValueTernaryOperator TernaryOperator( public interface IScalarTerm : IScalarValue, - ITerm { } + ITerm { } public interface IScalarExpression : IScalarValue, - IExpression { } + IExpression { } public interface IScalarFactor : IScalarValue { } - public interface IScalarConstant : IScalarFactor { + public interface IScalarConstant + : IScalarFactor, + IConstant { double Value { get; } } } \ No newline at end of file diff --git a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/impl/FixedFunctionOps.cs b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/impl/FixedFunctionOps.cs index 7ed567b48..e04223cb2 100644 --- a/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/impl/FixedFunctionOps.cs +++ b/FinModelUtility/Fin/Fin/src/language/equations/fixedFunction/impl/FixedFunctionOps.cs @@ -5,13 +5,14 @@ public class FixedFunctionOpsConstants { public const bool SIMPLIFY = true; } - public interface IFixedFunctionOps - where TValue : IValue - where TTerm : ITerm - where TExpression : IExpression { - TValue Zero { get; } - TValue Half { get; } - TValue One { get; } + public interface IFixedFunctionOps + where TValue : IValue + where TConstant : IConstant, TValue + where TTerm : ITerm, TValue + where TExpression : IExpression, TValue { + TConstant Zero { get; } + TConstant Half { get; } + TConstant One { get; } bool IsZero(TValue? value) => value == null || value.Equals(this.Zero); @@ -23,14 +24,15 @@ public interface IFixedFunctionOps TValue? MultiplyWithConstant(TValue? lhs, double constant); } - public abstract class BFixedFunctionOps - : IFixedFunctionOps - where TValue : IValue - where TTerm : ITerm - where TExpression : IExpression { - public abstract TValue Zero { get; } - public abstract TValue Half { get; } - public abstract TValue One { get; } + public abstract class BFixedFunctionOps + : IFixedFunctionOps + where TValue : IValue + where TConstant : IConstant, TValue + where TTerm : ITerm, TValue + where TExpression : IExpression, 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; @@ -76,12 +78,12 @@ public abstract class BFixedFunctionOps } public class ColorFixedFunctionOps - : BFixedFunctionOps { + : BFixedFunctionOps { private readonly IFixedFunctionEquations 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 equations) { @@ -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) { @@ -236,7 +238,7 @@ private bool IsZero_(IScalarValue? value) } public class ScalarFixedFunctionOps - : BFixedFunctionOps { + : BFixedFunctionOps { private readonly IFixedFunctionEquations equations_; private readonly IScalarValue scMinusOne_; @@ -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,