Newer
Older
using System;
using System.Collections.Generic;
using static CommunicationEvents;
Marco Zimmer
committed
public class ParsingDictionary {
public static Dictionary<string, Func<Scroll.ScrollFact, Fact>> parseFactDictionary = new Dictionary<string, Func<Scroll.ScrollFact, Fact>>() {
{MMTURIs.Point, PointFact.parseFact},
{MMTURIs.Metric, LineFact.parseFact},
{MMTURIs.Angle, AngleFact.parseFact},
{MMTURIs.LineType, RayFact.parseFact},
{MMTURIs.OnLine, OnLineFact.parseFact},
{MMTURIs.Eq, AngleFact.parseFact}
public class AddFactResponse
{
//class to Read AddFact Responses.
// public string factUri;
// public string factValUri;
public string uri;
Marco Zimmer
committed
public static bool sendAdd(MMTDeclaration mmtDecl, out string uri)
{
string body = MMTSymbolDeclaration.ToJson(mmtDecl);
return sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body, out uri);
}
public static bool sendAdd(string path, string body, out string uri)
{
if (!CommunicationEvents.ServerRunning)
{
Debug.LogWarning("Server not running");
Marco Zimmer
committed
uri = null;
return false;
Marco Zimmer
committed
if(VerboseURI)
Debug.Log("Sending to Server:\n" + body);
//Put constructor parses stringbody to byteArray internally (goofy workaround)
UnityWebRequest www = UnityWebRequest.Put(path, body);
www.method = UnityWebRequest.kHttpVerbPOST;
www.SetRequestHeader("Content-Type", "application/json");
www.timeout = 1;
//TODO: implement real asynchronous communication ...
AsyncOperation op = www.SendWebRequest();
while (!op.isDone) ;
if (www.result == UnityWebRequest.Result.ConnectionError
|| www.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogWarning(www.error);
Marco Zimmer
committed
uri = null;
return false;
}
else
{
string answer = www.downloadHandler.text;
Marco Zimmer
committed
AddFactResponse res = JsonUtility.FromJson<AddFactResponse>(answer);
if (VerboseURI)
Debug.Log("Server added Fact:\n" + res.uri);
uri = res.uri;
return true;
}
}
}
public GameObject Representation;
public string Id {
get { return _URI; }
set { if (_URI == null) _URI = value; }
}
Marco Zimmer
committed
// should be called once a constructor call
Marco Zimmer
committed
public string Label {
get { // in case of renamed dependables
return hasCustomLabel ?
_CustomLabel :
generateLabel();
Marco Zimmer
committed
}
set { rename(value); }
}
public bool hasCustomLabel {
get;
private set;
Marco Zimmer
committed
}
protected string _CustomLabel = null;
private int LabelId = 0;
protected FactOrganizer _Facts;
Marco Zimmer
committed
private static int MaxLabelId = 0;
private static SortedSet<int> UnusedLabelIds = new SortedSet<int>();
protected Fact()
// 0 parameter constructor for Json
{
this._Facts = new FactOrganizer();
hasCustomLabel = false;
}
protected Fact(FactOrganizer organizer)
{
this._Facts = organizer;
hasCustomLabel = false;
}
protected Fact(Fact fact, FactOrganizer organizer)
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
this._Facts = organizer;
hasCustomLabel = fact.hasCustomLabel;
if (hasCustomLabel)
_CustomLabel = fact.Label;
}
//TODO: notify about updated dependable Labelnames for UI
//TODO: check for colissions with not yet generated names
public bool rename(string newLabel)
// returns true if succeded
{
if (string.IsNullOrEmpty(newLabel))
// switch back to autogenerated
{
generateLabel();
_CustomLabel = null;
hasCustomLabel = false;
return true;
}
else
// set CustomLabel if available
{
if (_Facts.ContainsLabel(newLabel))
return false;
freeAutoLabel();
_CustomLabel = newLabel;
hasCustomLabel = true;
Marco Zimmer
committed
//If FactType depends on other Facts, e.g. AngleFacts depend on 3 PointFacts
Marco Zimmer
committed
public abstract bool hasDependentFacts();
public abstract string[] getDependentFactIds();
public abstract GameObject instantiateDisplay(GameObject prefab, Transform transform);
public static void Clear()
{
MaxLabelId = 0;
UnusedLabelIds.Clear();
}
Marco Zimmer
committed
public virtual void delete(bool keep_clean = true)
Marco Zimmer
committed
if (keep_clean)
Marco Zimmer
committed
Marco Zimmer
committed
if (VerboseURI)
Marco Zimmer
committed
Debug.Log("Server removed Fact:\n" + this.Id);
Marco Zimmer
committed
public abstract bool Equivalent(Fact f2);
public abstract bool Equivalent(Fact f1, Fact f2);
public abstract override int GetHashCode();
Marco Zimmer
committed
protected virtual string generateLabel()
{
if (LabelId == 0)
if (UnusedLabelIds.Count == 0)
LabelId = ++MaxLabelId;
else
{
LabelId = UnusedLabelIds.Min;
UnusedLabelIds.Remove(LabelId);
}
Marco Zimmer
committed
else if (LabelId < 0)
// reload Label if possible
LabelId = UnusedLabelIds.Remove(-LabelId) ? -LabelId : 0;
return ((char)(64 + LabelId)).ToString();
}
// TODO? only get _Fact to freeLabel/
public /*protected internal*/ void freeAutoLabel()
{
if (LabelId > 0)
UnusedLabelIds.Add(LabelId);
// store Label for name-persistance
Marco Zimmer
committed
LabelId = -LabelId;
}
Marco Zimmer
committed
public abstract class FactWrappedCRTP<T>: Fact where T: FactWrappedCRTP<T>
protected FactWrappedCRTP() : base() { }
protected FactWrappedCRTP(FactOrganizer organizer) : base(organizer) { }
protected FactWrappedCRTP(FactWrappedCRTP<T> fact, FactOrganizer organizer) : base(fact, organizer) { }
Marco Zimmer
committed
public override bool Equivalent(Fact f2)
{
return Equivalent(this, f2);
}
public override bool Equivalent(Fact f1, Fact f2)
{
return f1.GetType() == f2.GetType() && EquivalentWrapped((T)f1, (T)f2);
Marco Zimmer
committed
}
protected abstract bool EquivalentWrapped(T f1, T f2);
}
public abstract class AbstractLineFact: FactWrappedCRTP<AbstractLineFact>
{
//Id's of the 2 Point-Facts that are connected
Marco Zimmer
committed
// normalized Direction from Pid1 to Pid2
public Vector3 Dir;
//only for temporary Use of LineFacts.
Marco Zimmer
committed
protected AbstractLineFact() : base()
{
Pid1 = null;
Pid2 = null;
Dir = Vector3.zero;
}
protected AbstractLineFact(AbstractLineFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
{
set_public_members(old_to_new[fact.Pid1], old_to_new[fact.Pid2]);
}
protected AbstractLineFact(string pid1, string pid2, FactOrganizer organizer): base(organizer)
{
set_public_members(pid1, pid2);
}
protected AbstractLineFact(string pid1, string pid2, string backendURI, FactOrganizer organizer) : base(organizer)
{
set_public_members(pid1, pid2);
this._URI = backendURI;
}
Marco Zimmer
committed
private void set_public_members(string pid1, string pid2)
Marco Zimmer
committed
{
this.Pid1 = pid1;
this.Pid2 = pid2;
PointFact pf1 = _Facts[pid1] as PointFact;
PointFact pf2 = _Facts[pid2] as PointFact;
Marco Zimmer
committed
this.Dir = (pf2.Point - pf1.Point).normalized;
}
public override bool hasDependentFacts()
{
return true;
}
public override string[] getDependentFactIds()
Marco Zimmer
committed
{
Marco Zimmer
committed
}
public override int GetHashCode()
{
return this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode();
Marco Zimmer
committed
}
}
public abstract class AbstractLineFactWrappedCRTP<T>: AbstractLineFact where T: AbstractLineFactWrappedCRTP<T>
{
protected AbstractLineFactWrappedCRTP () : base() { }
Marco Zimmer
committed
protected AbstractLineFactWrappedCRTP (AbstractLineFactWrappedCRTP<T> fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, old_to_new, organizer) { }
protected AbstractLineFactWrappedCRTP (string pid1, string pid2, FactOrganizer organizer) : base(pid1, pid2, organizer) { }
protected AbstractLineFactWrappedCRTP (string pid1, string pid2, string backendURI, FactOrganizer organizer) : base(pid1, pid2, backendURI, organizer) { }
Marco Zimmer
committed
protected override bool EquivalentWrapped(AbstractLineFact f1, AbstractLineFact f2)
{
return EquivalentWrapped((T)f1, (T)f2);
}
protected abstract bool EquivalentWrapped(T f1, T f2);
Marco Zimmer
committed
public class PointFact : FactWrappedCRTP<PointFact>
public Vector3 Normal;
public PointFact() : base()
{
this.Point = Vector3.zero;
this.Normal = Vector3.zero;
}
public PointFact(PointFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
{
init(fact.Point, fact.Normal);
}
public PointFact(Vector3 P, Vector3 N, FactOrganizer organizer) : base(organizer)
{
init(P, N);
}
private void init(Vector3 P, Vector3 N)
this.Point = P;
this.Normal = N;
List<MMTTerm> arguments = new List<MMTTerm>
new OMF(P.x),
new OMF(P.y),
new OMF(P.z)
//OMS constructor generates full URI
MMTTerm tp = new OMS(MMTURIs.Point);
MMTTerm df = new OMA(new OMS(MMTURIs.Tuple), arguments);
MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
Marco Zimmer
committed
AddFactResponse.sendAdd(mmtDecl, out this._URI);
public PointFact(float a, float b, float c, string uri, FactOrganizer organizer) : base(organizer)
this.Point = new Vector3(a, b, c);
this.Normal = new Vector3(0, 1, 0);
public static PointFact parseFact(Scroll.ScrollFact fact) {
String uri = fact.@ref.uri;
OMA df = (OMA)((Scroll.ScrollSymbolFact)fact).df;
if (df != null)
{
float a = (float)((OMF)df.arguments[0]).f;
float b = (float)((OMF)df.arguments[1]).f;
float c = (float)((OMF)df.arguments[2]).f;
Marco Zimmer
committed
return new PointFact(a, b, c, uri, StageStatic.stage.factState);
}
else {
return null;
}
public override Boolean hasDependentFacts() {
return false;
}
public override string[] getDependentFactIds() {
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 = this.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
Marco Zimmer
committed
public override int GetHashCode()
Marco Zimmer
committed
return this.Point.GetHashCode() ^ this.Normal.GetHashCode();
Marco Zimmer
committed
protected override bool EquivalentWrapped(PointFact f1, PointFact f2)
return Math3d.IsApproximatelyEqual(f1.Point, f2.Point);
Marco Zimmer
committed
Marco Zimmer
committed
public class LineFact : AbstractLineFactWrappedCRTP<LineFact>
public float Distance;
public LineFact() : base()
{
Distance = 0;
}
public LineFact(LineFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, old_to_new, organizer)
{
init(old_to_new[fact.Pid1], old_to_new[fact.Pid2]);
}
public LineFact(string pid1, string pid2, string backendURI, FactOrganizer organizer) : base(pid1, pid2, backendURI, organizer)
{
SetDistance();
}
public LineFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, pid2, organizer)
{
init(pid1, pid2);
}
private void init(string pid1, string pid2)
SetDistance();
PointFact pf1 = _Facts[pid1] as PointFact;
PointFact pf2 = _Facts[pid2] as PointFact;
Marco Zimmer
committed
string p1URI = pf1.Id;
string p2URI = pf2.Id;
John Schihada
committed
MMTTerm valueTp = new OMS(MMTURIs.RealLit);
MMTTerm value = new OMF(v);
John Schihada
committed
MMTValueDeclaration mmtDecl = new MMTValueDeclaration(this.Label, lhs, valueTp, value);
Marco Zimmer
committed
AddFactResponse.sendAdd(mmtDecl, out this._URI);
public static LineFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
string pointAUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).uri;
string pointBUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[1]).uri;
Marco Zimmer
committed
if (StageStatic.stage.factState.ContainsKey(pointAUri)
&& StageStatic.stage.factState.ContainsKey(pointBUri))
return new LineFact(pointAUri, pointBUri, uri, StageStatic.stage.factState);
//If dependent facts do not exist return null
else {
return null;
}
}
protected override string generateLabel()
{
return "[" + _Facts[Pid1].Label + _Facts[Pid2].Label + "]";
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.GetComponent<FactWrapper>().fact = this;
return obj;
}
Marco Zimmer
committed
protected override bool EquivalentWrapped(LineFact f1, LineFact f2)
Marco Zimmer
committed
if ((f1.Pid1 == f2.Pid1 && f1.Pid2 == f2.Pid2))// ||
//(f1.Pid1 == f2.Pid2 && f1.Pid2 == f2.Pid1))
return true;
PointFact p1f1 = (PointFact)_Facts[f1.Pid1];
PointFact p2f1 = (PointFact)_Facts[f1.Pid2];
PointFact p1f2 = (PointFact)_Facts[f2.Pid1];
PointFact p2f2 = (PointFact)_Facts[f2.Pid2];
Marco Zimmer
committed
return (p1f1.Equivalent(p1f2) && p2f1.Equivalent(p2f2))
;//|| (p1f1.Equivalent(p2f2) && p2f1.Equivalent(p1f2));
private void SetDistance()
{
this.Distance = Vector3.Distance(((PointFact)_Facts[Pid1]).Point, ((PointFact)_Facts[Pid2]).Point);
}
Marco Zimmer
committed
public class RayFact : AbstractLineFactWrappedCRTP<RayFact>
public RayFact() : base() { }
public RayFact(RayFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, old_to_new, organizer)
{
init(old_to_new[fact.Pid1], old_to_new[fact.Pid2]);
}
public RayFact(string pid1, string pid2, string backendURI, FactOrganizer organizer) : base(pid1, pid2, backendURI, organizer)
{
_ = this.Label;
}
public RayFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, pid2, organizer)
{
init(pid1, pid2);
}
private void init(string pid1, string pid2)
PointFact pf1 = _Facts[pid1] as PointFact;
PointFact pf2 = _Facts[pid2] as PointFact;
Marco Zimmer
committed
Marco Zimmer
committed
string p1URI = pf1.Id;
string p2URI = pf2.Id;
List<MMTTerm> arguments = new List<MMTTerm>
{
new OMS(p1URI),
new OMS(p2URI)
};
//OMS constructor generates full URI
MMTTerm tp = new OMS(MMTURIs.LineType);
MMTTerm df = new OMA(new OMS(MMTURIs.LineOf), arguments);
MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
Marco Zimmer
committed
AddFactResponse.sendAdd(mmtDecl, out this._URI);
public static RayFact parseFact(Scroll.ScrollFact fact)
{
if ((OMA)((Scroll.ScrollSymbolFact)fact).df != null)
{
string pointAUri = ((OMS)((OMA)((Scroll.ScrollSymbolFact)fact).df).arguments[0]).uri;
string pointBUri = ((OMS)((OMA)((Scroll.ScrollSymbolFact)fact).df).arguments[1]).uri;
Marco Zimmer
committed
if (StageStatic.stage.factState.ContainsKey(pointAUri)
&& StageStatic.stage.factState.ContainsKey(pointBUri))
return new RayFact(pointAUri, pointBUri, uri, StageStatic.stage.factState);
//If dependent facts do not exist return null
}
return null;
protected override string generateLabel()
{
return "–" + _Facts[Pid1].Label + _Facts[Pid2].Label + "–";
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 = this.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
Marco Zimmer
committed
protected override bool EquivalentWrapped(RayFact f1, RayFact f2)
Marco Zimmer
committed
if (!Math3d.IsApproximatelyParallel(f1.Dir, f2.Dir))
PointFact p1f1 = (PointFact)_Facts[f1.Pid1];
PointFact p1f2 = (PointFact)_Facts[f2.Pid1];
PointFact p2f2 = (PointFact)_Facts[f2.Pid2];
Marco Zimmer
committed
return Math3d.IsPointApproximatelyOnLine(p1f1.Point, f1.Dir, p1f2.Point)
&& Math3d.IsPointApproximatelyOnLine(p1f1.Point, f1.Dir, p2f2.Point);
Marco Zimmer
committed
public class OnLineFact : FactWrappedCRTP<OnLineFact>
{
//Id's of the Point and the Line it's on
public OnLineFact() : base()
{
this.Pid = null;
this.Rid = null;
}
public OnLineFact(OnLineFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
{
init(old_to_new[fact.Pid], old_to_new[fact.Rid]);
}
public OnLineFact(string pid, string rid, FactOrganizer organizer) : base(organizer)
{
init(pid, rid);
}
private void init(string pid, string rid)
{
this.Pid = pid;
this.Rid = rid;
PointFact pf = _Facts[pid] as PointFact;
RayFact rf = _Facts[rid] as RayFact;
Marco Zimmer
committed
string pURI = pf.Id;
string rURI = rf.Id;
List<MMTTerm> innerArguments = new List<MMTTerm>
{
new OMS(rURI),
new OMS(pURI)
};
List<MMTTerm> outerArguments = new List<MMTTerm>
{
new OMA(new OMS(MMTURIs.OnLine), innerArguments)
};
//OMS constructor generates full URI
MMTTerm tp = new OMA(new OMS(MMTURIs.Ded), outerArguments);
MMTTerm df = null;
MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
Marco Zimmer
committed
AddFactResponse.sendAdd(mmtDecl, out this._URI);
}
public OnLineFact(string pid, string rid, string uri, FactOrganizer organizer) : base(organizer)
this.Pid = pid;
this.Rid = rid;
}
public static OnLineFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
string lineUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[0]).uri;
string pointUri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).uri;
Marco Zimmer
committed
if (StageStatic.stage.factState.ContainsKey(pointUri)
&& StageStatic.stage.factState.ContainsKey(lineUri))
return new OnLineFact(pointUri, lineUri, uri, StageStatic.stage.factState);
//If dependent facts do not exist return null
else
return null;
}
protected override string generateLabel()
{
return _Facts[Pid].Label + "∈" + _Facts[Rid].Label;
public override Boolean hasDependentFacts()
{
return true;
}
public override string[] getDependentFactIds()
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.Pid].Label;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Rid].Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
Marco Zimmer
committed
public override int GetHashCode()
return this.Pid.GetHashCode() ^ this.Rid.GetHashCode();
Marco Zimmer
committed
protected override bool EquivalentWrapped(OnLineFact f1, OnLineFact f2)
Marco Zimmer
committed
if (f1.Pid == f2.Pid && f1.Rid == f2.Rid)
return true;
PointFact pf1 = (PointFact)_Facts[f1.Pid];
RayFact rf1 = (RayFact)_Facts[f1.Rid];
PointFact pf2 = (PointFact)_Facts[f2.Pid];
RayFact rf2 = (RayFact)_Facts[f2.Rid];
Marco Zimmer
committed
return pf1.Equivalent(pf2) && rf1.Equivalent(rf2);
}
Marco Zimmer
committed
public class AngleFact : FactWrappedCRTP<AngleFact>
//Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is
public string Pid1, Pid2, Pid3;
public bool is_right_angle;
public AngleFact() : base()
{
this.Pid1 = null;
this.Pid2 = null;
this.Pid3 = null;
this.is_right_angle = false;
}
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]);
}
public AngleFact(string pid1, string pid2, string pid3, FactOrganizer organizer) : base(organizer)
{
init(pid1, pid2, pid3);
}
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);
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;
}
public 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
protected override string generateLabel()
{
return (is_right_angle ? "⊾" : "∠") + _Facts[Pid1].Label + _Facts[Pid2].Label + _Facts[Pid3].Label;
}
private float GetAngle()
{
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;
}
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
}
);
MMTTerm tp = new OMA(new OMS(MMTURIs.Ded), new List<MMTTerm> {argument});
MMTTerm df = null;
return new MMTSymbolDeclaration(this.Label, tp, df);
}
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);
}
public override Boolean hasDependentFacts()
{
return true;
}
public override string[] getDependentFactIds()
return new string[] { Pid1, Pid2, Pid3 };
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;
}
Marco Zimmer
committed
public override int GetHashCode()
return this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode() ^ this.Pid3.GetHashCode();
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));