Skip to content
Snippets Groups Projects
Fact.cs 147 KiB
Newer Older
  • Learn to ignore specific revisions
  •     {
            return this.Cid1.GetHashCode() ^ this.Cid2.GetHashCode();
        }
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(UnEqualCirclesFact f1, UnEqualCirclesFact f2)
        {
            if ((f1.Cid1 == f2.Cid1 && f1.Cid2 == f2.Cid2))
                return true;
    
            CircleFact e1f1 = (CircleFact)_Facts[f1.Cid1];
            CircleFact e2f1 = (CircleFact)_Facts[f1.Cid2];
            CircleFact e1f2 = (CircleFact)_Facts[f2.Cid1];
            CircleFact e2f2 = (CircleFact)_Facts[f2.Cid2];
    
            return (e1f1.Equivalent(e1f2) && e2f1.Equivalent(e2f2));
        }
    }
    
    
    /// TEST FACT
    
    ki7077's avatar
    ki7077 committed
    /// use this if you need to test certain implementations of facts.
    
    ki7077's avatar
    ki7077 committed
    /// just for testing purposes  
    
    /// </summary>
    public class TestFact : FactWrappedCRTP<TestFact>
    {
    
    MaZiFAU's avatar
    MaZiFAU committed
        /// \copydoc Fact.s_type
        [JsonProperty]
        protected static new string s_type = "TestFact";
    
    
    
    
    
        /// <summary> \copydoc Fact.Fact </summary>
        public TestFact() : base()
        {
            
        }
    
        /// <summary>
        /// Copies <paramref name="fact"/> by initiating new MMT %Fact.
        /// </summary>
        /// <param name="fact">Fact to be copied</param>
        /// <param name="old_to_new"><c>Dictionary</c> mapping <paramref name="fact"/>.<see cref="getDependentFactIds"/> in <paramref name="fact"/>.<see cref="Fact._Facts"/> to corresponding <see cref="Fact.Id"/> in <paramref name="organizer"/> </param>
        /// <param name="organizer">sets <see cref="_Facts"/></param>
        public TestFact(TestFact fact, Dictionary<string, string> old_to_new, FactOrganizer organizer) : base(fact, organizer)
        {
            init();
        }
    
        /// <summary>
        /// Standard Constructor
        /// </summary>
        /// <param name="pid1">sets <see cref="Pid1"/></param>
        /// <param name="pid2">sets <see cref="Pid2"/></param>
        /// <param name="radius">sets <see cref="radius"/></param>
        /// <param name="normal">sets <see cref="normal"/></param>
        /// <param name="organizer">sets <see cref="Fact._Facts"/></param>
        public TestFact( FactOrganizer organizer) : base(organizer)
        {
            init();
        }
    
        /// <summary>
        /// Initiates <see cref="Pid1"/>, <see cref="Pid2"/>, <see cref="radius"/>,<see cref="dir1"/>,<see cref="dir2"/>, <see cref="Fact._URI"/> and creates MMT %Fact Server-Side
        /// </summary>
        /// <param name="pid1">sets <see cref="Pid1"/></param>
        /// <param name="pid2">sets <see cref="Pid2"/></param>
        /// <param name="radius">sets <see cref="radius"/></param>
        /// <param name="normal">sets <see cref="normal"/></param>
        private void init()
        {
            
    
           // mmtDecl = generateCircleFactDeclaration(p1URI, p2URI, radius, normal);
    
          //  AddFactResponse.sendAdd(mmtDecl, out this._URI);
        }
    
        /// <summary>
        /// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
        /// </summary>
        /// <param name="Pid1">sets <see cref="Pid1"/></param>
        /// <param name="Pid2">sets <see cref="Pid2"/></param>
        /// <param name="radius">sets <see cref="radius"/></param>
        /// <param name="normal">sets <see cref="normal"/></param>
        /// <param name="backendURI">MMT URI</param>
        /// <param name="organizer">sets <see cref="Fact._Facts"/></param>
        public TestFact( string backendURI, FactOrganizer organizer) : base(organizer)
        {
          
            this._URI = backendURI;
            _ = this.Label;
        }
    
        /// <summary>
        /// parses the Circlefact response of the MMT-Server
        /// </summary>
        /// \copydoc Fact.parseFact(Scroll.ScrollFact) 
        public new static TestFact parseFact(Scroll.ScrollFact fact)
        {
            string uri = fact.@ref.uri;
            Debug.Log("TestFact Uri:" + uri);
            return new TestFact(uri, StageStatic.stage.factState);
          
        }
    
        /// \copydoc Fact.generateLabel
        protected override string generateLabel()
        {
    
            return "test" ;
        }
    
    
    
        /// <summary>
        /// Constructs struct for right-angled MMT %Fact <see cref="AddFactResponse"/>
        /// </summary>
        /// <param name="p1URI"> <see cref="Pid1"/></param>
        /// <param name="p2URI"> <see cref="Pid2"/></param>
        /// <param name="radius"> <see cref="radius"/></param>
        /// <returns>struct for <see cref="AddFactResponse"/></returns>
        private MMTDeclaration generateCircleFactDeclaration(string p1URI, string p2URI, float radius, Vector3 normal)
        {
            PointFact p1 = _Facts[p1URI] as PointFact;
            PointFact p2 = _Facts[p2URI] as PointFact;
    
    
            List<MMTTerm> normalArgs = new List<MMTTerm>
            {
                new OMF(normal.x),
                new OMF(normal.y),
                new OMF(normal.z)
            };
            OMA NormalVector = new OMA(new OMS(MMTURIs.Tuple), normalArgs);
    
    
    
            List<MMTTerm> planeArgs = new List<MMTTerm>
            {
                new OMS(p2URI),
                NormalVector //n
            };
    
            OMA CirclePlane = new OMA(new OMS(MMTURIs.pointNormalPlane), planeArgs);
            OMS middlePoint = new OMS(p1URI);
            OMF Radius = new OMF(radius);
    
            List<MMTTerm> outerArguments = new List<MMTTerm>
            {
               CirclePlane,
               middlePoint,
               Radius
            };
    
            //OMS constructor generates full URI
            // Do i need this here? doubt 
            MMTTerm tp = new OMS(MMTURIs.CircleType3d);
            MMTTerm df = new OMA(new OMS(MMTURIs.MkCircle3d), outerArguments);
    
            MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
            AddFactResponse.sendAdd(mmtDecl, out this._URI);
    
    
            return mmtDecl;
        }
    
    
        /// \copydoc Fact.hasDependentFacts
        public override Boolean hasDependentFacts()
        {
            return false;
        }
    
     
    
        /// \copydoc Fact.getDependentFactIds
        public override string[] getDependentFactIds()
        {
            return new string[] { };
        }
    
        /// \copydoc Fact.instantiateDisplay(GameObject, Transform)
        public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
        {
            var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
    
            // obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = _Facts[this.Lid2].Label;
    
            obj.GetComponent<FactWrapper>().fact = this;
            return obj;
        }
    
        /// \copydoc Fact.GetHashCode
        public override int GetHashCode()
        {
            return 112315414;// this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode();
        }
    
        /// \copydoc Fact.Equivalent(Fact, Fact)
        protected override bool EquivalentWrapped(TestFact f1, TestFact f2)
        {
            return false;