Skip to content
Snippets Groups Projects
Fact.cs 91.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => "○" + Point1.Label;
    
    
        /// <summary>
        /// Constructs struct for right-angled MMT %Fact <see cref="AddFactResponse"/>
        /// </summary>
    
        /// <param name="Pid1"> <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>
    
        protected override MMTDeclaration MakeMMTDeclaration()
    
            List<SOMDoc> outerArguments = new List<SOMDoc>
    
               //CirclePlane,
               new OMA(
                   //PointNormalPlane,
    
                        //base point of the circle plane?,
    
                        //NormalVector,
                        new OMA(
                            //"Vector"
    
                                new OMF(normal.x),
                                new OMF(normal.y),
                                new OMF(normal.z)
                            }
                        ),
                    }
                ),
               //middlePoint,
    
               //Radius,
               new OMF(radius),
    
            };
    
            // Do i need this here? doubt 
    
            SOMDoc tp = new OMS(MMT_OMS_URI.CircleType3d);
            SOMDoc df = new OMA(new OMS(MMT_OMS_URI.MkCircle3d), outerArguments);
    
            return new MMTSymbolDeclaration(Label, tp, df);
    
        }
    
        /// \copydoc Fact.hasDependentFacts
    
        public override bool HasDependentFacts => true;
    
    
        /// \copydoc Fact.getDependentFactIds
    
        protected override string[] GetGetDependentFactIds()
        {
            return new string[] { Pid1, Pid2 };
        }
    
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
    MaZiFAU's avatar
    MaZiFAU committed
            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)
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override bool EquivalentWrapped(CircleFact f1, CircleFact f2)
    
    MaZiFAU's avatar
    MaZiFAU committed
            => DependentFactsEquivalent(f1, f2)
            && Math3d.IsApproximatelyEqual(f1.normal, f2.normal)
            && f1.radius.IsApproximatelyEqual(f2.radius);
    
    MaZiFAU's avatar
    MaZiFAU committed
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
            => new CircleFact(old_to_new[this.Pid1], old_to_new[this.Pid2], this.radius, this.normal, organizer);
    
    }
    
    /// <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's avatar
    MaZiFAU committed
        public PointFact Point { get => (PointFact)FactOrganizer.AllFacts[Pid]; }
    
    MaZiFAU's avatar
    MaZiFAU committed
        public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid]; }
    
        /// <summary> \copydoc Fact.Fact </summary>
        public OnCircleFact() : base()
        {
            this.Pid = null;
            this.Cid = null;
        }
    
        /// <summary>
    
        /// Standard Constructor:
        /// 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>
        /// <param name="organizer">sets <see cref="Fact._Facts"/></param>
        public OnCircleFact(string pid, string cid, FactOrganizer organizer) : base(organizer)
        {
            this.Pid = pid;
    
            AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI);
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override void RecalculateTransform()
    
    MaZiFAU's avatar
    MaZiFAU committed
        {
            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(ScrollFact)
        public new static OnCircleFact parseFact(MMTDeclaration fact)
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (((MMTSymbolDeclaration)fact).type is not OMA type)
    
    MaZiFAU's avatar
    MaZiFAU committed
            string circleUri = ((OMS)((OMA)type.arguments[0]).arguments[0]).uri;
            string pointUri = ((OMS)((OMA)type.arguments[0]).arguments[1]).uri;
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (!FactOrganizer.AllFacts.ContainsKey(pointUri)
             || !FactOrganizer.AllFacts.ContainsKey(circleUri))
    
    MaZiFAU's avatar
    MaZiFAU committed
    
            return new OnCircleFact(pointUri, circleUri, fact.@ref.uri, StageStatic.stage.factState);
    
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => Point.Label + "∈" + Circle.Label;
    
    
        /// \copydoc Fact.hasDependentFacts
    
        public override bool HasDependentFacts => true;
    
    
        /// \copydoc Fact.getDependentFactIds
    
        protected override string[] GetGetDependentFactIds()
        {
            return new string[] { Pid, Cid };
        }
    
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
    MaZiFAU's avatar
    MaZiFAU committed
            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)
    
    MaZiFAU's avatar
    MaZiFAU committed
            => DependentFactsEquivalent(c1, c2);
    
    MaZiFAU's avatar
    MaZiFAU committed
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
            => new OnCircleFact(old_to_new[this.Pid], old_to_new[this.Cid], organizer);
    
    
        protected override MMTDeclaration MakeMMTDeclaration()
        {
            SOMDoc tp =
                new OMA(
                    new OMS(MMT_OMS_URI.Ded),
                    new List<SOMDoc> {
                        new OMA(
                            new OMS(MMT_OMS_URI.OnCircle),
                            new List<SOMDoc> {
                                new OMS(Cid),
                                new OMS(Pid),
            }),});
    
            SOMDoc df = null;
    
            return new MMTSymbolDeclaration(Label, tp, df);
        }
    
    /// 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's avatar
    MaZiFAU committed
        public AbstractLineFact Ray { get => (AbstractLineFact)FactOrganizer.AllFacts[Rid2]; }
    
    MaZiFAU's avatar
    MaZiFAU committed
        public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
    
    MaZiFAU's avatar
    MaZiFAU committed
        //TODO? deg or rad?
        [JsonIgnore]
    
    ki7077's avatar
    ki7077 committed
        public float angle;
    
    MaZiFAU's avatar
    MaZiFAU committed
        [JsonIgnore]
        public Vector3 intersection;
    
    
        /// <summary> \copydoc Fact.Fact </summary>
        public AngleCircleLineFact() : base()
        {
            this.Cid1 = null;
            this.Rid2 = null;
            this.angle = 0.0f;
        }
    
        /// <summary>
    
        /// Standard Constructor:
        /// 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>
    
        /// <param name="organizer">sets <see cref="Fact._Facts"/></param>
    
    MaZiFAU's avatar
    MaZiFAU committed
        public AngleCircleLineFact(string cid1, string rid2, FactOrganizer organizer) : base(organizer)
    
        {
            this.Cid1 = cid1;
            this.Rid2 = rid2;
    
    MaZiFAU's avatar
    MaZiFAU committed
            this.angle = Math3d.AngleVectorPlane(Ray.Dir, Circle.normal).ToDegrees();
            Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position);
    
    
            AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI);
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override void RecalculateTransform()
    
    MaZiFAU's avatar
    MaZiFAU committed
        {
    
    MaZiFAU's avatar
    MaZiFAU committed
            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(ScrollFact)
        public new static AngleCircleLineFact parseFact(MMTDeclaration fact)
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (((MMTValueDeclaration)fact).lhs is not OMA lhs)
    
                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;
    
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (((MMTValueDeclaration)fact).value is OMF oMFangle)
                angle = oMFangle.@float;
    
    MaZiFAU's avatar
    MaZiFAU committed
            string CircleUri = ((OMS)lhs.arguments[0]).uri;
            string RayUri = ((OMS)lhs.arguments[1]).uri;
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (!FactOrganizer.AllFacts.ContainsKey(CircleUri)
             || !FactOrganizer.AllFacts.ContainsKey(RayUri))
                return null;
    
    MaZiFAU's avatar
    MaZiFAU committed
            return new AngleCircleLineFact(CircleUri, RayUri, angle, fact.@ref.uri, StageStatic.stage.factState);
    
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => "∠" + Circle.Label + Ray.Label;
    
        protected override MMTDeclaration MakeMMTDeclaration()
    
                    new OMS(MMT_OMS_URI.AnglePlaneLine),
                    new List<SOMDoc> {
    
                        new OMS(Cid1),
                        new OMS(Rid2),
    
            SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
    
            SOMDoc value = new OMF(angle);
    
    
            return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
        }
    
    
        /// \copydoc Fact.hasDependentFacts
    
        public override bool HasDependentFacts => true;
    
    
        /// \copydoc Fact.getDependentFactIds
    
        protected override string[] GetGetDependentFactIds()
        {
            return new string[] { Cid1, Rid2 };
        }
    
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
    MaZiFAU's avatar
    MaZiFAU committed
            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)
    
    MaZiFAU's avatar
    MaZiFAU committed
            => DependentFactsEquivalent(f1, f2);
    
    MaZiFAU's avatar
    MaZiFAU committed
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
            => new AngleCircleLineFact(old_to_new[this.Cid1], old_to_new[this.Rid2], organizer);
    
    }
    
    /// <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's avatar
    MaZiFAU committed
        public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
    
        /// <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>
    
        /// Standard Constructor:
        /// Initiates <see cref="Cid1"/> and <see cref="rad"/>
    
        /// </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)
        {
            this.Cid1 = cid1;
    
    MaZiFAU's avatar
    MaZiFAU committed
            this.rad = Circle.radius;
    
            AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI);
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override void RecalculateTransform()
    
    MaZiFAU's avatar
    MaZiFAU committed
        {
            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(ScrollFact)
        public new static RadiusFact parseFact(MMTDeclaration fact)
    
            string CircleUri = ((OMS)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).uri;
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (!FactOrganizer.AllFacts.ContainsKey(CircleUri))
    
    MaZiFAU's avatar
    MaZiFAU committed
    
            return new RadiusFact(CircleUri, fact.@ref.uri, StageStatic.stage.factState);
    
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => "r " + Circle.Label;
    
    
        /// <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>
    
    
        protected override MMTDeclaration MakeMMTDeclaration()
    
                    new OMS(MMT_OMS_URI.RadiusCircleMetric),
                    new List<SOMDoc> {
    
            SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
            SOMDoc value = new OMF(rad);
    
    
            return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
        }
    
        /// \copydoc Fact.hasDependentFacts
    
        public override bool HasDependentFacts => true;
    
    
        /// \copydoc Fact.getDependentFactIds
    
        protected override string[] GetGetDependentFactIds()
        {
            return new string[] { Cid1 };
        }
    
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
    MaZiFAU's avatar
    MaZiFAU committed
            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)
    
    MaZiFAU's avatar
    MaZiFAU committed
            => DependentFactsEquivalent(f1, f2);
    
    MaZiFAU's avatar
    MaZiFAU committed
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
            => new RadiusFact(old_to_new[this.Cid1], organizer);
    
    }
    
    /// <summary>
    /// Area of a <see cref="CircleFact">CircleFact</see> 
    /// </summary>
    public class AreaCircleFact : FactWrappedCRTP<AreaCircleFact>
    {
    
    MaZiFAU's avatar
    MaZiFAU committed
        /// <summary> the circle <see cref="CircleFact">CircleFact</see>  </summary>
    
    MaZiFAU's avatar
    MaZiFAU committed
        public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
    
        /// <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>
    
        /// Standard Constructor:
        /// Initiates <see cref="Cid1"/> and creates MMT %Fact Server-Side
    
        /// </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)
        {
            this.Cid1 = cid1;
    
    
    MaZiFAU's avatar
    MaZiFAU committed
            this.A = Circle.radius * Circle.radius * ((float)System.Math.PI);
    
            AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI);
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override void RecalculateTransform()
    
    MaZiFAU's avatar
    MaZiFAU committed
        {
            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(ScrollFact)
        public new static AreaCircleFact parseFact(MMTDeclaration fact)
    
            string CircleUri = ((OMS)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).uri;
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (!FactOrganizer.AllFacts.ContainsKey(CircleUri))
    
    MaZiFAU's avatar
    MaZiFAU committed
    
            return new AreaCircleFact(CircleUri, fact.@ref.uri, StageStatic.stage.factState);
    
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => "A(" + Circle.Label + ")";
    
        protected override MMTDeclaration MakeMMTDeclaration()
    
                    new OMS(MMT_OMS_URI.AreaCircle),
                    new List<SOMDoc> {
    
            SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
    
            SOMDoc value = new OMF(A);
    
    
            return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
        }
    
        /// \copydoc Fact.hasDependentFacts
    
        public override bool HasDependentFacts => true;
    
    
        /// \copydoc Fact.getDependentFactIds
    
        protected override string[] GetGetDependentFactIds()
        {
            return new string[] { Cid1 };
        }
    
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
    MaZiFAU's avatar
    MaZiFAU committed
            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()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => base.GetHashCode() ^ A.GetHashCode();
    
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(AreaCircleFact f1, AreaCircleFact f2)
    
    MaZiFAU's avatar
    MaZiFAU committed
            => DependentFactsEquivalent(f1, f2);
    
    MaZiFAU's avatar
    MaZiFAU committed
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
            => new AreaCircleFact(old_to_new[this.Cid1], organizer);
    
    }
    
    /// <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's avatar
    MaZiFAU committed
        public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
    
        ///  <summary> a <see cref="PointFact">PointFact</see> describing the apex point  </summary>
        public string Pid1;
    
    MaZiFAU's avatar
    MaZiFAU committed
        public PointFact Point { get => (PointFact)FactOrganizer.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, FactOrganizer organizer) : base(organizer)
    
        {
            this.Cid1 = cid1;
            this.Pid1 = pid1;
            this.vol = vol;
    
    
            AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI);
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override void RecalculateTransform()
    
    MaZiFAU's avatar
    MaZiFAU committed
        {
            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(ScrollFact)
        public new static ConeVolumeFact parseFact(MMTDeclaration fact)
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (((MMTValueDeclaration)fact).lhs is not OMA lhs)
    
    MaZiFAU's avatar
    MaZiFAU committed
            string CircleUri = ((OMS)((OMA)lhs.arguments[0]).arguments[0]).uri;
            string PointUri = ((OMS)((OMA)lhs.arguments[0]).arguments[1]).uri;
    
    MaZiFAU's avatar
    MaZiFAU committed
            float volume = 0.0f;
            if (((MMTValueDeclaration)fact).value is OMF oMFvolume)
                volume = oMFvolume.@float;
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (!FactOrganizer.AllFacts.ContainsKey(CircleUri)
             || !FactOrganizer.AllFacts.ContainsKey(PointUri))
    
    MaZiFAU's avatar
    MaZiFAU committed
    
            return new ConeVolumeFact(CircleUri, PointUri, volume, fact.@ref.uri, StageStatic.stage.factState);
    
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => "V(" + Circle.Label + "," + Point.Label + ")";
    
        protected override MMTDeclaration MakeMMTDeclaration()
    
                    new List<SOMDoc> {
                        new OMA(new OMS(MMT_OMS_URI.ConeOfCircleApex),
                            new List<SOMDoc> {
    
                                new OMS(Cid1),
                                new OMS(Pid1),
    
            SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
    
            SOMDoc value = new OMF(vol);
    
    
            return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
        }
    
        /// \copydoc Fact.hasDependentFacts
    
        public override bool HasDependentFacts => true;
    
    
        /// \copydoc Fact.getDependentFactIds
    
        protected override string[] GetGetDependentFactIds()
        {
            return new string[] { Cid1, Pid1 };
        }
    
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
    MaZiFAU's avatar
    MaZiFAU committed
            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)
    
    MaZiFAU's avatar
    MaZiFAU committed
            => DependentFactsEquivalent(f1, f2);
    
    MaZiFAU's avatar
    MaZiFAU committed
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
            => new ConeVolumeFact(old_to_new[this.Cid1], old_to_new[this.Pid1], this.vol, organizer);
    
    }
    
    /// <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's avatar
    MaZiFAU committed
        public CircleFact Circle { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
    
        ///  <summary> a <see cref="RayFact">Rayfact</see> describing the line </summary>
        public string Lid1;
    
    MaZiFAU's avatar
    MaZiFAU committed
        public AbstractLineFact Ray { get => (AbstractLineFact)FactOrganizer.AllFacts[Lid1]; }
    
    MaZiFAU's avatar
    MaZiFAU committed
        //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>
    
        /// Standard Constructor:
        /// Initiates members and creates MMT %Fact Server-Side
    
        /// </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)
        {
            this.Cid1 = cid1;
            this.Lid1 = lid1;
    
    MaZiFAU's avatar
    MaZiFAU committed
            Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position);
    
    
            AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI);
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override void RecalculateTransform()
    
    MaZiFAU's avatar
    MaZiFAU committed
        {
    
    MaZiFAU's avatar
    MaZiFAU committed
            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>
    
        /// <param name="backendURI">MMT URI</param>
        /// <param name="organizer">sets <see cref="Fact._Facts"/></param>
    
        public OrthogonalCircleLineFact(string Cid1, string Lid1, string backendURI, FactOrganizer organizer) : base(organizer)
    
        {
            this.Cid1 = Cid1;
            this.Lid1 = Lid1;
    
            this._URI = backendURI;
            _ = this.Label;
        }
    
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static OrthogonalCircleLineFact parseFact(MMTDeclaration fact)
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (((MMTSymbolDeclaration)fact).type is not OMA type)
    
    MaZiFAU's avatar
    MaZiFAU committed
            string CircleUri = ((OMS)((OMA)type.arguments[0]).arguments[0]).uri;
            string LineUri = ((OMS)((OMA)type.arguments[0]).arguments[1]).uri;
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (!FactOrganizer.AllFacts.ContainsKey(CircleUri)
             || !FactOrganizer.AllFacts.ContainsKey(LineUri))
    
    MaZiFAU's avatar
    MaZiFAU committed
    
            return new OrthogonalCircleLineFact(CircleUri, LineUri, fact.@ref.uri, StageStatic.stage.factState);
    
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => Circle.Label + "⊥" + Ray.Label;
    
        protected override MMTDeclaration MakeMMTDeclaration()
    
                new OMS(MMT_OMS_URI.Ded),
    
                        new OMS(MMT_OMS_URI.OrthoCircleLine),
    
                            new OMS(Cid1),
                            new OMS(Lid1),
    
    
            return new MMTSymbolDeclaration(this.Label, tp, df);
        }
    
        /// \copydoc Fact.hasDependentFacts
    
        public override bool HasDependentFacts => true;
    
    
        /// \copydoc Fact.getDependentFactIds
    
        protected override string[] GetGetDependentFactIds()
        {
            return new string[] { Cid1, Lid1 };
        }
    
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
    MaZiFAU's avatar
    MaZiFAU committed
            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.GetHashCode
        /// uhhh is this a problem?
        public override int GetHashCode()
    
            => this.Cid1.GetHashCode() ^ this.Lid1.GetHashCode();
    
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(OrthogonalCircleLineFact f1, OrthogonalCircleLineFact f2)
    
    MaZiFAU's avatar
    MaZiFAU committed
            => DependentFactsEquivalent(f1, f2);
    
    MaZiFAU's avatar
    MaZiFAU committed
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
            => new OrthogonalCircleLineFact(old_to_new[this.Cid1], old_to_new[this.Lid1], 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 Cid1;
    
    MaZiFAU's avatar
    MaZiFAU committed
        public CircleFact Circle1 { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
    
        ///  <summary> a <see cref="CircleFact">CircleFact</see> describing the top area  </summary>
    
    MaZiFAU's avatar
    MaZiFAU committed
        public CircleFact Circle2 { get => (CircleFact)FactOrganizer.AllFacts[Cid2]; }
    
        ///  <summary> the volume of Truncated the cone as a float </summary>
    
        /// <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.Cid1 = null;
            this.Cid2 = null;
            this.vol = 0.0f;
    
            this.unequalCirclesProof = null;
    
        /// 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 TruncatedConeVolumeFact(string cid1, string cid2, float vol, string unequalproof, OMA proof, FactOrganizer organizer) : base(organizer)
    
        {
            this.Cid1 = cid1;
            this.Cid2 = cid2;
            this.proof = proof;
    
            this.unequalCirclesProof = unequalproof;
    
            AddFactResponse.sendAdd(MakeMMTDeclaration(), out this._URI);
    
    MaZiFAU's avatar
    MaZiFAU committed
        protected override void RecalculateTransform()
    
    MaZiFAU's avatar
    MaZiFAU committed
        {
            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 TruncatedConeVolumeFact(string Cid1, string Cid2, float volume, string unequalproof, OMA proof, string backendURI, FactOrganizer organizer) : base(organizer)
    
        {
            this.Cid1 = Cid1;
            this.Cid2 = Cid2;
            this.vol = volume;
            this.proof = proof;
    
            this.unequalCirclesProof = unequalproof;
    
    
            this._URI = backendURI;
            _ = this.Label;
        }
    
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static TruncatedConeVolumeFact parseFact(MMTDeclaration fact)
    
            string Circle1Uri = ((OMS)((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[0]).uri;
            string Circle2Uri = ((OMS)((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[1]).uri;
    
    MaZiFAU's avatar
    MaZiFAU committed
            float volume = ((OMF)((MMTValueDeclaration)fact).value).@float;
    
            string UnEqualCirclesProof = ((OMS)(((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[2])).uri;
            OMA proof = (OMA)(((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[3]);
    
    MaZiFAU's avatar
    MaZiFAU committed
            if (!FactOrganizer.AllFacts.ContainsKey(Circle1Uri)
             || !FactOrganizer.AllFacts.ContainsKey(Circle2Uri))
    
    MaZiFAU's avatar
    MaZiFAU committed
    
            return new TruncatedConeVolumeFact(Circle1Uri, Circle2Uri, volume, UnEqualCirclesProof, proof, fact.@ref.uri, StageStatic.stage.factState);
    
        }
    
        /// \copydoc Fact.generateLabel
    
        protected override string generateLabel()
    
    MaZiFAU's avatar
    MaZiFAU committed
            => "V(" + Circle1.Label + "," + Circle2.Label + ")";
    
        protected override MMTDeclaration MakeMMTDeclaration()