Newer
Older
{
Marco Zimmer
committed
/// \copydoc Fact.s_type
public new string s_type = "AngleFact";
/// @{ <summary>
/// One <see cref="Fact.Id">Id</see> of three <see cref="PointFact">PointFacts</see> defining Angle [<see cref="Pid1"/>, <see cref="Pid2"/>, <see cref="Pid3"/>].
/// </summary>
/// @}
/// <summary> <see langword="true"/>, if AngleFact is approximately 90° or 270°</summary>
/// <summary> \copydoc Fact.Fact </summary>
public AngleFact() : base()
{
this.Pid1 = null;
this.Pid2 = null;
this.Pid3 = null;
this.is_right_angle = false;
}
/// <summary>
/// Copies <paramref name="fact"/> by initiating new MMT %Fact.
/// </summary>
/// <param name="fact">Fact to be copied</param>
/// <param name="old_to_new"><c>Dictionary</c> mapping <paramref name="fact"/>.<see cref="getDependentFactIds"/> in <paramref name="fact"/>.<see cref="Fact._Facts"/> to corresponding <see cref="Fact.Id"/> in <paramref name="organizer"/> </param>
/// <param name="organizer">sets <see cref="_Facts"/></param>
public AngleFact(AngleFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
{
init(old_to_new[fact.Pid1], old_to_new[fact.Pid2], old_to_new[fact.Pid3]);
}
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="pid1">sets <see cref="Pid1"/></param>
/// <param name="pid2">sets <see cref="Pid2"/></param>
/// <param name="pid3">sets <see cref="Pid3"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public AngleFact(string pid1, string pid2, string pid3, FactOrganizer organizer) : base(organizer)
{
init(pid1, pid2, pid3);
}
/// <summary>
/// Initiates <see cref="Pid1"/>, <see cref="Pid2"/>, <see cref="Pid3"/>, <see cref="is_right_angle"/>, <see cref="Fact._URI"/> and creates MMT %Fact Server-Side
/// </summary>
/// <param name="pid1">sets <see cref="Pid1"/></param>
/// <param name="pid2">sets <see cref="Pid2"/></param>
/// <param name="pid3">sets <see cref="Pid3"/></param>
private void init(string pid1, string pid2, string pid3)
this.Pid1 = pid1;
this.Pid2 = pid2;
this.Pid3 = pid3;
PointFact pf1 = _Facts[pid1] as PointFact;
PointFact pf2 = _Facts[pid2] as PointFact;
PointFact pf3 = _Facts[pid3] as PointFact;
float v = GetAngle(); // sets is_right_angle
John Schihada
committed
MMTDeclaration mmtDecl;
Marco Zimmer
committed
string p1URI = pf1.Id;
string p2URI = pf2.Id;
string p3URI = pf3.Id;
John Schihada
committed
mmtDecl = generate90DegreeAngleDeclaration(v, p1URI, p2URI, p3URI);
else
mmtDecl = generateNot90DegreeAngleDeclaration(v, p1URI, p2URI, p3URI);
Marco Zimmer
committed
AddFactResponse.sendAdd(mmtDecl, out this._URI);
/// <summary>
/// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
/// </summary>
/// <param name="Pid1">sets <see cref="Pid1"/></param>
/// <param name="Pid2">sets <see cref="Pid2"/></param>
/// <param name="Pid3">sets <see cref="Pid3"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public AngleFact(string Pid1, string Pid2, string Pid3, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Pid1 = Pid1;
this.Pid2 = Pid2;
this.Pid3 = Pid3;
GetAngle();
this._URI = backendURI;
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static AngleFact parseFact(Scroll.ScrollFact fact)
string uri = fact.@ref.uri;
string
pointAUri,
pointBUri,
pointCUri;
//If angle is not a 90Degree-Angle
if (fact.GetType().Equals(typeof(Scroll.ScrollValueFact)))
{
pointAUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).uri;
pointBUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[1]).uri;
pointCUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[2]).uri;
}
//If angle is a 90Degree-Angle
else {
pointAUri = ((OMS)((OMA)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).arguments[0]).uri;
pointBUri = ((OMS)((OMA)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).arguments[1]).uri;
pointCUri = ((OMS)((OMA)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).arguments[2]).uri;
}
Marco Zimmer
committed
if (StageStatic.stage.factState.ContainsKey(pointAUri)
&& StageStatic.stage.factState.ContainsKey(pointBUri)
&& StageStatic.stage.factState.ContainsKey(pointCUri))
Marco Zimmer
committed
return new AngleFact(pointAUri, pointBUri, pointCUri, uri, StageStatic.stage.factState);
else //If dependent facts do not exist return null
return null;
John Schihada
committed
/// \copydoc Fact.generateLabel
protected override string generateLabel()
{
return (is_right_angle ? "⊾" : "∠") + _Facts[Pid1].Label + _Facts[Pid2].Label + _Facts[Pid3].Label;
/// <summary>
/// Computes smallest angle and sets <see cref="is_right_angle"/>
/// </summary>
/// <returns>Smallets angle between [<see cref="Pid1"/>, <see cref="Pid2"/>] and [<see cref="Pid2"/>, <see cref="Pid3"/>]</returns>
PointFact pf1 = _Facts[Pid1] as PointFact;
PointFact pf2 = _Facts[Pid2] as PointFact;
PointFact pf3 = _Facts[Pid3] as PointFact;
float v = Vector3.Angle((pf1.Point - pf2.Point), (pf3.Point - pf2.Point));
this.is_right_angle = Mathf.Abs(v - 90.0f) < 0.01;
return is_right_angle ? 90f : v;
}
/// <summary>
/// Constructs struct for right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="val">Angle == 90f, _not checked_</param>
/// <param name="p1URI"><see cref="Pid1"/></param>
/// <param name="p2URI"><see cref="Pid2"/></param>
/// <param name="p3URI"><see cref="Pid3"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
John Schihada
committed
private MMTDeclaration generate90DegreeAngleDeclaration(float val, string p1URI, string p2URI, string p3URI) {
MMTTerm argument = new OMA(
new OMS(MMTURIs.Eq),
new List<MMTTerm> {
new OMS(MMTURIs.RealLit),
new OMA(
new OMS(MMTURIs.Angle),
new List<MMTTerm> {
new OMS(p1URI),
new OMS(p2URI),
new OMS(p3URI)
}
),
John Schihada
committed
}
);
MMTTerm tp = new OMA(new OMS(MMTURIs.Ded), new List<MMTTerm> {argument});
MMTTerm df = null;
return new MMTSymbolDeclaration(this.Label, tp, df);
}
/// <summary>
/// Constructs struct for not-right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="val">Angle != 90f, _not checked_</param>
/// <param name="p1URI"><see cref="Pid1"/></param>
/// <param name="p2URI"><see cref="Pid2"/></param>
/// <param name="p3URI"><see cref="Pid3"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
John Schihada
committed
private MMTDeclaration generateNot90DegreeAngleDeclaration(float val, string p1URI, string p2URI, string p3URI)
{
MMTTerm lhs =
new OMA(
new OMS(MMTURIs.Angle),
new List<MMTTerm> {
new OMS(p1URI),
new OMS(p2URI),
new OMS(p3URI)
}
);
MMTTerm valueTp = new OMS(MMTURIs.RealLit);
MMTTerm value = new OMF(val);
return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
}
/// \copydoc Fact.hasDependentFacts
public override Boolean hasDependentFacts()
{
return true;
}
/// \copydoc Fact.getDependentFactIds
public override string[] getDependentFactIds()
return new string[] { Pid1, Pid2, Pid3 };
/// \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(2).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Pid3].Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.GetHashCode
Marco Zimmer
committed
public override int GetHashCode()
return this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode() ^ this.Pid3.GetHashCode();
/// \copydoc Fact.Equivalent(Fact, Fact)
Marco Zimmer
committed
protected override bool EquivalentWrapped(AngleFact f1, AngleFact f2)
Marco Zimmer
committed
if ((f1.Pid1 == f2.Pid1 && f1.Pid2 == f2.Pid2 && f1.Pid3 == f2.Pid3))// ||
//(f1.Pid1 == f2.Pid3 && f1.Pid2 == f2.Pid2 && f1.Pid3 == f2.Pid1))
return true;
PointFact p1f1 = (PointFact)_Facts[f1.Pid1];
PointFact p2f1 = (PointFact)_Facts[f1.Pid2];
PointFact p3f1 = (PointFact)_Facts[f1.Pid3];
PointFact p1f2 = (PointFact)_Facts[f2.Pid1];
PointFact p2f2 = (PointFact)_Facts[f2.Pid2];
PointFact p3f2 = (PointFact)_Facts[f2.Pid3];
Marco Zimmer
committed
return (p1f1.Equivalent(p1f2) && p2f1.Equivalent(p2f2) && p3f1.Equivalent(p3f2))
;//|| (p1f1.Equivalent(p3f2) && p2f1.Equivalent(p2f2) && p1f1.Equivalent(p3f2));