Newer
Older
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
/// \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 = Point1.Label;
// obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Lid2].Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(CircleFact f1, CircleFact f2)
=> DependentFactsEquivalent(f1, f2)
&& Math3d.IsApproximatelyEqual(f1.normal, f2.normal)
&& f1.radius.IsApproximatelyEqual(f2.radius);
}
/// <summary>
/// A <see cref="PointFact"/> on a <see cref="CircleFact"/>
/// </summary>
public class OnCircleFact : FactWrappedCRTP<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)FactOrganizer.AllFacts[Pid]; }
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid]; }
MaZiFAU
committed
/// <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;
MaZiFAU
committed
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);
protected override void RecalulateTransform()
{
Position = Point.Position;
Rotation = Circle.Rotation;
}
/// <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()
/// \copydoc Fact.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 = Point.Label + "∈" + Circle.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(OnCircleFact c1, OnCircleFact c2)
}
/// <summary>
/// Angle comprised of a line and a circle
/// </summary>
public class AngleCircleLineFact : FactWrappedCRTP<AngleCircleLineFact>
{
/// @{ <summary>
/// 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)FactOrganizer.AllFacts[Rid2]; }
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
MaZiFAU
committed
/// <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;
this.angle = Math3d.AngleVectorPlane(Ray.Dir, Circle.normal).ToDegrees();
Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position);
RecalulateTransform();
MMTDeclaration mmtDecl = generateMMTDeclaration(angle, cid1, rid2);
AddFactResponse.sendAdd(mmtDecl, out this._URI);
}
protected override void RecalulateTransform()
{
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
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);
}
}
/// <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>
/// <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()
/// <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 = Circle.Label;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = Ray.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(AngleCircleLineFact f1, AngleCircleLineFact f2)
}
/// <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>
{
/// <summary> The circle corresponding to the radius </summary>
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
MaZiFAU
committed
/// <summary> The radius as a float </summary>
public float rad;
/// <summary> \copydoc Fact.Fact </summary>
public RadiusFact() : base()
{
this.Cid1 = null;
this.rad = 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 RadiusFact(RadiusFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public RadiusFact(string cid1, FactOrganizer organizer) : base(organizer)
/// <summary>
/// Initiates <see cref="Cid1"/> and <see cref="rad"/>
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
private void init(string cid1)
{
this.Cid1 = cid1;
MMTDeclaration mmtDecl = generateMMTDeclaration(cid1, this.rad);
AddFactResponse.sendAdd(mmtDecl, out this._URI);
protected override void RecalulateTransform()
{
Position = Circle.Position;
Rotation = Circle.Rotation;
}
/// <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="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public RadiusFact(string Cid1, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = Cid1;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static RadiusFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
string CircleUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).uri;
if (StageStatic.stage.factState.ContainsKey(CircleUri))
return new RadiusFact(CircleUri, 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 not-right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="rad"> see <see cref="rad"/></param>
/// <param name="c1URI"> see <see cref="Cid1"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
private MMTDeclaration generateMMTDeclaration(string c1URI, float rad)
MaZiFAU
committed
SOMDoc lhs =
MaZiFAU
committed
new OMS(MMT_OMS_URI.RadiusCircleMetric),
new List<SOMDoc> {
new OMS(c1URI),
}
);
MaZiFAU
committed
SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
SOMDoc value = new OMF(rad);
return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
}
/// \copydoc Fact.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 = "r: " + Circle.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(RadiusFact f1, RadiusFact f2)
}
/// <summary>
/// Area of a <see cref="CircleFact">CircleFact</see>
/// </summary>
public class AreaCircleFact : FactWrappedCRTP<AreaCircleFact>
{
/// <summary> the circle <see cref="CircleFact">CircleFact</see> </summary>
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
MaZiFAU
committed
/// <summary> the area which is contained by the circle </summary>
public float A;
/// <summary> \copydoc Fact.Fact </summary>
public AreaCircleFact() : base()
{
this.Cid1 = null;
this.A = 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 AreaCircleFact(AreaCircleFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public AreaCircleFact(string cid1, FactOrganizer organizer) : base(organizer)
/// <summary>
/// Initiates <see cref="Cid1"/> and creates MMT %Fact Server-Side
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
private void init(string cid1)
{
this.Cid1 = cid1;
this.A = Circle.radius * Circle.radius * ((float)System.Math.PI);
MMTDeclaration mmtDecl = generateMMTDeclaration(cid1, this.A);
AddFactResponse.sendAdd(mmtDecl, out this._URI);
}
protected override void RecalulateTransform()
{
Position = Circle.Position;
Rotation = Circle.Rotation;
}
/// <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="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public AreaCircleFact(string Cid1, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = Cid1;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static AreaCircleFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
string CircleUri = ((OMS)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).uri;
if (StageStatic.stage.factState.ContainsKey(CircleUri))
return new AreaCircleFact(CircleUri, uri, StageStatic.stage.factState);
else //If dependent facts do not exist return null
return null;
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
/// <summary>
/// Constructs a response, that is sent to the MMT-Server
/// </summary>
/// <param name="area"> area of the circle </param>
/// <param name="c1URI"> <see cref="Cid1"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
private MMTDeclaration generateMMTDeclaration(string c1URI, float area)
{
MaZiFAU
committed
SOMDoc lhs =
MaZiFAU
committed
new OMS(MMT_OMS_URI.AreaCircle),
new List<SOMDoc> {
new OMS(c1URI),
}
);
MaZiFAU
committed
SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
SOMDoc value = new OMF(area);
return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
}
/// \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 = Circle.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.GetHashCode
/// is this a problem?
public override int GetHashCode()
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(AreaCircleFact f1, AreaCircleFact f2)
}
/// <summary>
/// The volume of a cone A defined by a base area <see cref="CircleFact">CircleFact</see>, an apex <see cref="PointFact">PointFact</see> and the volume as float
/// </summary>
public class ConeVolumeFact : FactWrappedCRTP<ConeVolumeFact>
{
/// <summary> a <see cref="CircleFact">CircleFact</see> describing the base area </summary>
public string Cid1;
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
MaZiFAU
committed
/// <summary> a <see cref="PointFact">PointFact</see> describing the apex point </summary>
public string Pid1;
MaZiFAU
committed
[JsonIgnore]
public PointFact Point { get => (PointFact)FactOrganizer.AllFacts[Pid1]; }
MaZiFAU
committed
/// <summary> the volume of the cone as a float </summary>
public float vol;
/// <summary> \copydoc Fact.Fact </summary>
public ConeVolumeFact() : base()
{
this.Cid1 = null;
this.Pid1 = null;
this.vol = 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 ConeVolumeFact(ConeVolumeFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
=> init(old_to_new[fact.Cid1], old_to_new[fact.Pid1], fact.vol);
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="pid1">sets <see cref="Pid1"/></param>
/// <param name="vol">sets <see cref="vol"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public ConeVolumeFact(string cid1, string pid1, float vol, FactOrganizer organizer) : base(organizer)
=> init(cid1, pid1, vol);
/// Initiates <see cref="Cid1"/>, <see cref="Pid1"/>, <see cref="vol"/>, <see cref="Fact._URI"/> and creates MMT %Fact Server-Side
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="pid1">sets <see cref="Pid1"/></param>
/// <param name="vol">sets <see cref="vol"/></param>
private void init(string cid1, string pid1, float vol)
{
this.Cid1 = cid1;
this.Pid1 = pid1;
this.vol = vol;
MMTDeclaration mmtDecl = generateMMTDeclaration(cid1, pid1, vol);
AddFactResponse.sendAdd(mmtDecl, out this._URI);
}
protected override void RecalulateTransform()
{
Position = Point.Position;
Rotation = Circle.Rotation;
}
/// <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="Pid1">sets <see cref="Pid1"/></param>
/// <param name="volume">sets <see cref="vol"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public ConeVolumeFact(string Cid1, string Pid1, float volume, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = Cid1;
this.Pid1 = Pid1;
this.vol = volume;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(Scroll.ScrollFact)
public new static ConeVolumeFact parseFact(Scroll.ScrollFact fact)
{
string uri = fact.@ref.uri;
if (((Scroll.ScrollValueFact)fact).lhs == null)
return null;
string CircleUri = ((OMS)((OMA)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).arguments[0]).uri;
string PointUri = ((OMS)((OMA)((OMA)((Scroll.ScrollValueFact)fact).lhs).arguments[0]).arguments[1]).uri;
float volume = 0.0f;
if ((((Scroll.ScrollValueFact)fact).value) != null)
volume = ((OMF)((Scroll.ScrollValueFact)fact).value).f;
if (StageStatic.stage.factState.ContainsKey(CircleUri) && StageStatic.stage.factState.ContainsKey(PointUri))
return new ConeVolumeFact(CircleUri, PointUri, volume, 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 not-right-angled MMT %Fact <see cref="AddFactResponse"/>
/// </summary>
/// <param name="c1URI"> Uri for <see cref="Cid1"/></param>
/// <param name="p1URI"> Uri for <see cref="Pid1"/></param>
/// <param name="val"> <see cref="vol"/></param>
/// <returns>struct for <see cref="AddFactResponse"/></returns>
private MMTDeclaration generateMMTDeclaration(string c1URI, string p1URI, float val)
{
MaZiFAU
committed
SOMDoc lhs =
MaZiFAU
committed
new OMS(MMT_OMS_URI.VolumeCone),
MaZiFAU
committed
new List<SOMDoc> {
new OMA(new OMS(MMT_OMS_URI.ConeOfCircleApex),
new List<SOMDoc> {
new OMS(c1URI),
new OMS(p1URI),
}
),
}
);
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()
/// \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 = Circle.Label + Point.Label;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(ConeVolumeFact f1, ConeVolumeFact f2)
}
/// <summary>
/// The fact that the plane of a <see cref="CircleFact">CircleFact</see> and the line <see cref="RayFact>RayFact</see> are orthogonal
/// </summary>
public class OrthogonalCircleLineFact : FactWrappedCRTP<OrthogonalCircleLineFact>
{
/// <summary> a <see cref="CircleFact">CircleFact</see> describing the base area </summary>
public string Cid1;
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
MaZiFAU
committed
/// <summary> a <see cref="RayFact">Rayfact</see> describing the line </summary>
public string Lid1;
MaZiFAU
committed
[JsonIgnore]
public AbstractLineFact Ray { get => (AbstractLineFact)FactOrganizer.AllFacts[Lid1]; }
//TODO? deg or rad?
[JsonIgnore]
public float angle = 90f;
[JsonIgnore]
public Vector3 intersection;
/// <summary> \copydoc Fact.Fact </summary>
public OrthogonalCircleLineFact() : base()
{
this.Cid1 = null;
this.Lid1 = 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 OrthogonalCircleLineFact(OrthogonalCircleLineFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
=> init(old_to_new[fact.Cid1], old_to_new[fact.Lid1]);
/// <summary>
/// Standard Constructor
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="lid1">sets <see cref="Lid1"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public OrthogonalCircleLineFact(string cid1, string lid1, 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="cid1">sets <see cref="Cid1"/></param>
/// <param name="lid1">sets <see cref="Lid1"/></param>
private void init(string cid1, string lid1)
{
this.Cid1 = cid1;
this.Lid1 = lid1;
Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position);
RecalulateTransform();
MMTDeclaration mmtDecl = generateMMTDeclaration(cid1, lid1);
AddFactResponse.sendAdd(mmtDecl, out this._URI);
}
protected override void RecalulateTransform()
{
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 forward = (from + to).normalized;
Rotation = Quaternion.LookRotation(forward, up);
}
}
/// <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="Lid1">sets <see cref="Lid1"/></param>