Select Git revision
VolumeFacts.cs
MaZiFAU authored
new ShapeGenerator-System: + added Plane/PrismGenerator; + Fixed Torus Mesh Generation + streamlined Generator process; + enabled normal offset; + Refactoring altered ShapePrefabs: + added Prism/Cone Prefab an entree in FactSpawner; + switched to using new ShapGenerator-System; + added BoundingPositioning.cs for dynamic TextPosition; refactored Facts: + added QuadFact + mostly moved semantic coherent Facts in own file + Some spelling and semantic errors
VolumeFacts.cs 14.94 KiB
using System.Collections.Generic;
using Newtonsoft.Json;
using REST_JSON_API;
/// <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;
[JsonIgnore]
public CircleFact Circle { get => (CircleFact)FactRecorder.AllFacts[Cid1]; }
/// <summary> a <see cref="PointFact">PointFact</see> describing the apex point </summary>
public string Pid1;
[JsonIgnore]
public PointFact Point { get => (PointFact)FactRecorder.AllFacts[Pid1]; }
/// <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>
/// Standard Constructor:
/// Initiates members 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>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public ConeVolumeFact(string cid1, string pid1, float vol, FactRecorder organizer) : base(organizer)
{
this.Cid1 = cid1;
this.Pid1 = pid1;
this.vol = vol;
SendToMMT();
}
protected override void RecalculateTransform()
{
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, FactRecorder organizer) : base(organizer)
{
this.Cid1 = Cid1;
this.Pid1 = Pid1;
this.vol = volume;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static ConeVolumeFact parseFact(MMTFact fact)
{
if (((MMTValueFact)fact).lhs is not OMA lhs)
return null;
string CircleUri = ((OMS)((OMA)lhs.arguments[0]).arguments[0]).uri;
string PointUri = ((OMS)((OMA)lhs.arguments[0]).arguments[1]).uri;
float volume = 0.0f;
if (((MMTValueFact)fact).value is OMF oMFvolume)
volume = oMFvolume.@float;
if (!FactRecorder.AllFacts.ContainsKey(CircleUri)
|| !FactRecorder.AllFacts.ContainsKey(PointUri))
return null;
return new ConeVolumeFact(CircleUri, PointUri, volume, fact.@ref.uri, StageStatic.stage.factState);
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> "V(" + Circle.Label + "," + Point.Label + ")";
public override MMTFact MakeMMTDeclaration()
{
SOMDoc lhs =
new OMA(
new OMS(MMTConstants.VolumeCone),
new[] {
new OMA(new OMS(MMTConstants.ConeOfCircleApex),
new[] {
new OMS(Cid1),
new OMS(Pid1),
}
),
}
);
SOMDoc valueTp = new OMS(MMTConstants.RealLit);
SOMDoc value = new OMF(vol);
return new MMTValueFact(this.Label, lhs, valueTp, value);
}
/// \copydoc Fact.hasDependentFacts
public override bool HasDependentFacts => true;
/// \copydoc Fact.getDependentFactIds
protected override string[] GetDependentFactIds()
=> new string[] { Cid1, Pid1 };
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(ConeVolumeFact f1, ConeVolumeFact f2)
=> DependentFactsEquivalent(f1, f2);
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactRecorder organizer)
=> new ConeVolumeFact(old_to_new[this.Cid1], old_to_new[this.Pid1], this.vol, organizer);
}
/// <summary>
/// The volume of a cone A defined by a base area <see cref="CircleFact">CircleFact</see>, a top area <see cref="CircleFact">CircleFact</see> and the volume as float
/// </summary>
public class TruncatedConeVolumeFact : FactWrappedCRTP<TruncatedConeVolumeFact>
{
/// <summary> a <see cref="CircleFact">CircleFact</see> describing the base area </summary>
public string CidBase;
[JsonIgnore]
public CircleFact CircleBase { get => (CircleFact)FactRecorder.AllFacts[CidBase]; }
/// <summary> a <see cref="CircleFact">CircleFact</see> describing the top area </summary>
public string CidTop;
[JsonIgnore]
public CircleFact CircleTop { get => (CircleFact)FactRecorder.AllFacts[CidTop]; }
/// <summary> the volume of Truncated the cone as a float </summary>
[JsonIgnore]
public float vol;
/// <summary> a proof that both circles have not the same size </summary>
public string unequalCirclesProof;
/// <summary> OMA proof that the two circles are parallel </summary>
public OMA proof;
/// <summary> \copydoc Fact.Fact </summary>
public TruncatedConeVolumeFact() : base()
{
this.CidBase = null;
this.CidTop = null;
this.vol = 0.0f;
this.unequalCirclesProof = null;
this.proof = null;
}
/// <summary>
/// Standard Constructor:
/// Initiates members and creates MMT %Fact Server-Side
/// </summary>
/// <param name="cid1">sets <see cref="CidBase"/></param>
/// <param name="cid2">sets <see cref="CidTop"/></param>
/// <param name="vol">sets <see cref="vol"/></param>
/// <param name="proof">sets <see cref="proof"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public TruncatedConeVolumeFact(string cid1, string cid2, float vol, string unequalproof, OMA proof, FactRecorder organizer) : base(organizer)
{
this.CidBase = cid1;
this.CidTop = cid2;
this.proof = proof;
this.unequalCirclesProof = unequalproof;
this.vol = vol;
SendToMMT();
}
protected override void RecalculateTransform()
{
Position = CircleTop.Position;
Rotation = CircleTop.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="CidBase"/></param>
/// <param name="Cid2">sets <see cref="CidTop"/></param>
/// <param name="volume">sets <see cref="vol"/></param>
/// <param name="proof">sets <see cref="proof"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public TruncatedConeVolumeFact(string Cid1, string Cid2, float volume, string unequalproof, OMA proof, string backendURI, FactRecorder organizer) : base(organizer)
{
this.CidBase = Cid1;
this.CidTop = Cid2;
this.vol = volume;
this.proof = proof;
this.unequalCirclesProof = unequalproof;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static TruncatedConeVolumeFact parseFact(MMTFact fact)
{
string Circle1Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[0]).uri;
string Circle2Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[1]).uri;
float volume = ((OMF)((MMTValueFact)fact).value).@float;
string UnEqualCirclesProof = ((OMS)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[2])).uri;
OMA proof = (OMA)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[3]);
if (!FactRecorder.AllFacts.ContainsKey(Circle1Uri)
|| !FactRecorder.AllFacts.ContainsKey(Circle2Uri))
return null;
return new TruncatedConeVolumeFact(Circle1Uri, Circle2Uri, volume, UnEqualCirclesProof, proof, fact.@ref.uri, StageStatic.stage.factState);
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> "V(" + CircleBase.Label + "," + CircleTop.Label + ")";
public override MMTFact MakeMMTDeclaration()
{
SOMDoc lhs =
new OMA(
new OMS(MMTConstants.TruncatedVolumeCone),
new SOMDoc[] {
new OMS(CidBase),
new OMS(CidTop),
new OMS(unequalCirclesProof),
proof,
}
);
SOMDoc valueTp = new OMS(MMTConstants.RealLit);
SOMDoc value = new OMF(vol);
return new MMTValueFact(this.Label, lhs, valueTp, value);
}
/// \copydoc Fact.hasDependentFacts
public override bool HasDependentFacts => true;
/// \copydoc Fact.getDependentFactIds
protected override string[] GetDependentFactIds()
=> new string[] { CidBase, CidTop };
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(TruncatedConeVolumeFact f1, TruncatedConeVolumeFact f2)
=> DependentFactsEquivalent(f1, f2);
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactRecorder organizer)
=> new TruncatedConeVolumeFact(old_to_new[this.CidBase], old_to_new[this.CidTop], this.vol, old_to_new[this.unequalCirclesProof], this.proof, organizer);
}
/// <summary>
/// The volume of a cylinder defined by a base area <see cref="CircleFact">CircleFact</see>, a top area <see cref="CircleFact">CircleFact</see> and the volume as float
/// </summary>
public class CylinderVolumeFact : FactWrappedCRTP<CylinderVolumeFact>
{
/// <summary> a <see cref="CircleFact">CircleFact</see> describing the base area </summary>
public string Cid1;
[JsonIgnore]
public CircleFact Circle1 { get => (CircleFact)FactRecorder.AllFacts[Cid1]; }
/// <summary> a <see cref="CircleFact">CircleFact</see> describing the top area </summary>
public string Cid2;
[JsonIgnore]
public CircleFact Circle2 { get => (CircleFact)FactRecorder.AllFacts[Cid2]; }
/// <summary> the volume of the cylinder as a float </summary>
public float vol;
/// <summary> a proof that both circles have the same size </summary>
public string equalCirclesProof;
/// <summary> OMA proof that the two circles are parallel </summary>
public OMA proof;
/// <summary> \copydoc Fact.Fact </summary>
public CylinderVolumeFact() : base()
{
this.Cid1 = null;
this.Cid2 = null;
this.vol = 0.0f;
this.proof = null;
this.equalCirclesProof = null;
}
/// <summary>
/// Standard Constructor:
/// Initiates members and creates MMT %Fact Server-Side
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="cid2">sets <see cref="Cid2"/></param>
/// <param name="vol">sets <see cref="vol"/></param>
/// <param name="proof">sets <see cref="proof"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public CylinderVolumeFact(string cid1, string cid2, float vol, string eqProof, OMA proof, FactRecorder organizer) : base(organizer)
{
this.Cid1 = cid1;
this.Cid2 = cid2;
this.proof = proof;
this.equalCirclesProof = eqProof;
this.vol = vol;
SendToMMT();
}
protected override void RecalculateTransform()
{
Position = Circle2.Position;
Rotation = Circle2.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="Cid2">sets <see cref="Cid2"/></param>
/// <param name="volume">sets <see cref="vol"/></param>
/// <param name="proof">sets <see cref="proof"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public CylinderVolumeFact(string Cid1, string Cid2, float volume, string eqProof, OMA proof, string backendURI, FactRecorder organizer) : base(organizer)
{
this.Cid1 = Cid1;
this.Cid2 = Cid2;
this.vol = volume;
this.proof = proof;
this.equalCirclesProof = eqProof;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static CylinderVolumeFact parseFact(MMTFact fact)
{
string Circle1Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[0]).uri;
string Circle2Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[1]).uri;
float volume = ((OMF)((MMTValueFact)fact).value).@float;
string EqualCirclesProof = ((OMS)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[2])).uri;
OMA proof = (OMA)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[3]);
if (!FactRecorder.AllFacts.ContainsKey(Circle1Uri)
|| !FactRecorder.AllFacts.ContainsKey(Circle2Uri))
return null;
return new CylinderVolumeFact(Circle1Uri, Circle2Uri, volume, EqualCirclesProof, proof, fact.@ref.uri, StageStatic.stage.factState);
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
=> "V(" + Circle1.Label + "," + Circle2.Label + ")";
public override MMTFact MakeMMTDeclaration()
{
SOMDoc lhs =
new OMA(
new OMS(MMTConstants.CylinderVolume),
new SOMDoc[] {
new OMS(Cid1),
new OMS(Cid2),
new OMS(equalCirclesProof),
proof,
}
);
SOMDoc valueTp = new OMS(MMTConstants.RealLit);
SOMDoc value = new OMF(vol);
return new MMTValueFact(this.Label, lhs, valueTp, value);
}
/// \copydoc Fact.hasDependentFacts
public override bool HasDependentFacts => true;
/// \copydoc Fact.getDependentFactIds
protected override string[] GetDependentFactIds()
=> new string[] { Cid1, Cid2, equalCirclesProof };
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(CylinderVolumeFact f1, CylinderVolumeFact f2)
=> DependentFactsEquivalent(f1, f2);
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactRecorder organizer)
=> new CylinderVolumeFact(old_to_new[this.Cid1], old_to_new[this.Cid2], this.vol, old_to_new[this.equalCirclesProof], this.proof, organizer);
}