diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/CuboidFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/CuboidFact.cs new file mode 100644 index 0000000000000000000000000000000000000000..54afb9f74acc0a663aadf74993fa6def081f5299 --- /dev/null +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/CuboidFact.cs @@ -0,0 +1,161 @@ +using Newtonsoft.Json; +using REST_JSON_API; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +/// <summary> +/// Point in 3D Space +/// </summary> +public class CuboidFact : FactWrappedCRTP<CuboidFact> +{ + + + //used points + public string PidR, PidT; + + public Vector3 T; + public RectangleFact RF = null; + + public float Area = 0.0F; + + + public RectangleFact GetR {get => (RectangleFact)FactRecorder.AllFacts[PidR];} + public PointFact GetT {get => (PointFact)FactRecorder.AllFacts[PidT];} + protected void calculate_vectors(){ + + /* + A = ((PointFact)FactRecorder.AllFacts[PidA]).Point + Vector3.zero; + B = ((PointFact)FactRecorder.AllFacts[PidB]).Point + Vector3.zero; + C = ((PointFact)FactRecorder.AllFacts[PidC]).Point + Vector3.zero; + D = (A - B) + C; + + Area = (Vector3.Distance(A, B) * Vector3.Distance(B, C)); + + Vector3 scale = new Vector3(Vector3.Distance(B, C), Vector3.Distance(A, B), 1.0F); + + LocalScale = scale * 0.5F; + + Position = B + 0.5F*((A-B) + (C-B)); + + Rotation = Quaternion.LookRotation(Vector3.Cross((A-B), (C-B)), Vector3.up); + //Rotation = Quaternion.LookRotation(forward, new Vector3(1.0F, 0.0F, 0.0F)); + */ + + T = ((PointFact)FactRecorder.AllFacts[PidT]).Point + Vector3.zero; + RF = ((RectangleFact)FactRecorder.AllFacts[PidR]); + + + } + + public CuboidFact() : base(){ + this.PidR = null; + this.PidT = null; + } + [JsonConstructor] + public CuboidFact( string PidR, string PidT) : base() + { + + this.PidR = PidR; + this.PidT = PidT; + + 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 CuboidFact(string PidR, string PidT, SOMDoc ServerDefinition) : base() + { + + + this.PidR = PidR; + this.PidT = PidT; + + 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 rectangleR, pointT; + + rectangleR = (OMS)df.arguments[0]; + pointT = (OMS)df.arguments[1]; + + string PidR = rectangleR.uri; + string PidT = pointT.uri; + + + + ret.Add(new CuboidFact(PidR, PidT, fact.@ref)); + + //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[] {PidR, PidT}; + + /// \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(CuboidFact f1, CuboidFact f2){ + + return ( + + Math3d.IsApproximatelyEqual(f1.T, f2.T) + && f1.RF.isEqual(f2.RF) + + ); + + } + + protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new){ + + return new CuboidFact(this.PidR, this.PidT); + + } + + public override MMTFact MakeMMTDeclaration() + { + SOMDoc tp = new OMS(MMTConstants.CuboidType); + + return new MMTGeneralFact(_LastLabel, tp, Defines()); + } + + public override SOMDoc Defines() + => new OMA( + new OMS(MMTConstants.CuboidCons), + new[] { + new OMS(PidR), + new OMS(PidT) + } + ); +} \ No newline at end of file diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/CuboidFact.cs.meta b/Assets/Scripts/InteractionEngine/FactHandling/Facts/CuboidFact.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..a8dacc7c29aa0261ea97c68b9ec560b80715df7b --- /dev/null +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/CuboidFact.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 67ed11bf3c4fc4043a85233ce249d78d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs index f69cc74e3a8d232ee952823274307b10a67ac021..be9021338aef2ce51e8e5f7f069b08a2c286139d 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs @@ -136,6 +136,10 @@ protected override bool EquivalentWrapped(RectangleFact f1, RectangleFact f2){ } + public bool isEqual(RectangleFact f2){ + return EquivalentWrapped(this, f2); + } + protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new){ return new RectangleFact(this.PidA, this.PidB, this.PidC); diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs index 35e80957ce172890cc97b3802f63173f1bc76de5..60cd4ebf57323a46c0369624b10f50daab8d9f5b 100644 --- a/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs @@ -48,6 +48,10 @@ public static class MMTConstants public static readonly string TriangleType = "http://mathhub.info/FrameIT/frameworld?TriangleType?triangleType"; public static readonly string TriangleScroll = "http://mathhub.info/FrameIT/frameworld?TriangleScroll"; + public static readonly string CuboidCons = "http://mathhub.info/FrameIT/frameworld?CuboidType?cuboidCons"; + public static readonly string CuboidType = "http://mathhub.info/FrameIT/frameworld?CuboidType?cuboidType"; + public static readonly string CuboidScroll = "http://mathhub.info/FrameIT/frameworld?CuboidScroll"; + public static readonly string CircleType3d = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circleType3D"; public static readonly string MkCircle3d = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circle3D"; public static readonly string TriangleMiddlePoint = "http://mathhub.info/FrameIT/frameworld?FrameITTriangles?triangleMidPointWrapper";