Skip to content
Snippets Groups Projects
PrismFact.cs 4.01 KiB
using Newtonsoft.Json;
using REST_JSON_API;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;

/// <summary>
/// Point in 3D Space
/// </summary>
public class PrismFact : FactWrappedCRTP<PrismFact>
{


    //used points
    public string PidT, PidD;

    public Vector3 A, B, C, a, b, c, D;

    public float cPosition;

    public float Volume = 0.0F;



    public TriangleFact2 GetT {get =>  (TriangleFact2)FactRecorder.AllFacts[PidT];}
    public PointFact GetD {get =>  (PointFact)FactRecorder.AllFacts[PidD];}
    protected void calculate_vectors(){

        A = ((TriangleFact2)FactRecorder.AllFacts[PidT]).A + Vector3.zero;
        B = ((TriangleFact2)FactRecorder.AllFacts[PidT]).B + Vector3.zero;
        C = ((TriangleFact2)FactRecorder.AllFacts[PidT]).C + Vector3.zero;
        a = ((TriangleFact2)FactRecorder.AllFacts[PidT]).a + Vector3.zero;
        b = ((TriangleFact2)FactRecorder.AllFacts[PidT]).b + Vector3.zero;
        c = ((TriangleFact2)FactRecorder.AllFacts[PidT]).c + Vector3.zero;
        D = ((PointFact)FactRecorder.AllFacts[PidD]).Point + Vector3.zero;

        cPosition = Vector3.Distance(A, c) / Vector3.Distance(A, B);

        Volume = ((TriangleFact2)FactRecorder.AllFacts[PidT]).Area * Vector3.Distance(A, D);

        Position = ((TriangleFact2)FactRecorder.AllFacts[PidT]).Position;

        Rotation = ((TriangleFact2)FactRecorder.AllFacts[PidT]).Rotation;
    }

    public PrismFact() : base(){
        this.PidT = null;
        this.PidD = null;
    }
    [JsonConstructor]
    public PrismFact( string PidT, string PidD) : base()
    {
        this.PidT = PidT;
        this.PidD = PidD;

        calculate_vectors();
    }

    /// <summary>
    /// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
    /// <see cref="Normal"/> set to <c>Vector3.up</c>
    /// </summary>
    /// <param name="Point">sets <see cref="Point"/></param>
    /// <param name="ServerDefinition">MMT URI as OMS</param>
    public PrismFact(string PidT, string PidD, SOMDoc ServerDefinition) : base()
    {
        this.PidT = PidT;
        this.PidD = PidD;
        
        this.ServerDefinition = ServerDefinition;

        calculate_vectors();
    }

    /// \copydoc Fact.parseFact(ScrollFact)
    public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
    {
        if (((MMTGeneralFact)fact).defines is not OMA df)
            yield break;

        OMS triangleT, pointD;

        triangleT = (OMS)df.arguments[0];
        pointD = (OMS)df.arguments[1];

        string PidT = triangleT.uri;
        string PidD = pointD.uri;

        

        ret.Add(new PrismFact(PidT, PidD));

        //ParsingDictionary.parseTermsToId.TryAdd(defines.ToString(), fact.@ref.uri);
        //ret.Add(new PointFact(SOMDoc.MakeVector3(defines), fact.@ref));
    }


    /// \copydoc Fact.hasDependentFacts
    public override bool HasDependentFacts => true;

    /// \copydoc Fact.getDependentFactIds
    protected override string[] GetDependentFactIds()
        => new string[] { PidT, PidD};

    /// \copydoc Fact.GetHashCode
    /* public override int GetHashCode()
        => this.Point.GetHashCode();
    */
    protected override void RecalculateTransform()
    {
        calculate_vectors();
    }
    /// \copydoc Fact.Equivalent(Fact, Fact)
    protected override bool EquivalentWrapped(PrismFact p1, PrismFact p2){
        return DependentFactsEquivalent(p1, p2);
    }

    protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new){
        return new PrismFact(this.PidT, this.PidD);
    }

    public override MMTFact MakeMMTDeclaration()
    {
        SOMDoc tp = new OMS(MMTConstants.PrismType);

        return new MMTGeneralFact(_LastLabel, tp, Defines());
    }

    public override SOMDoc Defines()
        => new OMA(
                new OMS(MMTConstants.PrismCons),
                new[] {
                    new OMS(PidT),
                    new OMS(PidD),
                }
            );
}