From 2bc371c35e773e6008eb8a763bf814c9d1d010ad Mon Sep 17 00:00:00 2001 From: MaZiFAU <63099053+MaZiFAU@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:55:07 +0100 Subject: [PATCH] BugFix; SOMDocToLambdaExpression; BugFix: + R inputs updates now with scroll + R values have proper label SOMDocToLambdaExpression: + more constants + manual angle_between (TODO: autamatic per AST) --- .../FactWrapper/RenderedScrollFact.cs | 1 + .../FactHandling/Facts/Fact.cs | 2 +- .../FactHandling/Facts/MMTTypes.cs | 4 +++ .../CommunicationProtocoll/MMTConstants.cs | 5 ++-- .../SOMDocToLambdaExpression.cs | 26 ++++++++++++++----- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs index 26f2efd3..36d7ef33 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactWrapper/RenderedScrollFact.cs @@ -24,6 +24,7 @@ public Scroll Scroll { _Scroll = value; SetLabel(null); + ResetPayload(); } } private Scroll _Scroll; diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs index d8e40c1e..c10ea05d 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs @@ -675,7 +675,7 @@ public static List<Fact> MMTFactory(MMTFact ingredient) //} //catch (NotSupportedException) { } - MakeFact(ret, CompiledValue, indirect_payload, true, ingredient.@ref); + MakeFact(ret, CompiledValue, indirect_payload, false, ingredient.@ref); //true => server does not recognize fact return ret; } diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs index c53d2f7e..07daa97d 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs @@ -628,6 +628,10 @@ protected override string[] GetDependentFactIds() protected override void RecalculateTransform() { } + /// \copydoc Fact.generateLabel + protected override string generateLabel(FactRecorder name_space) + => $"R{value}"; + protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new) => new RealLitFact(value); } diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs index 827aacce..5d613eac 100644 --- a/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs @@ -83,6 +83,7 @@ public static class MMTConstants public static readonly string MinusRealLit = "http://mathhub.info/MitM/Foundation?RealLiterals?minus_real_lit"; public static readonly string InvertRealLit = "http://mathhub.info/MitM/Foundation?RealLiterals?inv_real_lit"; public static readonly string TimesRealLit = "http://mathhub.info/MitM/Foundation?RealLiterals?times_real_lit"; + public static readonly string RealMultiplication = "http://mathhub.info/MitM/core/arithmetics?RealArithmetics?multiplication"; public static readonly string LEQRealLit = "http://mathhub.info/MitM/Foundation?RealLiterals?leq_real_lit"; public static readonly string IfThenElse = "http://mathhub.info/FrameIT/frameworld?IfThenElseX?ifthenelsex"; @@ -102,8 +103,8 @@ public static class MMTConstants public static readonly string ToArray = "?ToArray"; public static readonly string Invoke = "?lambda"; - public static readonly string Sin = "Sin"; - public static readonly string Cos = "Cos"; + public static readonly string Sin = "http://mathhub.info/MitM/Foundation?Trigonometry?sin"; + public static readonly string Cos = "http://mathhub.info/MitM/Foundation?Trigonometry?cos"; public static readonly string Divide = "Divide"; public static readonly string SquareRoot = "http://mathhub.info/MitM/Foundation?RealLiterals?sqrt"; public static readonly string LessThan = "LessThan"; diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs index 192673b5..ae2b510d 100644 --- a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs @@ -113,6 +113,8 @@ protected static class SOMDocToLambdaExpression MakeTupel }, { MMTConstants.Product, // TODO:Automate MakeTupel }, + { MMTConstants.Angle, // TODO: get AST from server? + CalculateAngle }, { MMTConstants.MakeObjectArray, MakeObjArray }, { MMTConstants.ListApplicant, @@ -227,6 +229,8 @@ protected static class SOMDocToLambdaExpression ExpressionType.Multiply}, { MMTConstants.VecMultI, ExpressionType.Multiply}, + { MMTConstants.RealMultiplication, + ExpressionType.Multiply}, { "MultiplyAssign", ExpressionType.MultiplyAssign}, { "MultiplyAssignChecked", @@ -345,15 +349,10 @@ void ThrowArgumentException(ExpressionType expression_cast, int expected) { return lamda_maker(lambda_applicant, lambda_arguments, found_bound_params); } - else - if (MMTConstants.OMS_TO_TYPE.TryGetValue(URI, out Type type)) - { - return Expression.Lambda(Expression.Default(type), null); - } else // Last entree to avoid stack-overflow: if (FactRecorder.AllFacts.TryGetValue(URI, out Fact fact)) { - type = fact.CompiledValue.GetType(); + Type type = fact.CompiledValue.GetType(); Expression lambda_orig = Expression.Constant(fact.CompiledValue, type); @@ -376,6 +375,11 @@ void ThrowArgumentException(ExpressionType expression_cast, int expected) else return _PartialInvoke(lambda_orig, lambda_applicant, found_bound_params); } + else + if (MMTConstants.OMS_TO_TYPE.TryGetValue(URI, out Type type)) + { + return Expression.Lambda(Expression.Default(type), null); + } throw new NotImplementedException("Could not map URI: \"" + URI + "\""); } @@ -534,6 +538,16 @@ public static LambdaExpression ProjRVecTupel(LambdaExpression[] lambda_applicant : MakeTupel(Items_applicant, lambda_arguments, bound_params); } + public static LambdaExpression CalculateAngle(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => MakeTupel(new[] { + ExpresionFuncToLambda( + (Expression<Func<Vector3, Vector3, Vector3, float>>)((Vector3 a, Vector3 b, Vector3 c) + => Mathf.Acos(Vector3.Dot((b - a).normalized, (b - c).normalized))), + "angle_between", lambda_applicant, bound_params + )}, + null, bound_params + ); + public static LambdaExpression MakeTupel(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) { if (lambda_applicant.Length == 3 -- GitLab