Newer
Older
MaZiFAU
committed
[JsonIgnore]
public PointFact Point2 { get => (PointFact)_Facts[Pid2]; }
[JsonIgnore]
public PointFact Point3 { get => (PointFact)_Facts[Pid2]; }
/// <summary> \copydoc Fact.Fact </summary>
public RightAngleFact() : base()
{
this.Pid1 = null;
this.Pid2 = null;
this.Pid3 = null;
}
/// <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 RightAngleFact(RightAngleFact 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 RightAngleFact(string pid1, string pid2, string pid3, FactOrganizer organizer) : base(organizer)
/// <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;
Position = Point2.Position;
{ //Rotation
Vector3 from = (Point1.Position - Position).normalized;
Vector3 to = (Point3.Position - Position).normalized;
Vector3 up = Vector3.Cross(to, from);
Vector3 forwoard = (from + to).normalized;
if (up.sqrMagnitude < Math3d.vectorPrecission)
{ //Angle is 180° (or 0°)
Vector3 arbitary = up.normalized == Vector3.forward ? Vector3.right : Vector3.forward;
up = Vector3.Cross(arbitary, to);
forwoard = Vector3.Cross(up, to);
}
Rotation = Quaternion.LookRotation(forwoard, up);
}
AddFactResponse.sendAdd(generateMMTDeclaration(pid1, pid2, pid3), out this._URI);
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
}
/// <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 RightAngleFact(string Pid1, string Pid2, string Pid3, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Pid1 = Pid1;
this.Pid2 = Pid2;
this.Pid3 = Pid3;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static RightAngleFact parseFact(Scroll.ScrollFact fact)
{
OMA tp = (OMA)((Scroll.ScrollSymbolFact)fact).tp;
if (tp == null)
return null;
string Point1Uri = "";
string Point2Uri = "";
string Point3Uri = "";
string uri = fact.@ref.uri;
OMA proof_OMA = (OMA)((Scroll.ScrollSymbolFact)fact).tp; // proof DED
OMA rightAngleOMA = (OMA)proof_OMA.arguments[0]; // rightAngle OMA
if (rightAngleOMA.arguments[0] is OMS)
{
Point1Uri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[0]).uri;
Point2Uri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[1]).uri;
Point3Uri = ((OMS)((OMA)((OMA)((Scroll.ScrollSymbolFact)fact).tp).arguments[0]).arguments[2]).uri;
}
if (StageStatic.stage.factState.ContainsKey(Point1Uri)
&& StageStatic.stage.factState.ContainsKey(Point2Uri)
&& StageStatic.stage.factState.ContainsKey(Point3Uri))
return new RightAngleFact(Point1Uri, Point2Uri, Point3Uri, uri, StageStatic.stage.factState);
else //If dependent facts do not exist return null
return null;
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> _Facts[Pid1].Label + _Facts[Pid2].Label + _Facts[Pid3].Label + "⊥";
/// <summary>
/// Constructs struct for not-right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="p1URI"> Uri for <see cref="Pid1"/></param>
/// <param name="p2URI"> Uri for <see cref="Pid2"/></param>
/// <param name="p3URI"> Uri for <see cref="Pid3"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
private MMTDeclaration generateMMTDeclaration(string p1URI, string p2URI, string p3URI)
{
MaZiFAU
committed
SOMDoc tp =
MaZiFAU
committed
new OMS(MMT_OMS_URI.Ded),
new List<SOMDoc> {
MaZiFAU
committed
new OMS(MMT_OMS_URI.RightAngle),
new List<SOMDoc> {
new OMS(p1URI),
new OMS(p2URI),
new OMS(p3URI),
}),});
MaZiFAU
committed
SOMDoc df = null;
return new MMTSymbolDeclaration(this.Label, tp, df);
}
/// \copydoc Fact.hasDependentFacts
public override Boolean hasDependentFacts()
/// \copydoc Fact.getDependentFactIds
public override string[] getDependentFactIds()
=> 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
/// uhhh is this a problem?
public override int GetHashCode()
=> this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode() ^ this.Pid3.GetHashCode();
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(RightAngleFact f1, RightAngleFact f2)
{
if (f1.Pid1 == f2.Pid1 && f1.Pid2 == f2.Pid2 && f1.Pid3 == f2.Pid3)
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];
return (p1f1.Equivalent(p1f2) && p2f1.Equivalent(p2f2) && p3f1.Equivalent(p3f2));
}
}
/// <summary>
/// Two parallel Lines comprised of two <see cref="LineFact">LineFacts</see>
/// </summary>
public class ParallelLineFact : FactWrappedCRTP<ParallelLineFact>
{
MaZiFAU
committed
protected new string s_type = "ParallelLineFact";
MaZiFAU
committed
/// One <see cref="Fact.Id">Id</see> of two <see cref="LineFact"/> that are parallel [<see cref="Lid1"/>, <see cref="Lid2"/>].
/// </summary>
public string Lid1, Lid2;
/// @}
MaZiFAU
committed
[JsonIgnore]
public AbstractLineFact Ray1 { get => (AbstractLineFact)_Facts[Lid1]; }
[JsonIgnore]
public AbstractLineFact Ray2 { get => (AbstractLineFact)_Facts[Lid2]; }
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
/// <summary> \copydoc Fact.Fact </summary>
public ParallelLineFact() : base()
{
this.Lid1 = null;
this.Lid2 = null;
}
/// <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 ParallelLineFact(ParallelLineFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
{
init(old_to_new[fact.Lid1], old_to_new[fact.Lid2]);
}
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="lid1">sets <see cref="Lid1"/></param>
/// <param name="lid2">sets <see cref="Lid2"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public ParallelLineFact(string lid1, string lid2, FactOrganizer organizer) : base(organizer)
{
init(lid1, lid2);
}
/// <summary>
/// Initiates <see cref="Lid1"/>, <see cref="Lid2"/>, <see cref="Fact._URI"/> and creates MMT %Fact Server-Side
/// </summary>
/// <param name="lid1">sets <see cref="Lid1"/></param>
/// <param name="lid2">sets <see cref="Lid2"/></param>
private void init(string lid1, string lid2)
{
this.Lid1 = lid1;
this.Lid2 = lid2;
RayFact lf1 = _Facts[lid1] as RayFact;
RayFact lf2 = _Facts[lid2] as RayFact;
MMTDeclaration mmtDecl;
string l1URI = lf1.Id;
string l2URI = lf2.Id;
mmtDecl = generateParallelLineDeclaration(l1URI, l2URI);
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
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="Lid1">sets <see cref="Lid1"/></param>
/// <param name="Lid2">sets <see cref="Lid2"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public ParallelLineFact(string Lid1, string Lid2, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Lid1 = Lid1;
this.Lid2 = Lid2;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static ParallelLineFact parseFact(Scroll.ScrollFact fact)
{
OMA tp = (OMA)((Scroll.ScrollSymbolFact)fact).tp;
if (tp == null)
return null;
string uri = fact.@ref.uri;
string lineAUri;
string lineBUri;
OMA proof_OMA = (OMA)((Scroll.ScrollSymbolFact)fact).tp; // proof DED
OMA parallel_lines_OMA = (OMA)proof_OMA.arguments[0]; // parallel
if (parallel_lines_OMA.arguments[0] is OMS)
{ // Normaler Fall
lineAUri = ((OMS) parallel_lines_OMA.arguments[0]).uri;
lineBUri = ((OMS) parallel_lines_OMA.arguments[1]).uri;
else // TODO: Second case might be redundant by now
{
OMA Projl_line_A_OMA = (OMA)parallel_lines_OMA.arguments[0]; // ProjectL
lineAUri = ((OMS)Projl_line_A_OMA.arguments[0]).uri;
OMA Projl_line_B_OMA = (OMA)parallel_lines_OMA.arguments[1]; // ProjectL
lineBUri = ((OMS)Projl_line_B_OMA.arguments[0]).uri;
}
if (StageStatic.stage.factState.ContainsKey(lineAUri)
&& StageStatic.stage.factState.ContainsKey(lineBUri))
return new ParallelLineFact(lineAUri, lineBUri, uri, StageStatic.stage.factState);
else //If dependent facts do not exist return null
return null;
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> _Facts[Lid1].Label + "||" + _Facts[Lid2].Label;
/// <summary>
/// Constructs struct for right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="l1URI"><see cref="Lid1"/></param>
/// <param name="l2URI"><see cref="Lid2"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
private MMTDeclaration generateParallelLineDeclaration(string l1URI, string l2URI)
{
MaZiFAU
committed
SOMDoc tp = new OMA(
new OMS(MMT_OMS_URI.Ded),
new List<SOMDoc> {
MaZiFAU
committed
new OMS(MMT_OMS_URI.ParallelLine),
new List<SOMDoc> {
new OMS(l1URI),
new OMS(l2URI),
}
),
}
);
MaZiFAU
committed
SOMDoc df = null;
MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
AddFactResponse.sendAdd(mmtDecl, out this._URI);
return mmtDecl;
}
/// \copydoc Fact.hasDependentFacts
public override Boolean hasDependentFacts()
=> true;
/// \copydoc Fact.getDependentFactIds
public override string[] getDependentFactIds()
=> new string[] { Lid1, Lid2 };
/// \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.Lid1].Label;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Lid2].Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.GetHashCode
public override int GetHashCode()
=> this.Lid1.GetHashCode() ^ this.Lid2.GetHashCode();
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(ParallelLineFact f1, ParallelLineFact f2)
{
if ((f1.Lid1 == f2.Lid1 && f1.Lid2 == f2.Lid2))
return true;
RayFact r1f1 = (RayFact)_Facts[f1.Lid1];
RayFact r2f1 = (RayFact)_Facts[f1.Lid2];
RayFact r1f2 = (RayFact)_Facts[f2.Lid1];
RayFact r2f2 = (RayFact)_Facts[f2.Lid2];
return (r1f1.Equivalent(r1f2) && r2f1.Equivalent(r2f2));
}
}
/// <summary>
/// A Circle that is made out of a middle point, a plane and a radius
/// </summary>
public class CircleFact : FactWrappedCRTP<CircleFact>
{
MaZiFAU
committed
protected new string s_type = "CircleFact";
/// <summary> defining the middle point of the circle </summary>
public string Pid1;
/// <summary> defining the base point of the circle plane </summary>
public string Pid2;
MaZiFAU
committed
[JsonIgnore]
public PointFact Point1 { get => (PointFact)_Facts[Pid1]; }
[JsonIgnore]
public PointFact Point2 { get => (PointFact)_Facts[Pid2]; }
/// <summary> radius of the circle </summary>
public float radius;
/// <summary> normal vector of the plane </summary>
public Vector3 normal;
/// <summary> \copydoc Fact.Fact </summary>
public CircleFact() : base()
{
this.normal = Vector3.zero;
this.Pid1 = null;
this.Pid2 = null;
this.radius = 0;
}
/// <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 CircleFact(CircleFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
=> init(old_to_new[fact.Pid1], old_to_new[fact.Pid2], fact.radius, fact.normal);
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="pid1">sets <see cref="Pid1"/></param>
/// <param name="pid2">sets <see cref="Pid2"/></param>
/// <param name="radius">sets <see cref="radius"/></param>
/// <param name="normal">sets <see cref="normal"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public CircleFact(string pid1, string pid2, float radius, Vector3 normal, FactOrganizer organizer) : base(organizer)
=> init(pid1, pid2, radius, normal);
/// <summary>
/// Initiates <see cref="Pid1"/>, <see cref="Pid2"/>, <see cref="radius"/>,<see cref="dir1"/>,<see cref="dir2"/>, <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="radius">sets <see cref="radius"/></param>
/// <param name="normal">sets <see cref="normal"/></param>
private void init(string pid1, string pid2, float radius, Vector3 normal)
{
this.Pid1 = pid1;
this.Pid2 = pid2;
this.radius = radius;
this.normal = normal;
Position = Point1.Position;
Rotation = Quaternion.LookRotation(normal);
LocalScale = new Vector3(radius, 1, radius);
MMTDeclaration mmtDecl = generateCircleFactDeclaration(pid1, pid2, radius, normal);
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="radius">sets <see cref="radius"/></param>
/// <param name="normal">sets <see cref="normal"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public CircleFact(string Pid1, string Pid2, float radius, Vector3 normal, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Pid1 = Pid1;
this.Pid2 = Pid2;
this.radius = radius;
this.normal = normal;
this._URI = backendURI;
_ = this.Label;
}
/// <summary>
/// parses the Circlefact response of the MMT-Server
/// </summary>
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static CircleFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
OMA df = (OMA)((Scroll.ScrollSymbolFact)fact).df;
if (df == null)
return null;
Scroll.ScrollSymbolFact scoll_symbol_fact = (Scroll.ScrollSymbolFact)fact;
float radius = ((OMF)((OMA)scoll_symbol_fact.df).arguments[2]).f;
OMA planeOMA = (OMA)((OMA)scoll_symbol_fact.df).arguments[0];
string planeApplicant = ((OMS)planeOMA.applicant).uri;
string A_uri;
Vector3 normal;
MaZiFAU
committed
if (planeApplicant.Equals(MMT_OMS_URI.pointNormalPlane))
//OMA pointAOMA = (OMA)planeOMA.arguments[0];
A_uri = ParsingDictionary.parseTermsToId[planeOMA.arguments[0].ToString()];
OMA n = (OMA)planeOMA.arguments[1];
normal = new Vector3(((OMF)n.arguments[0]).f, ((OMF)n.arguments[1]).f, ((OMF)n.arguments[2]).f);
}
// In case of parametrized plane
MaZiFAU
committed
else if (planeApplicant.Equals(MMT_OMS_URI.ParametrizedPlane))
A_uri = ParsingDictionary.parseTermsToId[planeOMA.arguments[0].ToString()];
OMA vOMA = (OMA)planeOMA.arguments[1];
OMA wOMA = (OMA)planeOMA.arguments[2];
Vector3 v = new Vector3(((OMF)vOMA.arguments[0]).f, ((OMF)vOMA.arguments[1]).f, ((OMF)vOMA.arguments[2]).f);
Vector3 w = new Vector3(((OMF)wOMA.arguments[0]).f, ((OMF)wOMA.arguments[1]).f, ((OMF)wOMA.arguments[2]).f);
normal = Vector3.Cross(v, w).normalized;
}
// incase of smth else. Shouldn't hapepen unless there is an error
else throw new ArgumentException("Invalid planeApplicant: " + planeApplicant);
// get the mid point uri
string parse_id_M = ((OMA)scoll_symbol_fact.df).arguments[1].ToString();
string M_uri = ParsingDictionary.parseTermsToId[parse_id_M];
if (StageStatic.stage.factState.ContainsKey(M_uri)
&& StageStatic.stage.factState.ContainsKey(A_uri))
return new CircleFact(M_uri, A_uri, radius, normal, uri, StageStatic.stage.factState);
else //If dependent facts do not exist return null
return null;
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
/// <summary>
/// Constructs struct for right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="p1URI"> <see cref="Pid1"/></param>
/// <param name="p2URI"> <see cref="Pid2"/></param>
/// <param name="radius"> <see cref="radius"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
private MMTDeclaration generateCircleFactDeclaration(string p1URI, string p2URI, float radius, Vector3 normal)
MaZiFAU
committed
List<SOMDoc> outerArguments = new List<SOMDoc>
//CirclePlane,
new OMA(
//PointNormalPlane,
MaZiFAU
committed
new OMS(MMT_OMS_URI.pointNormalPlane),
MaZiFAU
committed
new List<SOMDoc> {
//base point of the circle plane?,
new OMS(p2URI),
//NormalVector,
new OMA(
//"Vector"
MaZiFAU
committed
new OMS(MMT_OMS_URI.Tuple),
MaZiFAU
committed
new List<SOMDoc> {
new OMF(normal.x),
new OMF(normal.y),
new OMF(normal.z)
}
),
}
),
//middlePoint,
new OMS(p1URI),
//Radius,
new OMF(radius),
};
// Do i need this here? doubt
MaZiFAU
committed
SOMDoc tp = new OMS(MMT_OMS_URI.CircleType3d);
SOMDoc df = new OMA(new OMS(MMT_OMS_URI.MkCircle3d), outerArguments);
MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(Label, tp, df);
AddFactResponse.sendAdd(mmtDecl, out _URI);
return mmtDecl;
}
/// \copydoc Fact.hasDependentFacts
public override Boolean hasDependentFacts()
/// \copydoc Fact.getDependentFactIds
public override string[] getDependentFactIds()
/// \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.Lid2].Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.GetHashCode
public override int GetHashCode()
=> Pid1.GetHashCode() ^ Pid2.GetHashCode();
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(CircleFact f1, CircleFact f2)
{
if (f1.Pid1 == f2.Pid1 && f1.normal == f2.normal && f1.radius == f2.radius)
return true;
PointFact p1f1 = (PointFact)_Facts[f1.Pid1];
PointFact p1f2 = (PointFact)_Facts[f2.Pid1];
return p1f1.Equivalent(p1f2)
&& Math3d.IsApproximatelyEqual(f1.normal, f2.normal)
&& Mathf.Approximately(f1.radius, f2.radius);
}
}
/// <summary>
/// A <see cref="PointFact"/> on a <see cref="CircleFact"/>
/// </summary>
public class OnCircleFact : FactWrappedCRTP<OnCircleFact>
{
MaZiFAU
committed
protected new string s_type = "OnCircleFact";
/// <summary> the point on the circle </summary>
public string Pid;
/// <summary> the circle, which the point is on </summary>
public string Cid;
MaZiFAU
committed
[JsonIgnore]
public PointFact Point { get => (PointFact)_Facts[Pid]; }
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)_Facts[Cid]; }
/// <summary> \copydoc Fact.Fact </summary>
public OnCircleFact() : base()
{
this.Pid = null;
this.Cid = null;
}
/// <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 OnCircleFact(OnCircleFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
=> init(old_to_new[fact.Pid], old_to_new[fact.Cid]);
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="pid">sets <see cref="Pid"/></param>
/// <param name="cid">sets <see cref="Cid"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public OnCircleFact(string pid, string cid, FactOrganizer organizer) : base(organizer)
/// <summary>
/// Initiates <see cref="Pid"/>, <see cref="Rid"/>, <see cref="Fact._URI"/> and creates MMT %Fact Server-Side
/// </summary>
/// <param name="pid">sets <see cref="Pid"/></param>
/// <param name="cid">sets <see cref="Cid"/></param>
private void init(string pid, string cid)
{
this.Pid = pid;
Position = Point.Position;
Rotation = Circle.Rotation;
MaZiFAU
committed
SOMDoc tp =
MaZiFAU
committed
new OMS(MMT_OMS_URI.Ded),
new List<SOMDoc> {
MaZiFAU
committed
new OMS(MMT_OMS_URI.OnCircle),
new List<SOMDoc> {
new OMS(cid),
new OMS(pid),
}),});
MaZiFAU
committed
SOMDoc df = null;
AddFactResponse.sendAdd(new MMTSymbolDeclaration(Label, tp, df), out _URI);
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
}
/// <summary>
/// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
/// </summary>
/// <param name="pid">sets <see cref="Pid"/></param>
/// <param name="cid">sets <see cref="Cid"/></param>
/// <param name="uri">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public OnCircleFact(string pid, string cid, string uri, FactOrganizer organizer) : base(organizer)
{
this.Pid = pid;
this.Cid = cid;
this._URI = uri;
_ = this.Label;
}
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static OnCircleFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
OMA tp = (OMA)((Scroll.ScrollSymbolFact)fact).tp;
if (tp == null)
return null;
string circleUri = ((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;
if (StageStatic.stage.factState.ContainsKey(pointUri)
&& StageStatic.stage.factState.ContainsKey(circleUri))
return new OnCircleFact(pointUri, circleUri, uri, StageStatic.stage.factState);
//If dependent facts do not exist return null
else
return null;
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> _Facts[Pid].Label + "∈" + _Facts[Cid].Label;
/// \copydoc Fact.hasDependentFacts
public override Boolean hasDependentFacts()
/// \copydoc Fact.getDependentFactIds
public override string[] getDependentFactIds()
/// \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.Pid].Label + "∈" + _Facts[this.Cid].Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.GetHashCode
public override int GetHashCode()
=> Pid.GetHashCode() ^ Cid.GetHashCode();
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(OnCircleFact c1, OnCircleFact c2)
{
if (c1.Pid == c2.Pid && c1.Cid == c2.Pid)
return true;
PointFact pc1 = (PointFact)_Facts[c1.Pid];
CircleFact cc1 = (CircleFact)_Facts[c1.Cid];
PointFact pc2 = (PointFact)_Facts[c2.Pid];
CircleFact cc2 = (CircleFact)_Facts[c2.Cid];
return pc1.Equivalent(pc2) && cc1.Equivalent(cc2);
}
}
/// <summary>
/// Angle comprised of a line and a circle
/// </summary>
public class AngleCircleLineFact : FactWrappedCRTP<AngleCircleLineFact>
{
MaZiFAU
committed
protected new string s_type = "AngleCircleLineFact";
/// One <see cref="Fact.Id">Id</see> of a <see cref="RayFact">RayFact</see> and a <see cref="CircleFact">CircleFact</see> defining Angle [<see cref="Cid1"/>, <see cref="Rid2"/>].
/// </summary>
public string Cid1, Rid2;
/// @}
MaZiFAU
committed
[JsonIgnore]
public AbstractLineFact Ray { get => (AbstractLineFact)_Facts[Rid2]; }
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)_Facts[Cid1]; }
/// <summary> \copydoc Fact.Fact </summary>
public AngleCircleLineFact() : base()
{
this.Cid1 = null;
this.Rid2 = null;
this.angle = 0.0f;
}
/// <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 AngleCircleLineFact(AngleCircleLineFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
=> init(old_to_new[fact.Cid1], old_to_new[fact.Rid2]);
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="rid2">sets <see cref="Rid2"/></param>
/// <param name="angle"> sets the angle </param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public AngleCircleLineFact(string cid1, string rid2, FactOrganizer organizer) : base(organizer)
=> init(cid1, rid2);
/// Initiates <see cref="Cid1"/>, <see cref="Rid2"/>, <see cref="angle"/> <see cref="Fact._URI"/> and creates MMT %Fact Server-Side
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="rid2">sets <see cref="Rid2"/></param>
/// <param name="angle"> sets the angle </param>
{
this.Cid1 = cid1;
this.Rid2 = rid2;
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
this.angle = Math3d.AngleVectorPlane(Ray.Dir, Circle.normal).ToDegrees();
Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position);
Position = intersection;
{ //Rotation
Vector3 from = (Circle.Position - Position).normalized;
Vector3 angle_to = Math3d.IsApproximatelyEqual(intersection, Ray.Point1.Position)
? Ray.Point2.Position
: Ray.Point1.Position;
Vector3 to = (angle_to - Position).normalized;
Vector3 up = Vector3.Cross(to, from);
Vector3 forwoard = (from + to).normalized;
if (up.sqrMagnitude < Math3d.vectorPrecission)
{ //Angle is 180° (or 0°)
Vector3 arbitary = up.normalized == Vector3.forward ? Vector3.right : Vector3.forward;
up = Vector3.Cross(arbitary, to);
forwoard = Vector3.Cross(up, to);
}
Rotation = Quaternion.LookRotation(forwoard, up);
}
MMTDeclaration mmtDecl = generateMMTDeclaration(angle, cid1, rid2);
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="Cid1">sets <see cref="Cid1"/></param>
/// <param name="´Rid2">sets <see cref="Rid2"/></param>
/// <param name="angle"> sets the angle </param>
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public AngleCircleLineFact(string Cid1, string Rid2, float angle, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = Cid1;
this.Rid2 = Rid2;
this.angle = angle;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static AngleCircleLineFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
string
CircleUri,
RayUri;
OMA df = (OMA)((Scroll.ScrollValueFact)fact).lhs;
if (df == null)
return null;
// init it with 0 degrees, so we don't accidentally generate orthogonalfacts
// and the parsing works correctly if smb ever adds a scroll for this
float angle = 0.0f;
if ((((Scroll.ScrollValueFact)fact).value) != null)
angle = ((OMF)(((Scroll.ScrollValueFact)fact).value)).f;
CircleUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).uri;
RayUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[1]).uri;
if (StageStatic.stage.factState.ContainsKey(CircleUri)
&& StageStatic.stage.factState.ContainsKey(RayUri))
return new AngleCircleLineFact(CircleUri, RayUri, angle, uri, StageStatic.stage.factState);
else return null; //If dependent facts do not exist return null
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> "∠" + _Facts[Cid1].Label + _Facts[Rid2].Label;
/// <summary>
/// Constructs struct for not-right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="val">Angle != 90f, _not checked_</param>
/// <param name="c1URI"><see cref="Cid1"/></param>
/// <param name="R2URI"><see cref="Rid2"/></param>
/// <param name="val"><see cref="angle"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
private MMTDeclaration generateMMTDeclaration(float val, string c1URI, string r2URI)
{
MaZiFAU
committed
SOMDoc lhs =
MaZiFAU
committed
new OMS(MMT_OMS_URI.AnglePlaneLine),
new List<SOMDoc> {
new OMS(c1URI),
new OMS(r2URI),
}
);
MaZiFAU
committed
SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
SOMDoc value = new OMF(val);
return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
}
/// \copydoc Fact.hasDependentFacts
public override Boolean hasDependentFacts()
=> true;
/// \copydoc Fact.getDependentFactIds
public override string[] getDependentFactIds()
/// \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.Cid1].Label;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Rid2].Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.GetHashCode
public override int GetHashCode()
=> this.Cid1.GetHashCode() ^ this.Rid2.GetHashCode();
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(AngleCircleLineFact f1, AngleCircleLineFact f2)
{
if (f1.Cid1 == f2.Cid1 && f1.Rid2 == f2.Rid2)
return true;
CircleFact c1f1 = (CircleFact)_Facts[f1.Cid1];
RayFact r2f1 = (RayFact)_Facts[f1.Rid2];
CircleFact c1f2 = (CircleFact)_Facts[f2.Cid1];
RayFact r2f2 = (RayFact)_Facts[f2.Rid2];
return (c1f1.Equivalent(c1f2) && r2f1.Equivalent(r2f2));
}
}
/// <summary>
/// A RadiusFact that corresponds to a <see cref="CircleFact">PointFacts</see> and has a float value (the actual radius).
/// </summary>
public class RadiusFact : FactWrappedCRTP<RadiusFact>
{