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

Refactored Fact

200+ lines abstracted
parent 3cd94c90
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,9 @@ public abstract class AbstractLineFact : FactWrappedCRTP<AbstractLineFact>
/// @}
[JsonIgnore]
public PointFact Point1 { get => (PointFact)_Facts[Pid1]; }
public PointFact Point1 { get => (PointFact)FactOrganizer.AllFacts[Pid1]; }
[JsonIgnore]
public PointFact Point2 { get => (PointFact)_Facts[Pid2]; }
public PointFact Point2 { get => (PointFact)FactOrganizer.AllFacts[Pid2]; }
/// <summary> Distance between <see cref="AbstractLineFact.Pid1"/> and <see cref="AbstractLineFact.Pid2"/></summary>
[JsonIgnore]
......@@ -98,22 +98,12 @@ protected override void RecalulateTransform()
}
/// \copydoc Fact.hasDependentFacts
public override bool hasDependentFacts()
{
return true;
}
public override bool hasDependentFacts()
=> true;
/// \copydoc Fact.getDependentFactIds
public override string[] getDependentFactIds()
{
return new string[] { Pid1, Pid2 };
}
/// \copydoc Fact.GetHashCode
public override int GetHashCode()
{
return this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode();
}
public override string[] getDependentFactIds()
=> new string[] { Pid1, Pid2 };
}
/// <summary>
......@@ -206,28 +196,21 @@ private void init(string pid1, string pid2)
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> "[" + _Facts[Pid1].Label + _Facts[Pid2].Label + "]";
=> "[" + Point1.Label + Point2.Label + "]";
/// \copydoc Fact.instantiateDisplay(GameObject, Transform)
public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
{
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Pid1].Label;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Pid2].Label;
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = Point1.Label;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = Point2.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(LineFact f1, LineFact f2)
{
if ((f1.Pid1 == f2.Pid1 && f1.Pid2 == f2.Pid2))// ||
//(f1.Pid1 == f2.Pid2 && f1.Pid2 == f2.Pid1))
return true;
return (f1.Point1.Equivalent(f2.Point1) && f1.Point2.Equivalent(f2.Point2))
;//|| (p1f1.Equivalent(p2f2) && p2f1.Equivalent(p1f2));
}
=> DependentFactsEquivalent(f1, f2);
}
/// <summary>
......@@ -304,7 +287,7 @@ protected override string generateLabel()
{
// TODO this string is too large to properly depict on scrolls.
// return "]" + _Facts[Pid1].Label + _Facts[Pid2].Label + "[";
return _Facts[Pid1].Label + _Facts[Pid2].Label;
return Point1.Label + Point2.Label;
}
/// \copydoc Fact.instantiateDisplay(GameObject, Transform)
......@@ -322,11 +305,7 @@ protected override bool EquivalentWrapped(RayFact f1, RayFact f2)
if (!Math3d.IsApproximatelyParallel(f1.Dir, f2.Dir))
return false;
PointFact p1f1 = (PointFact)_Facts[f1.Pid1];
PointFact p1f2 = (PointFact)_Facts[f2.Pid1];
PointFact p2f2 = (PointFact)_Facts[f2.Pid2];
return Math3d.IsPointApproximatelyOnLine(p1f1.Point, f1.Dir, p1f2.Point)
&& Math3d.IsPointApproximatelyOnLine(p1f1.Point, f1.Dir, p2f2.Point);
return Math3d.IsPointApproximatelyOnLine(f1.Point1.Point, f1.Dir, f2.Point1.Point)
&& Math3d.IsPointApproximatelyOnLine(f1.Point1.Point, f1.Dir, f2.Point2.Point);
}
}
This diff is collapsed.
......@@ -195,7 +195,8 @@ public FunctionFactFloat(SOMDoc Function_MMT, (float, float) domain, string uri,
/// \copydoc Fact.EquivalentWrapped
protected override bool EquivalentWrapped(FunctionFactFloat<TResult> f1, FunctionFactFloat<TResult> f2)
=> f1.Domain.t_0.IsApproximatelyEqual(f2.Domain.t_0)
=> 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);
}
......@@ -206,10 +207,10 @@ public class AttachedPositionFunction : FactWrappedCRTP<AttachedPositionFunction
public string[] funcids;
[JsonIgnore]
public Fact Fact { get => _Facts[fid]; }
public Fact Fact { get => FactOrganizer.AllFacts[fid]; }
[JsonIgnore]
public FunctionFact<float, Vector3>[] FunctionFacts {
get => funcids.Select(f => _Facts[f] as FunctionFact<float, Vector3>).ToArray();
get => funcids.Select(f => FactOrganizer.AllFacts[f] as FunctionFact<float, Vector3>).ToArray();
}
/// <summary>\copydoc Fact.Fact()</summary>
......@@ -287,11 +288,7 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans
}
protected override bool EquivalentWrapped(AttachedPositionFunction f1, AttachedPositionFunction f2)
=> f1.Fact.Equivalent(f2.Fact)
&& f1.FunctionFacts.Zip(
f2.FunctionFacts,
(ff1, ff2) => ff1.Equivalent(ff2)
).All(b => b);
=> DependentFactsEquivalent(f1, f2);
protected override void RecalulateTransform()
{
......
......@@ -48,8 +48,10 @@ public void NewExecutingInstance()
{
if (!original)
return;
var cloneComp = GameObject.Instantiate(gameObject).GetComponent<AttachedPositionFunctionBehaviour>();
AttachedPositionFunctionBehaviour cloneComp =
GameObject.Instantiate(gameObject, gameObject.transform)
.GetComponent<AttachedPositionFunctionBehaviour>();
cloneComp.Start();
cloneComp.original = false;
cloneComp.StartExecution();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment