Skip to content
Snippets Groups Projects
Commit d7e3ead0 authored by MaZiFAU's avatar MaZiFAU
Browse files

Changed how FunctFacts work

parent cda734c9
Branches
No related tags found
No related merge requests found
Showing
with 19928 additions and 27378 deletions
......@@ -325,6 +325,8 @@ MonoBehaviour:
factSpotPrefab: {fileID: 7124463502404826001, guid: 04d12e0a0a5aa884c8c7dff56f4963f6,
type: 3}
PrefabtTypeReadonly:
- AbstractAngleFact
- AbstractAngleFactWrappedCRTP`1[T]
- AbstractLineFact
- AbstractLineFactWrappedCRTP`1[T]
- AngleCircleLineFact
......@@ -337,9 +339,8 @@ MonoBehaviour:
- EqualCirclesFact
- Fact
- FactWrappedCRTP`1[T]
- FunctionFact`2[T0,TResult]
- FunctionFactCRTP`3[CRTP,T0,TResult]
- FunctionFactFloat`1[TResult]
- FunctionCallFact
- FunctionFact
- LineFact
- OnCircleFact
- OnLineFact
......@@ -353,6 +354,8 @@ MonoBehaviour:
- TruncatedConeVolumeFact
- UnEqualCirclesFact
PrefabDataConfig:
- {fileID: 6643637775379894484, guid: 30fcd362f34a9844fba66065924c6143, type: 3}
- {fileID: 6643637775379894484, guid: 30fcd362f34a9844fba66065924c6143, type: 3}
- {fileID: 7510387096843212865, guid: d6ee990520a44954fb494468665d19e9, type: 3}
- {fileID: 7510387096843212865, guid: d6ee990520a44954fb494468665d19e9, type: 3}
- {fileID: 4902928549420802332, guid: 62cec72d28de59d4c8ae782957cc10a1, type: 3}
......@@ -367,7 +370,6 @@ MonoBehaviour:
- {fileID: 2846439484187545958, guid: 5dc76e187eae4214697491bfb42773e8, type: 3}
- {fileID: 2846439484187545958, guid: 5dc76e187eae4214697491bfb42773e8, type: 3}
- {fileID: 2846439484187545958, guid: 5dc76e187eae4214697491bfb42773e8, type: 3}
- {fileID: 2846439484187545958, guid: 5dc76e187eae4214697491bfb42773e8, type: 3}
- {fileID: 4221381813544557775, guid: 8106c748f1aeb084d87fdc71dd009b67, type: 3}
- {fileID: 2115817999818309900, guid: df93bd4d977e4ab42a626f7bd06596d6, type: 3}
- {fileID: 6050914136827205310, guid: 496d04605465c7f4dba7638cc6e2dc6e, type: 3}
......@@ -491,7 +493,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -30720}
m_AnchoredPosition: {x: 0, y: -33139.805}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &8823539307371861913
......
......@@ -226,16 +226,11 @@ public static void GenerateCanonBallStage()
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI);
List<FunctionFactFloat<Vector3>> targetfunc = new CanonBallProblemCalculator(Walls, StartPos, StartVec, Gravity, dim_const, dim_A, dim_B, StageStatic.stage.solution).Compute();
foreach (var func in targetfunc)
{
string funcURI = StageStatic.stage.solution.Add(func, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(funcURI);
}
CanonBallProblemCalculator calc = new (Walls, StartPos, StartVec, Gravity, dim_const, dim_A, dim_B, StageStatic.stage.solution);
AttachedPositionFunction attachFact =
new AttachedPositionFunction(BallURI, targetfunc.Select(f => f.Id).ToArray(), StageStatic.stage.solution);
string attacheFactURI = StageStatic.stage.solution.Add(attachFact, out _, true, null, null);
string attacheFactURI = StageStatic.stage.solution.Add(
new AttachedPositionFunction(BallURI, calc.Result_FuncCall_Id.ToArray(), StageStatic.stage.solution),
out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(attacheFactURI);
//TODO:
......
......@@ -205,6 +205,7 @@ public static EqualCirclesFact AddEqualCirclesFact(string cid1, string cid2, boo
{
return (EqualCirclesFact)AddFactIfNotFound(new EqualCirclesFact(cid1, cid2, StageStatic.stage.factState), out _, samestep,gadget,scroll_label);
}
public static UnEqualCirclesFact AddUnEqualCirclesFact(string cid1, string cid2, bool samestep = false, Gadget gadget = null, string scroll_label = null)
{
return (UnEqualCirclesFact)AddFactIfNotFound(new UnEqualCirclesFact(cid1, cid2, StageStatic.stage.factState), out _, samestep,gadget,scroll_label);
......
......@@ -128,9 +128,10 @@ public static bool sendAdd(string path, string body, out string uri)
[JsonSubtypes.KnownSubType(typeof(EqualCirclesFact), nameof(EqualCirclesFact))]
[JsonSubtypes.KnownSubType(typeof(UnEqualCirclesFact), nameof(UnEqualCirclesFact))]
[JsonSubtypes.KnownSubType(typeof(AttachedPositionFunction), nameof(AttachedPositionFunction))]
[JsonSubtypes.KnownSubType(typeof(FunctionFact), nameof(FunctionFact))]
[JsonSubtypes.KnownSubType(typeof(FunctionCallFact), nameof(FunctionCallFact))]
//[JsonSubtypes.KnownSubType(typeof(FunctionFact<T0, TResult>), "FunctionFact<T0, TResult>")] //TODO: generics? => nameof does not work (generic agnostic)
[JsonSubtypes.KnownSubType(typeof(FunctionFact<float, float>), "FunctionFact<System.Single, System.Single>")]
[JsonSubtypes.KnownSubType(typeof(FunctionFactFloat<Vector3>), "FunctionFact<System.Single, UnityEngine.Vector3>")]
//[JsonSubtypes.KnownSubType(typeof(FunctionFactFloat<Vector3>), "FunctionFact<System.Single, UnityEngine.Vector3>")]
public abstract class Fact
{
/// <summary>
......
......@@ -5,18 +5,81 @@
using static SOMDocManager;
using System.Linq.Expressions;
using System.Linq;
using MoreLinq;
using MoreLinq.Extensions;
using Characters.FirstPerson;
/// <summary>
/// Represents a function taking Parameters (<typeparam name="T0">) and Returning <typeparam name="TResult">
/// </summary>
public class FunctionFact<T0, TResult> : FactWrappedCRTP<FunctionFact<T0, TResult>>
public class FunctionCallFact : FactWrappedCRTP<FunctionCallFact>
{
public string func_id;
public string arg_func_id;
public (float t_0, float t_n) Domain;
[JsonIgnore]
public FunctionFact Function_in => (FunctionFact)FactOrganizer.AllFacts[func_id];
[JsonIgnore]
public FunctionFact Function_args => (FunctionFact)FactOrganizer.AllFacts[arg_func_id];
public FunctionCallFact() : base() { }
public FunctionCallFact(string func_id, string arg_func_id, (float t_0, float t_n) Domain, FactOrganizer organizer) : base(organizer)
{
this.func_id = func_id;
this.arg_func_id = arg_func_id;
this.Domain = Domain;
_URI = func_id.ToString() + arg_func_id.ToString() + Domain.ToString();
}
public object[] Call(float t)
{
if (t < Domain.t_0 || t > Domain.t_n)
return null;
return Function_in.Function(Function_args.Function(new object[] { t }));
}
public override bool HasDependentFacts
=> true;
protected override string[] GetGetDependentFactIds()
=> new[] { func_id, arg_func_id };
public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
{
/// \copydoc Fact.s_type
[JsonProperty]
protected new string s_type = "FunctionFact<" + typeof(T0) + ", " + typeof(TResult) + ">";
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
//obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = this.Label;
//obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
protected override bool EquivalentWrapped(FunctionCallFact f1, FunctionCallFact f2)
=> f1.Domain.t_0.IsApproximatelyEqual(f2.Domain.t_0)
&& f1.Domain.t_n.IsApproximatelyEqual(f2.Domain.t_n)
&& (DependentFactsEquivalent(f1, f2)
|| (f1.Function_in.Equivalent(f2.Function_in)
&& f1.Function_args.Equivalent(f2.Function_args)
));
protected override MMTDeclaration MakeMMTDeclaration()
{
throw new NotImplementedException();
}
protected override void RecalculateTransform()
{
Position = Function_in.Position;
Rotation = Function_in.Rotation;
LocalScale = Function_in.LocalScale;
}
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new FunctionCallFact(old_to_new[this.func_id], old_to_new[this.arg_func_id], this.Domain, organizer);
}
public class FunctionFact : FactWrappedCRTP<FunctionFact>
{
public SOMDoc Function_SOMDoc;
//TODO: doc
......@@ -24,10 +87,10 @@ public class FunctionFact<T0, TResult> : FactWrappedCRTP<FunctionFact<T0, TResul
public LambdaExpression Function_expression;
[JsonIgnore]
public Func<T0, TResult> Function;
public Type[] Signature;
//TODO
public (T0 t_0, T0 t_n) Domain = (default, default);
[JsonIgnore]
public Func<object[], object[]> Function;
/// <summary> \copydoc Fact.Fact </summary>
public FunctionFact() : base() { }
......@@ -38,19 +101,18 @@ public FunctionFact() : base() { }
/// </summary>
/// <param name="Function_SOMDoc">sets <see cref="Function_SOMDoc"/> and contains the Abstract Syntax Tree</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public FunctionFact(SOMDoc Function_SOMDoc, (T0, T0) domain, FactOrganizer organizer) : base(organizer)
public FunctionFact(SOMDoc Function_SOMDoc, FactOrganizer organizer) : base(organizer)
{
this.Function_SOMDoc = Function_SOMDoc;
this.Domain = domain;
this.Function_expression = this.Function_SOMDoc.GetLambdaExpression();
this.Function_expression = this.Function_SOMDoc.PartialInvokeCastingLambdaExpression(out Signature);
////TODO: catch
//string debug_tostring = Function_expression.ToString();
//dynamic debug_function = Function_expression.Compile();
this.Function = this.Function_expression.Compile() as Func<T0, TResult>;
//Delegate debug_function = Function_expression.Compile();
this.Function = this.Function_expression.Compile() as Func<object[], object[]>;
//ducktaped:
_URI = this.Function_expression.ToString() + domain.ToString();
_URI = this.Function_expression.ToString();
////TODO: Function_SOMDoc+domain
......@@ -70,16 +132,15 @@ public FunctionFact(SOMDoc Function_SOMDoc, (T0, T0) domain, FactOrganizer organ
/// <param name="function_expression">sets <see cref="Function_expression"/> and contains the Abstract Syntax Tree</param>
/// <param name="uri">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public FunctionFact(SOMDoc Function_SOMDoc, (T0, T0) domain, string uri, FactOrganizer organizer) : base(organizer)
public FunctionFact(SOMDoc Function_SOMDoc, string uri, FactOrganizer organizer) : base(organizer)
{
this.Function_SOMDoc = Function_SOMDoc;
this.Domain = domain;
this.Function_expression = Function_SOMDoc.GetLambdaExpression();
this.Function_expression = Function_SOMDoc.PartialInvokeCastingLambdaExpression(out Signature);
////TODO: catch
//string debug_tostring = Function_expression.ToString();
//dynamic debug_function = Function_expression.Compile();
this.Function = this.Function_expression.Compile() as Func<T0, TResult>;
this.Function = this.Function_expression.Compile() as Func<object[], object[]>;
this._URI = uri;
_ = this.Label;
......@@ -88,7 +149,7 @@ public FunctionFact(SOMDoc Function_SOMDoc, (T0, T0) domain, string uri, FactOrg
protected override void RecalculateTransform() { }
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static FunctionFact<T0, TResult> parseFact(Scroll.ScrollFact fact)
public new static FunctionFact parseFact(Scroll.ScrollFact fact)
{// TODO Correctness
string uri = fact.@ref.uri;
OMA df = (OMA)((Scroll.ScrollSymbolFact)fact).df;
......@@ -100,17 +161,16 @@ protected override void RecalculateTransform() { }
if (!ParsingDictionary.parseTermsToId.ContainsKey(parse_id))
ParsingDictionary.parseTermsToId[parse_id] = uri;
return new FunctionFact<T0, TResult>(df, (default, default), uri, StageStatic.stage.factState);
return new FunctionFact(df, uri, StageStatic.stage.factState);
}
/// \copydoc Fact.hasDependentFacts
public override bool HasDependentFacts => false;
public override bool HasDependentFacts
=> false;
/// \copydoc Fact.getDependentFactIds
protected override string[] GetGetDependentFactIds()
{
return new string[] { };
}
=> new string[] { };
/// \copydoc Fact.GetHashCode
public override int GetHashCode()
......@@ -126,13 +186,11 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans
}
/// \copydoc Fact.EquivalentWrapped
protected override bool EquivalentWrapped(FunctionFact<T0, TResult> f1, FunctionFact<T0, TResult> f2)
//=> f1.Function_SOMDoc.Equivalent(f2.Function_SOMDoc);
// && f1.domain.Equals(f2.domain); // no! => exact instead of similar => CRTP
=> false;
protected override bool EquivalentWrapped(FunctionFact f1, FunctionFact f2)
=> f1.Function_SOMDoc.Equivalent(f2.Function_SOMDoc);
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new FunctionFact<T0, TResult>(this.Function_SOMDoc.MapURIs(old_to_new), this.Domain, organizer);
=> new FunctionFact(this.Function_SOMDoc.MapURIs(old_to_new), organizer);
protected override MMTDeclaration MakeMMTDeclaration()
{
......@@ -140,65 +198,18 @@ protected override MMTDeclaration MakeMMTDeclaration()
}
}
/// <summary>
/// Implements CRTP for <see cref="FunctionFact"/>; Escalates constructors;
/// </summary>
/// <typeparam name="CRTP">class, which inherits from FunctionFactCRTP</typeparam>
public abstract class FunctionFactCRTP<CRTP, T0, TResult> : FunctionFact<T0, TResult> where CRTP : FunctionFactCRTP<CRTP, T0, TResult>
{
/// <summary> \copydoc FunctionFact.FunctionFact </summary>
protected FunctionFactCRTP() : base() { }
/// <summary> \copydoc FunctionFact.FunctionFact(SOMDoc, Tuple{T0, T0}, FactOrganizer) </summary>
protected FunctionFactCRTP(SOMDoc Function_MMT, (T0, T0) domain, FactOrganizer organizer) : base(Function_MMT, domain, organizer) { }
/// <summary> \copydoc FunctionFact.FunctionFact(LambdaExpression, string, FactOrganizer) </summary>
protected FunctionFactCRTP(SOMDoc Function_MMT, (T0, T0) domain, string uri, FactOrganizer organizer) : base(Function_MMT, domain, uri, organizer) { }
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(FunctionFact<T0, TResult> f1, FunctionFact<T0, TResult> f2)
=> EquivalentWrapped((CRTP)f1, (CRTP)f2)
&& base.EquivalentWrapped(f1, f2);
/// <summary>CRTP step of <see cref="EquivalentWrapped(FunctionFact{T0, TResult}, FunctionFact{T0, TResult})"/></summary>
protected abstract bool EquivalentWrapped(CRTP f1, CRTP f2);
}
/// <summary>
/// Used to overrite FunctionFact.EquivalentWrapped for special case T0 = float
/// </summary>
public class FunctionFactFloat<TResult> : FunctionFactCRTP<FunctionFactFloat<TResult>, float, TResult>
{
/// <summary> \copydoc FunctionFact.FunctionFact </summary>
public FunctionFactFloat() : base() { }
/// <summary> \copydoc FunctionFact.FunctionFact(SOMDoc, Tuple{T0, T0}, FactOrganizer) </summary>
public FunctionFactFloat(SOMDoc Function_MMT, (float, float) domain, FactOrganizer organizer) : base(Function_MMT, domain, organizer) { }
/// <summary> \copydoc FunctionFact.FunctionFact(LambdaExpression, string, FactOrganizer) </summary>
public FunctionFactFloat(SOMDoc Function_MMT, (float, float) domain, string uri, FactOrganizer organizer) : base(Function_MMT, domain, uri, organizer) { }
/// \copydoc Fact.EquivalentWrapped
protected override bool EquivalentWrapped(FunctionFactFloat<TResult> f1, FunctionFactFloat<TResult> f2)
=> f1.Function_SOMDoc.Equivalent(f2.Function_SOMDoc)
&& f1.Domain.t_0.IsApproximatelyEqual(f2.Domain.t_0)
&& f1.Domain.t_n.IsApproximatelyEqual(f2.Domain.t_n);
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new FunctionFactFloat<TResult>(this.Function_SOMDoc.MapURIs(old_to_new), this.Domain, organizer);
}
public class AttachedPositionFunction : FactWrappedCRTP<AttachedPositionFunction>
{
public string fid;
public string[] funcids;
public string[] func_call_ids;
[JsonIgnore]
public Fact Fact { get => FactOrganizer.AllFacts[fid]; }
[JsonIgnore]
public FunctionFact<float, Vector3>[] FunctionFacts {
get => funcids.Select(f => FactOrganizer.AllFacts[f] as FunctionFact<float, Vector3>).ToArray();
public FunctionCallFact[] FunctionFacts
{
get => func_call_ids.Select(f => FactOrganizer.AllFacts[f] as FunctionCallFact).ToArray();
}
/// <summary>\copydoc Fact.Fact()</summary>
......@@ -206,25 +217,24 @@ public AttachedPositionFunction() : base() { }
/// <summary>\copydoc Fact.Fact(FactOrganizer)</summary>
public AttachedPositionFunction(string fid, string[] funcids, FactOrganizer organizer) : base(organizer)
=> init(fid, funcids);
{
init(fid, funcids);
//TODO: call MMT, set URI
_URI = Fact.Id + "{" + string.Join(", ", FunctionFacts.Select(f => f.Id)) + "}";
}
private void init(string fid, string[] funcids)
{
this.fid = fid;
this.funcids = new string[funcids.Length];
funcids.CopyTo(this.funcids, 0);
this.func_call_ids = new string[funcids.Length];
funcids.CopyTo(this.func_call_ids, 0);
//TODO: call MMT, set URI
_URI = Fact.Id + "{" + string.Join(", ", FunctionFacts.Select(f => f.Id)) + "}";
}
protected AttachedPositionFunction(string fid, string[] funcids, string uri, FactOrganizer organizer) : base(organizer)
{
this.fid = fid;
this.funcids = new string[funcids.Length];
funcids.CopyTo(this.funcids, 0);
init(fid, funcids);
_URI = uri;
}
......@@ -244,20 +254,15 @@ protected AttachedPositionFunction(string fid, string[] funcids, string uri, Fac
return new AttachedPositionFunction(default, default, uri, StageStatic.stage.factState);
}
protected override string[] GetGetDependentFactIds()
{
string[] ret = new string[1 + funcids.Length];
funcids.CopyTo(ret, 1);
ret[0] = fid;
public override bool HasDependentFacts
=> true;
return ret;
}
protected override string[] GetGetDependentFactIds()
=> new string[] { fid }.ShallowCloneAppend(func_call_ids);
public override int GetHashCode()
=> Fact.GetHashCode() ^ FunctionFacts.GetHashCode();
public override bool HasDependentFacts => true;
public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
{
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
......@@ -277,7 +282,7 @@ protected override void RecalculateTransform()
}
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new AttachedPositionFunction(old_to_new[this.fid], this.funcids.Select(id => old_to_new[id]).ToArray(), organizer);
=> new AttachedPositionFunction(old_to_new[this.fid], this.func_call_ids.Select(id => old_to_new[id]).ToArray(), organizer);
protected override MMTDeclaration MakeMMTDeclaration()
{
......
......@@ -8,7 +8,7 @@ public class AttachedPositionFunctionBehaviour : FactObject
{
private Transform startcondition;
public List<FunctionFact<float, Vector3>> f_t_to_pos;
public List<FunctionCallFact> f_t_to_pos;
//public List<FunctionFact<float, Quaternion>> f_t_to_rot;
//public List<FunctionFact<float, Vector3>> f_t_to_scale;
......@@ -78,7 +78,7 @@ void Update()
if (!executing)
return;
if (time > f_t_to_pos[active_func_ind].Domain.t_n)
while (time > f_t_to_pos[active_func_ind].Domain.t_n)
{
active_func_ind++;
......@@ -88,12 +88,12 @@ void Update()
return;
}
time = f_t_to_pos[active_func_ind - 1].Domain.t_n
+ f_t_to_pos[active_func_ind + 0].Domain.t_0
- time;
time = time
- f_t_to_pos[active_func_ind - 1].Domain.t_n
+ f_t_to_pos[active_func_ind + 0].Domain.t_0;
}
transform.position = f_t_to_pos[active_func_ind].Function(time);
transform.position = (Vector3)f_t_to_pos[active_func_ind].Call(time)[0];
time += Time.deltaTime;
}
......
......@@ -16,7 +16,9 @@ public class CanonBallProblemCalculator
private Vector3 Gravity;
private List<Wall> Walls;
private List<FunctionFactFloat<Vector3>> Result;
public string Result_MovementFunc_Id;
public List<string> Result_ArgsFunc_Id;
public List<string> Result_FuncCall_Id;
public struct Wall
{
......@@ -41,24 +43,30 @@ public CanonBallProblemCalculator(List<Wall> walls, Vector3 starPos, Vector3 sta
StartVel = starVec;
Gravity = gravity;
FactOrganizer = factOrganizer;
Compute();
}
public List<FunctionFactFloat<Vector3>> Compute()
private void Compute()
{
SOMDoc BuildOMA(Vector3 Pos, Vector3 Vel)
SOMDoc BuildOMA_XVA()
{ //Pos = Pos + Vel * t + 0.5 * g * t**2
return new OMBINDC("t", "R", //typeof(float),
return
new OMBINDC("Pos", typeof(Vector3),
new OMBINDC("Vel", typeof(Vector3),
new OMBINDC("Acc", typeof(Vector3),
new OMBINDC("t", "R",
new OMA(
new OMS(MMT_OMS_URI.Add),
new() {
SOMDoc.MakeUnityEngineVector3(Pos),
new OMV("Pos"),
new OMA(
new OMS(MMT_OMS_URI.Add),
new() {
new OMA(
new OMS(MMT_OMS_URI.Multiply),
new() {
SOMDoc.MakeUnityEngineVector3(Vel),
new OMV("Vel"),
new OMV("t"),
}
),
......@@ -69,13 +77,27 @@ SOMDoc BuildOMA(Vector3 Pos, Vector3 Vel)
new OMA(
new OMS(MMT_OMS_URI.Multiply),
new() {
SOMDoc.MakeUnityEngineVector3(Gravity),
new OMV("Acc"),
new OMA(
new OMS(MMT_OMS_URI.Multiply),
new() {
new OMV("t"),
new OMV("t"),
}),}),}),}),}));
}),}),}),}),})))));
}
SOMDoc BuildOMAPath(Vector3 Pos, Vector3 Vel)
{ //t -> [Pos, Vel, g, t]
return new OMBINDC("t", "R",
new OMA(
new OMS(MMT_OMS_URI.MakeObjectArray),
new() {
SOMDoc.MakeUnityEngineVector3(Pos),
SOMDoc.MakeUnityEngineVector3(Vel),
SOMDoc.MakeUnityEngineVector3(Gravity),
new OMV("t"),
}
));
}
//Pos = Pos + Vel * t + 0.5 * g * t**2
......@@ -124,12 +146,17 @@ float SolveForDistanceOnPlane(Vector3 Pos, Vector3 Vel, LineFact Top, float t)
return dir.magnitude * Math.Sign(dot);
};
var Result_Movement = new FunctionFact(BuildOMA_XVA(), FactOrganizer);
Result_MovementFunc_Id = FactOrganizer.Add(Result_Movement, out _, false, null, null);
Vector3 PlaneNorm = Vector3.zero;
PlaneNorm[Dim_const] = 1;
Vector3 pos = StartPos;
Vector3 vel = StartVel;
Result = new();
Result_ArgsFunc_Id = new();
Result_FuncCall_Id = new();
for (int i = 0; i < MaxIter; i++)
{
......@@ -152,7 +179,15 @@ float SolveForDistanceOnPlane(Vector3 Pos, Vector3 Vel, LineFact Top, float t)
? hits[0]
: (default(Wall), float.PositiveInfinity, default);
Result.Add(new (BuildOMA(pos, vel), (-(float)Math3d.vectorPrecission, next_t), FactOrganizer));
Result_ArgsFunc_Id.Add(
FactOrganizer.Add(
new FunctionFact(BuildOMAPath(pos, vel), FactOrganizer),
out _, true, null, null));
Result_FuncCall_Id.Add(
FactOrganizer.Add(
new FunctionCallFact(Result_MovementFunc_Id, Result_ArgsFunc_Id.Last(), (-(float)Math3d.vectorPrecission, next_t), FactOrganizer),
out _, true, null, null));
if (hits.Length == 0)
break;
......@@ -167,6 +202,6 @@ float SolveForDistanceOnPlane(Vector3 Pos, Vector3 Vel, LineFact Top, float t)
vel = bounce_fac * Vector3.Reflect(vel_at_bounce, LineFactNorm);
}
return Result;
return;
}
}
......@@ -68,8 +68,8 @@ public void OnAfterDeserialize()
_PrefabDictionary = new();
for (int i = 0; i != Math.Min(PrefabtTypeReadonly.Count, PrefabDataConfig.Count); i++)
// if (PrefabDataConfig[i] != null)
_PrefabDictionary.Add(
TypeExtensions<Fact>.UAssemblyInheritenceTypes.First(type => type.ToString() == PrefabtTypeReadonly[i]),
_PrefabDictionary.TryAdd(
TypeExtensions<Fact>.UAssemblyInheritenceTypes.FirstOrDefault(type => type.ToString() == PrefabtTypeReadonly[i]),
PrefabDataConfig[i]
);
}
......
......@@ -62,6 +62,7 @@ public static class MMT_OMS_URI
public static readonly string Subtract = "Subtract";
public static readonly string SquareRoot = "SquareRoot";
public static readonly string MakeUnityEngineVector3 = "UnityEngine.Vector3";
public static readonly string MakeObjectArray = "MakeObjectArray";
}
......@@ -81,6 +82,8 @@ public static class SOMDoctoLambdaExpression<T>
MakeCos},
{ MMT_OMS_URI.MakeUnityEngineVector3,
MakeUnityEngineVector3},
{ MMT_OMS_URI.MakeObjectArray,
MakeArray},
};
private static readonly Dictionary<string, ExpressionType> MMTtoBinaryExpressionType = new()
......@@ -241,7 +244,7 @@ private static LambdaExpression MakeSin(LambdaExpression[] lambda_args, Paramete
{
float => ParseFuncUUToExpression<float>(MathF.Sin),
double => ParseFuncUUToExpression<double>(Math.Sin),
_ => throw new NotImplementedException("Sinus for " + typeof(T))
_ => throw new NotImplementedException("Sinus for " + nameof(T) + "=" + typeof(T))
},
"Sin", lambda_args, bound_params, 1
);
......@@ -252,7 +255,7 @@ private static LambdaExpression MakeCos(LambdaExpression[] lambda_args, Paramete
{
float => ParseFuncUUToExpression<float>(MathF.Cos),
double => ParseFuncUUToExpression<double>(Math.Cos),
_ => throw new NotImplementedException("Cosinus for " + typeof(T))
_ => throw new NotImplementedException("Cosinus for " + nameof(T) + "=" + typeof(T))
},
"Cos", lambda_args, bound_params, 1
);
......@@ -262,6 +265,15 @@ private static LambdaExpression MakeUnityEngineVector3(LambdaExpression[] args_l
(Expression<Func<float, float, float, Vector3>>)((x, y, z) => new Vector3(x, y, z)),
"UnityEngineVector3", args_lamda, bound_params, 3
);
private static LambdaExpression MakeArray(LambdaExpression[] args_lamda, ParameterExpression[] bound_params)
=> Expression.Lambda(
Expression.NewArrayInit(
typeof(object),
args_lamda.Select(l => Expression.Convert(l.Body, typeof(object)))
),
bound_params
);
}
......@@ -310,6 +322,56 @@ public static bool Equivalent(SOMDoc sd1, SOMDoc sd2)
public abstract bool Equivalent(SOMDoc sd2);
public LambdaExpression PartialInvokeCastingLambdaExpression(out Type[] signature_args, object[] args = null)
{
LambdaExpression lambda_orig =
GetLambdaExpression(new LambdaExpression[0], new ParameterExpression[0]);
signature_args = new Type[lambda_orig.Parameters.Count + 1];
ParameterExpression object_arr = Expression.Parameter(typeof(object[]), "PARAMS_Arr");
Expression[] cast_new_to_signature = new Expression[lambda_orig.Parameters.Count];
int n_params = 0;
for (int i = 0; i < lambda_orig.Parameters.Count; i++)
{
if (args != null && args.Length < i && args[i] != null)
{
cast_new_to_signature[i] =
Expression.Constant(args[i], lambda_orig.Parameters[i].Type);
continue;
}
signature_args[n_params] = lambda_orig.Parameters[i].Type;
cast_new_to_signature[i] =
Expression.Convert(
Expression.ArrayIndex(
object_arr,
Expression.Constant(i)
),
signature_args[n_params]
);
n_params++;
}
signature_args[n_params] = lambda_orig.ReturnType;
signature_args = signature_args.Slice(0, n_params + 1).ToArray();
return Expression.Lambda(
typeof(Array).IsAssignableFrom(lambda_orig.ReturnType)
? Expression.Convert(
Expression.Invoke(lambda_orig, cast_new_to_signature),
typeof(object[]))
: Expression.NewArrayInit(
typeof(object),
new Expression[] { Expression.Convert(Expression.Invoke(lambda_orig, cast_new_to_signature), typeof(object)) }),
object_arr
);
}
public LambdaExpression GetLambdaExpression()
=> GetLambdaExpression(new LambdaExpression[0], new ParameterExpression[0]);
......@@ -385,7 +447,9 @@ public OMBINDC(string name, Type type, SOMDoc lambdabody) : base()
}
protected override bool EquivalentWrapped(OMBINDC sd2)
=> this.type == sd2.type && this.name.Equals(sd2.name);
=> this.type == sd2.type
&& this.name.Equals(sd2.name)
&& this.lambdabody.Equivalent(sd2.lambdabody);
protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_args, ParameterExpression[] bound_params)
{
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
"ValidationSet": [
{
"MasterIDs": [
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1652"
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3800"
],
"SolutionIndex": [],
"RelationIndex": [],
......@@ -16,21 +16,22 @@
}
],
"ExposedSolutionFacts": [],
"ImmutableFacts": [],
"WorkflowGadgetDict": {
"-1": null
},
"MetaInf": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1650": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3798": {
"workflow_id": 0,
"active": true,
"isImmutable": false
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1651": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3799": {
"workflow_id": 1,
"active": true,
"isImmutable": false
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1652": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3800": {
"workflow_id": 2,
"active": true,
"isImmutable": false
......@@ -38,34 +39,34 @@
},
"Workflow": [
{
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1650",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3798",
"samestep": false,
"steplink": 3,
"creation": true,
"gadget_rank": -1,
"scroll_label": null,
"GadgetFlow": [],
"GadgetTime": 0.34399739999935264
"GadgetTime": 0.17582429997855797
},
{
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1651",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3799",
"samestep": true,
"steplink": 0,
"creation": true,
"gadget_rank": -1,
"scroll_label": null,
"GadgetFlow": [],
"GadgetTime": 0.34399739999935264
"GadgetTime": 0.17582429997855797
},
{
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1652",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3800",
"samestep": true,
"steplink": 0,
"creation": true,
"gadget_rank": -1,
"scroll_label": null,
"GadgetFlow": [],
"GadgetTime": 0.34399739999935264
"GadgetTime": 0.17582429997855797
}
],
"marker": 3,
......@@ -76,7 +77,7 @@
"MaxLabelId": 2,
"UnusedLabelIds": [],
"JsonFactSpace": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1650": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3798": {
"Point": {
"x": 0.0,
"y": 0.0,
......@@ -93,12 +94,12 @@
},
"s_type": "PointFact",
"DependentFactIds": [],
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1650",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3798",
"Label": "A",
"hasCustomLabel": false,
"LabelId": 1
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1651": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3799": {
"Point": {
"x": 0.0,
"y": 6.0,
......@@ -122,15 +123,15 @@
},
"s_type": "PointFact",
"DependentFactIds": [],
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1651",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3799",
"Label": "B",
"hasCustomLabel": false,
"LabelId": 2
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1652": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3800": {
"s_type": "LineFact",
"Pid1": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1650",
"Pid2": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1651",
"Pid1": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3798",
"Pid2": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3799",
"Dir": {
"x": 0.0,
"y": -1.0,
......@@ -139,10 +140,10 @@
"sqrMagnitude": 1.0
},
"DependentFactIds": [
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1650",
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1651"
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3798",
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3799"
],
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1652",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3800",
"Label": "[AB]",
"hasCustomLabel": false,
"LabelId": 0
......
......@@ -8,7 +8,7 @@
"ValidationSet": [
{
"MasterIDs": [
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1655"
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3803"
],
"SolutionIndex": [],
"RelationIndex": [],
......@@ -16,7 +16,7 @@
},
{
"MasterIDs": [
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1655"
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3803"
],
"SolutionIndex": [],
"RelationIndex": [],
......@@ -34,21 +34,22 @@
}
],
"ExposedSolutionFacts": [],
"ImmutableFacts": [],
"WorkflowGadgetDict": {
"-1": null
},
"MetaInf": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1653": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3801": {
"workflow_id": 0,
"active": true,
"isImmutable": false
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1654": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3802": {
"workflow_id": 1,
"active": true,
"isImmutable": false
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1655": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3803": {
"workflow_id": 2,
"active": true,
"isImmutable": false
......@@ -56,34 +57,34 @@
},
"Workflow": [
{
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1653",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3801",
"samestep": false,
"steplink": 3,
"creation": true,
"gadget_rank": -1,
"scroll_label": null,
"GadgetFlow": [],
"GadgetTime": 0.34399739999935264
"GadgetTime": 0.17582429997855797
},
{
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1654",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3802",
"samestep": true,
"steplink": 0,
"creation": true,
"gadget_rank": -1,
"scroll_label": null,
"GadgetFlow": [],
"GadgetTime": 0.34399739999935264
"GadgetTime": 0.17582429997855797
},
{
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1655",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3803",
"samestep": true,
"steplink": 0,
"creation": true,
"gadget_rank": -1,
"scroll_label": null,
"GadgetFlow": [],
"GadgetTime": 0.34399739999935264
"GadgetTime": 0.17582429997855797
}
],
"marker": 3,
......@@ -94,7 +95,7 @@
"MaxLabelId": 2,
"UnusedLabelIds": [],
"JsonFactSpace": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1653": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3801": {
"Point": {
"x": 0.0,
"y": 0.0,
......@@ -111,12 +112,12 @@
},
"s_type": "PointFact",
"DependentFactIds": [],
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1653",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3801",
"Label": "A",
"hasCustomLabel": false,
"LabelId": 1
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1654": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3802": {
"Point": {
"x": 0.0,
"y": 6.0,
......@@ -140,15 +141,15 @@
},
"s_type": "PointFact",
"DependentFactIds": [],
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1654",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3802",
"Label": "B",
"hasCustomLabel": false,
"LabelId": 2
},
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1655": {
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3803": {
"s_type": "LineFact",
"Pid1": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1653",
"Pid2": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1654",
"Pid1": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3801",
"Pid2": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3802",
"Dir": {
"x": 0.0,
"y": -1.0,
......@@ -157,10 +158,10 @@
"sqrMagnitude": 1.0
},
"DependentFactIds": [
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1653",
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1654"
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3801",
"http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3802"
],
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1655",
"Id": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3803",
"Label": "[AB]",
"hasCustomLabel": false,
"LabelId": 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment