Skip to content
Snippets Groups Projects
Select Git revision
  • 0db8aa8884d887629dd6d7361d630e18e8a2cde1
  • master default
  • JS-based-scroll-rendering
  • Paul_Marius_Level
  • Paul_Marius_2
  • Paul_Marius
  • Andi_Mark
  • be-UnityWebView
  • gitignoreFrameitServer
  • ZimmerBSc
  • Bugfix_StageLoading
  • stages
  • MAZIFAU_Experimental
  • tsc/coneworld
  • tsc/fact-interaction
  • marcel
  • MaZiFAU_TopSort
  • mergeHelper
  • zwischenSpeichern
  • tempAndrToMaster
  • SebBranch
  • 3.0
  • v2.1
  • v2.0
  • v1.0
25 results

CircleFact.cs

Blame
  • CircleFact.cs 33.37 KiB
    using Newtonsoft.Json;
    using REST_JSON_API;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    /// <summary>
    /// A Circle that is made out of a middle point, a plane and a radius
    /// </summary>
    public class CircleFact : FactWrappedCRTP<CircleFact>
    {
        /// <summary> defining the middle point of the circle  </summary>
        public string PidCenter;
        /// <summary>  defining the base point of the circle plane </summary>
        public string PidBase;
    
        [JsonIgnore]
        public PointFact PointCenter { get => (PointFact)FactRecorder.AllFacts[PidCenter]; }
        [JsonIgnore]
        public PointFact PointBase { get => (PointFact)FactRecorder.AllFacts[PidBase]; }
    
        /// <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.PidCenter = null;
            this.PidBase = null;
            this.radius = 0;
        }
    
        /// <summary>
        /// Standard Constructor:
        /// Initiates <see cref="PidCenter"/>, <see cref="PidBase"/>, <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="PidCenter"/></param>
        /// <param name="pid2">sets <see cref="PidBase"/></param>
        /// <param name="radius">sets <see cref="radius"/></param>
        /// <param name="normal">sets <see cref="normal"/></param>
        public CircleFact(string pid1, string pid2, float radius, Vector3 normal) : base()
        {
            this.PidCenter = pid1;
            this.PidBase = pid2;
    
            this.radius = radius;
            this.normal = normal;
        }
    
        protected override void RecalculateTransform()
        {
            Position = PointCenter.Position;
            { //Rotation
                Vector3 arbitary_not_normal = normal == Vector3.forward ? Vector3.right : Vector3.forward;
                Vector3 forwoard = Vector3.Cross(arbitary_not_normal, normal);
    
                Rotation = Quaternion.LookRotation(forwoard, normal);
            }
            LocalScale = new Vector3(radius, 1, radius);
        }
    
        /// <summary>
        /// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
        /// </summary>
        /// <param name="Pid1">sets <see cref="PidCenter"/></param>
        /// <param name="Pid2">sets <see cref="PidBase"/></param>
        /// <param name="radius">sets <see cref="radius"/></param>
        /// <param name="normal">sets <see cref="normal"/></param>
        /// <param name="backendURI">MMT URI</param>
        public CircleFact(string Pid1, string Pid2, float radius, Vector3 normal, SOMDoc _ServerDefinition) : base()
        {
            this.PidCenter = Pid1;
            this.PidBase = Pid2;
    
            this.radius = radius;
            this.normal = normal;
    
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// <summary>
        /// parses the Circlefact response of the MMT-Server
        /// </summary>
        /// \copydoc Fact.parseFact(ScrollFact) 
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            if (((MMTGeneralFact)fact).defines is not OMA df)
                yield break;
    
            OMA planeOMA = (OMA)df.arguments[0];
            string planeApplicant = ((OMS)planeOMA.applicant).uri;
    
            Vector3 normal;
            // Getting the plane
            // IN case of a normale plane
            if (planeApplicant.Equals(MMTConstants.pointNormalPlane))
            {
                //OMA pointAOMA = (OMA)planeOMA.arguments[0];
                normal = SOMDoc.MakeVector3((OMA)planeOMA.arguments[1]);
            }
            // In case of parametrized plane
            else if (planeApplicant.Equals(MMTConstants.ParametrizedPlane))
            {
                Vector3 v = SOMDoc.MakeVector3((OMA)planeOMA.arguments[1]);
                Vector3 w = SOMDoc.MakeVector3((OMA)planeOMA.arguments[2]);
    
                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 = df.arguments[1].ToString();
            string M_uri = ParsingDictionary.parseTermsToId[parse_id_M];
            string A_uri = ParsingDictionary.parseTermsToId[planeOMA.arguments[0].ToString()];
            float radius = ((OMLIT<float>)df.arguments[2]).value;
    
            if (!FactRecorder.AllFacts.ContainsKey(M_uri)
             || !FactRecorder.AllFacts.ContainsKey(A_uri))
                yield break; //If dependent facts do not exist return null
    
            ret.Add(new CircleFact(M_uri, A_uri, radius, normal, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => "○" + PointCenter.GetLabel(name_space);
    
        /// <summary>
        /// Constructs struct for right-angled MMT %Fact <see cref="AddFactResponse"/>
        /// </summary>
        /// <param name="Pid1"> <see cref="PidCenter"/></param>
        /// <param name="p2URI"> <see cref="PidBase"/></param>
        /// <param name="radius"> <see cref="radius"/></param>
        /// <returns>struct for <see cref="AddFactResponse"/></returns>
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc tp = new OMS(MMTConstants.CircleType3d);
    
            return new MMTGeneralFact(_LastLabel, tp, Defines());
        }
    
        public override SOMDoc Defines()
            => new OMA(
                new OMS(MMTConstants.MkCircle3d),
                new SOMDoc[] {
                   //CirclePlane,
                   new OMA(
                       //PointNormalPlane,
                       new OMS(MMTConstants.pointNormalPlane), 
                       //planeArgs,
                       new SOMDoc[] {
                            //base point of the circle plane?,
                            new OMS(PidBase),
                            //NormalVector,
                            new OMA(
                                //"Vector"
                                new OMS(MMTConstants.Tuple),
                                //normalArgs,
                                new[]  {
                                    new OMLIT<float>(normal.x),
                                    new OMLIT<float>(normal.y),
                                    new OMLIT<float>(normal.z)
                                }
                            ),
                        }
                    ),
                   //middlePoint,
                   new OMS(PidCenter),
                   //Radius,
                   new OMLIT<float>(radius),
                }
            );
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { PidCenter, PidBase };
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(CircleFact f1, CircleFact f2)
            => DependentFactsEquivalent(f1, f2)
            && Math3d.IsApproximatelyEqual(f1.normal, f2.normal)
            && Mathf.Approximately(f1.radius, f2.radius);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new CircleFact(old_to_new[this.PidCenter], old_to_new[this.PidBase], this.radius, this.normal);
    }
    
    /// <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>
        public string Cid1;
    
        [JsonIgnore]
        public CircleFact Circle { get => (CircleFact)FactRecorder.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>
        public RadiusFact(string cid1) : base()
        {
            this.Cid1 = cid1;
            this.rad = Circle.radius;
        }
    
        protected override void RecalculateTransform()
        {
            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>
        public RadiusFact(string Cid1, SOMDoc _ServerDefinition) : base()
        {
            this.Cid1 = Cid1;
    
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            string CircleUri = ((OMS)((OMA)((MMTValueFact)fact).lhs).arguments[0]).uri;
    
            if (!FactRecorder.AllFacts.ContainsKey(CircleUri))
                yield break;
    
            ret.Add(new RadiusFact(CircleUri, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => "r " + Circle.GetLabel(name_space);
    
        /// <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>
    
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc valueTp = new OMS(MMTConstants.RealLit);
            SOMDoc value = new OMLIT<float>(rad);
    
            return new MMTValueFact(_LastLabel, Defines(), valueTp, value);
        }
    
        public override SOMDoc Defines()
            => new OMA(
                new OMS(MMTConstants.RadiusCircleMetric),
                new[] {
                    new OMS(Cid1),
                }
            );
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { Cid1 };
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(RadiusFact f1, RadiusFact f2)
            => DependentFactsEquivalent(f1, f2);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new RadiusFact(old_to_new[this.Cid1]);
    }
    
    /// <summary>
    /// Area of a <see cref="CircleFact">CircleFact</see> 
    /// </summary>
    public class AreaCircleFact : FactWrappedCRTP<AreaCircleFact>
    {
        /// <summary> the circle <see cref="CircleFact">CircleFact</see>  </summary>
        public string Cid1;
    
        [JsonIgnore]
        public CircleFact Circle { get => (CircleFact)FactRecorder.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>
        public AreaCircleFact(string cid1) : base()
        {
            this.Cid1 = cid1;
            this.A = Circle.radius * Circle.radius * (float)Math.PI;
        }
    
        protected override void RecalculateTransform()
        {
            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>
        public AreaCircleFact(string Cid1, SOMDoc _ServerDefinition) : base()
        {
            this.Cid1 = Cid1;
    
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            string CircleUri = ((OMS)((OMA)((MMTValueFact)fact).lhs).arguments[0]).uri;
    
            if (!FactRecorder.AllFacts.ContainsKey(CircleUri))
                yield break;
    
            ret.Add(new AreaCircleFact(CircleUri, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => "A(" + Circle.GetLabel(name_space) + ")";
    
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc valueTp = new OMS(MMTConstants.RealLit);
            SOMDoc value = new OMLIT<float>(A);
    
            return new MMTValueFact(_LastLabel, Defines(), valueTp, value);
        }
    
        public override SOMDoc Defines()
            => new OMA(
                new OMS(MMTConstants.AreaCircle),
                new[] {
                    new OMS(Cid1),
                }
            );
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { Cid1 };
    
        /// \copydoc Fact.GetHashCode
        public override int GetHashCode()
            => base.GetHashCode() ^ A.GetHashCode();
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(AreaCircleFact f1, AreaCircleFact f2)
            => DependentFactsEquivalent(f1, f2);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new AreaCircleFact(old_to_new[this.Cid1]);
    }
    
    /// <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;
    
        [JsonIgnore]
        public PointFact Point { get => (PointFact)FactRecorder.AllFacts[Pid]; }
        [JsonIgnore]
        public CircleFact Circle { get => (CircleFact)FactRecorder.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>
        public OnCircleFact(string pid, string cid) : base()
        {
            this.Pid = pid;
            this.Cid = cid;
        }
    
        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="pid">sets <see cref="Pid"/></param>
        /// <param name="cid">sets <see cref="Cid"/></param>
        /// <param name="uri">MMT URI</param>
        public OnCircleFact(string pid, string cid, SOMDoc _ServerDefinition) : base()
        {
            this.Pid = pid;
            this.Cid = cid;
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            if (((MMTGeneralFact)fact).type is not OMA type)
                yield break;
    
            string circleUri = ((OMS)((OMA)type.arguments[0]).arguments[0]).uri;
            string pointUri = ((OMS)((OMA)type.arguments[0]).arguments[1]).uri;
    
            if (!FactRecorder.AllFacts.ContainsKey(pointUri)
             || !FactRecorder.AllFacts.ContainsKey(circleUri))
                yield break;
    
            ret.Add(new OnCircleFact(pointUri, circleUri, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => Point.GetLabel(name_space) + "∈" + Circle.GetLabel(name_space);
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { Pid, Cid };
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(OnCircleFact c1, OnCircleFact c2)
            => DependentFactsEquivalent(c1, c2);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new OnCircleFact(old_to_new[this.Pid], old_to_new[this.Cid]);
    
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc tp =
                new OMA(
                    new OMS(MMTConstants.Ded),
                    new[] {
                        new OMA(
                            new OMS(MMTConstants.OnCircle),
                            new[] {
                                new OMS(Cid),
                                new OMS(Pid),
            }),});
    
            return new MMTGeneralFact(_LastLabel, tp, Defines());
        }
    
        public override SOMDoc Defines()
            => null;
    }
    
    /// <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;
        /// @}
    
        [JsonIgnore]
        public AbstractLineFact Ray { get => (AbstractLineFact)FactRecorder.AllFacts[Rid2]; }
        [JsonIgnore]
        public CircleFact Circle { get => (CircleFact)FactRecorder.AllFacts[Cid1]; }
    
        //TODO? deg or rad?
        [JsonIgnore]
        public float angle;
    
        [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
        /// </summary>
        /// <param name="cid1">sets <see cref="Cid1"/></param>
        /// <param name="rid2">sets <see cref="Rid2"/></param>
        /// <param name="angle"> sets the angle </param>
        public AngleCircleLineFact(string cid1, string rid2) : base()
        {
            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);
        }
    
        protected override void RecalculateTransform()
        {
            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>
        public AngleCircleLineFact(string Cid1, string Rid2, float angle, SOMDoc _ServerDefinition) : base()
        {
            this.Cid1 = Cid1;
            this.Rid2 = Rid2;
            this.angle = angle;
    
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            if (((MMTValueFact)fact).lhs is not OMA lhs)
                yield break;
    
            // 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 (((MMTValueFact)fact).value is OMLIT<float> oMFangle)
                angle = oMFangle.value;
    
            string CircleUri = ((OMS)lhs.arguments[0]).uri;
            string RayUri = ((OMS)lhs.arguments[1]).uri;
    
            if (!FactRecorder.AllFacts.ContainsKey(CircleUri)
             || !FactRecorder.AllFacts.ContainsKey(RayUri))
                yield break;
    
            ret.Add(new AngleCircleLineFact(CircleUri, RayUri, angle, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => "∠" + Circle.GetLabel(name_space) + Ray.GetLabel(name_space);
    
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc valueTp = new OMS(MMTConstants.RealLit);
            SOMDoc value = new OMLIT<float>(angle);
    
            return new MMTValueFact(_LastLabel, Defines(), valueTp, value);
        }
    
        public override SOMDoc Defines()
            => new OMA(
                    new OMS(MMTConstants.AnglePlaneLine),
                    new[] {
                        new OMS(Cid1),
                        new OMS(Rid2),
                    }
                );
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { Cid1, Rid2 };
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(AngleCircleLineFact f1, AngleCircleLineFact f2)
            => DependentFactsEquivalent(f1, f2);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new AngleCircleLineFact(old_to_new[this.Cid1], old_to_new[this.Rid2]);
    }
    
    /// <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;
        [JsonIgnore]
        public CircleFact Circle { get => (CircleFact)FactRecorder.AllFacts[Cid1]; }
    
        ///  <summary> a <see cref="RayFact">Rayfact</see> describing the line </summary>
        public string Lid1;
        [JsonIgnore]
        public AbstractLineFact Ray { get => (AbstractLineFact)FactRecorder.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>
        /// 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>
        public OrthogonalCircleLineFact(string cid1, string lid1) : base()
        {
            this.Cid1 = cid1;
            this.Lid1 = lid1;
            Math3d.LinePlaneIntersection(out intersection, Ray.Point1.Position, Ray.Dir, Circle.normal, Circle.Position);
        }
    
        protected override void RecalculateTransform()
        {
            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>
        public OrthogonalCircleLineFact(string Cid1, string Lid1, SOMDoc _ServerDefinition) : base()
        {
            this.Cid1 = Cid1;
            this.Lid1 = Lid1;
    
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            if (((MMTGeneralFact)fact).type is not OMA type)
                yield break;
    
            string CircleUri = ((OMS)((OMA)type.arguments[0]).arguments[0]).uri;
            string LineUri = ((OMS)((OMA)type.arguments[0]).arguments[1]).uri;
    
            if (!FactRecorder.AllFacts.ContainsKey(CircleUri)
             || !FactRecorder.AllFacts.ContainsKey(LineUri))
                yield break;
    
            ret.Add(new OrthogonalCircleLineFact(CircleUri, LineUri, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => Circle.GetLabel(name_space) + "⊥" + Ray.GetLabel(name_space);
    
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc tp = new OMA(
                new OMS(MMTConstants.Ded),
                new[]{
                    new OMA(
                        new OMS(MMTConstants.OrthoCircleLine),
                        new[] {
                            new OMS(Cid1),
                            new OMS(Lid1),
                        }
                    ),
                }
            );
    
            return new MMTGeneralFact(_LastLabel, tp, Defines());
        }
    
        public override SOMDoc Defines()
            => null;
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { Cid1, Lid1 };
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(OrthogonalCircleLineFact f1, OrthogonalCircleLineFact f2)
            => DependentFactsEquivalent(f1, f2);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new OrthogonalCircleLineFact(old_to_new[this.Cid1], old_to_new[this.Lid1]);
    }
    
    /// <summary>
    /// A fact that describes, that two circles have the same size and is comprised of two <see cref="CircleFact">CircleFacts</see> 
    /// </summary>
    public class EqualCirclesFact : FactWrappedCRTP<EqualCirclesFact>
    {
        /// @{ <summary>
        /// two circles that are meant to be equal in area
        /// </summary>
        public string Cid1, Cid2;
        /// @}
    
        [JsonIgnore]
        public CircleFact Circle1 { get => (CircleFact)FactRecorder.AllFacts[Cid1]; }
        [JsonIgnore]
        public CircleFact Circle2 { get => (CircleFact)FactRecorder.AllFacts[Cid2]; }
    
        /// <summary> \copydoc Fact.Fact </summary>
        public EqualCirclesFact() : base()
        {
            this.Cid1 = null;
            this.Cid2 = 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>
        public EqualCirclesFact(string cid1, string cid2) : base()
        {
            this.Cid1 = cid1;
            this.Cid2 = cid2;
        }
    
        protected override void RecalculateTransform()
        {
            Position = Circle1.Position;
            Rotation = Circle1.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="backendURI">MMT URI</param>
        public EqualCirclesFact(string Cid1, string Cid2, SOMDoc _ServerDefinition) : base()
        {
            this.Cid1 = Cid1;
            this.Cid2 = Cid2;
    
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            if (((MMTGeneralFact)fact).type is not OMA proof_OMA) // proof DED
                yield break;
    
            OMA parallel_circles_OMA = (OMA)proof_OMA.arguments[0]; // parallel
    
            string circleAUri = ((OMS)parallel_circles_OMA.arguments[0]).uri;
            string circleBUri = ((OMS)parallel_circles_OMA.arguments[1]).uri;
    
            if (!FactRecorder.AllFacts.ContainsKey(circleAUri)
             || !FactRecorder.AllFacts.ContainsKey(circleBUri))
                yield break;
    
            ret.Add(new EqualCirclesFact(circleAUri, circleBUri, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => Circle1.GetLabel(name_space) + " ≠ " + Circle2.GetLabel(name_space);
    
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc tp = new OMA(
                new OMS(MMTConstants.Ded),
                new[] {
                    new OMA(
                        new OMS(MMTConstants.EqualityCircles),
                        new[]  {
                            new OMS(Cid1),
                            new OMS(Cid2),
                        }
                    )
                }
            );
    
            return new MMTGeneralFact(_LastLabel, tp, Defines());
        }
    
        public override SOMDoc Defines()
            => null;
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { Cid1, Cid2 };
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(EqualCirclesFact f1, EqualCirclesFact f2)
            => DependentFactsEquivalent(f1, f2);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new EqualCirclesFact(old_to_new[this.Cid1], old_to_new[this.Cid2]);
    }
    
    /// <summary>
    /// A fact that describes, that two circles have not the same size and is comprised of two <see cref="CircleFact">CircleFacts</see> 
    /// </summary>
    public class UnEqualCirclesFact : FactWrappedCRTP<UnEqualCirclesFact>
    {
        /// @{ <summary>
        /// two circles that are meant to be unequal in area
        /// </summary>
        public string Cid1, Cid2;
        /// @}
    
        [JsonIgnore]
        public CircleFact Circle1 { get => (CircleFact)FactRecorder.AllFacts[Cid1]; }
        [JsonIgnore]
        public CircleFact Circle2 { get => (CircleFact)FactRecorder.AllFacts[Cid2]; }
    
        /// <summary> \copydoc Fact.Fact </summary>
        public UnEqualCirclesFact() : base()
        {
            this.Cid1 = null;
            this.Cid2 = 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>
        public UnEqualCirclesFact(string cid1, string cid2) : base()
        {
            this.Cid1 = cid1;
            this.Cid2 = cid2;
        }
    
        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="backendURI">MMT URI</param>
        public UnEqualCirclesFact(string Cid1, string Cid2, SOMDoc _ServerDefinition) : base()
        {
            this.Cid1 = Cid1;
            this.Cid2 = Cid2;
    
            this.ServerDefinition = _ServerDefinition;
        }
    
        /// \copydoc Fact.parseFact(ScrollFact)
        public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
        {
            if (((MMTGeneralFact)fact).type is not OMA proof_OMA) // proof DED
                yield break;
    
            OMA unequal_circles_OMA = (OMA)proof_OMA.arguments[0]; // unequal
    
            string circleAUri = ((OMS)unequal_circles_OMA.arguments[0]).uri;
            string circleBUri = ((OMS)unequal_circles_OMA.arguments[1]).uri;
    
            if (!FactRecorder.AllFacts.ContainsKey(circleAUri)
             || !FactRecorder.AllFacts.ContainsKey(circleBUri))
                yield break;
    
            ret.Add(new UnEqualCirclesFact(circleAUri, circleBUri, fact.@ref));
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel(FactRecorder name_space)
            => Circle1.GetLabel(name_space) + " = " + Circle2.GetLabel(name_space);
    
        public override MMTFact MakeMMTDeclaration()
        {
            SOMDoc tp = new OMA(
                new OMS(MMTConstants.Ded),
                new[] {
                    new OMA(new OMS(MMTConstants.UnEqualityCircles),
                    new[]  {
                        new OMS(Cid1),
                        new OMS(Cid2),
            }),});
    
            return new MMTGeneralFact(_LastLabel, tp, Defines());
        }
    
        public override SOMDoc Defines()
            => null;
    
        /// \copydoc Fact.hasDependentFacts
        public override bool HasDependentFacts => true;
    
        /// \copydoc Fact.getDependentFactIds
        protected override string[] GetDependentFactIds()
            => new string[] { Cid1, Cid2 };
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(UnEqualCirclesFact f1, UnEqualCirclesFact f2)
            => DependentFactsEquivalent(f1, f2);
    
        protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new)
            => new UnEqualCirclesFact(old_to_new[this.Cid1], old_to_new[this.Cid2]);
    }