Newer
Older
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 CylinderFact : FactWrappedCRTP<CylinderFact>
{
//used points
public string PidM, PidE, PidT;
public Vector3 M, E, T;
public float Volume = 0.0F;
public float Radius = 0.0F;
public float Height = 0.0F;
public PointFact GetM {get => (PointFact)FactRecorder.AllFacts[PidM];}
public PointFact GetE {get => (PointFact)FactRecorder.AllFacts[PidE];}
public PointFact GetT {get => (PointFact)FactRecorder.AllFacts[PidT];}
protected void calculate_vectors(){
M = ((PointFact)FactRecorder.AllFacts[PidM]).Point + Vector3.zero;
E = ((PointFact)FactRecorder.AllFacts[PidE]).Point + Vector3.zero;
T = ((PointFact)FactRecorder.AllFacts[PidT]).Point + Vector3.zero;
//Rotation = Quaternion.LookRotation(forward, new Vector3(1.0F, 0.0F, 0.0F));
LocalScale = new Vector3(Radius*2 + 0.1F, Height + 0.1F, Radius*2 + 0.1F);
Vector3 bottomnormal = (T - M).normalized;
Vector3 rightvector = (E - M).normalized;
Rotation = Quaternion.LookRotation(rightvector, bottomnormal);
Volume = Mathf.PI * Radius * Radius * Height;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
}
public CylinderFact() : base(){
this.PidM = null;
this.PidE = null;
this.PidT = null;
}
[JsonConstructor]
public CylinderFact( string PidM, string PidE, string PidT) : base()
{
this.PidM = PidM;
this.PidE = PidE;
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 CylinderFact(string PidM, string PidE, string PidT, SOMDoc ServerDefinition) : base()
{
this.PidM = PidM;
this.PidE = PidE;
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 pointM, pointE, pointT;
pointM = (OMS)df.arguments[0];
pointE = (OMS)df.arguments[1];
pointT = (OMS)df.arguments[2];
string PidM = pointM.uri;
string PidE = pointE.uri;
string PidT = pointT.uri;
ret.Add(new CylinderFact(PidM, PidE, PidT));
//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[] { PidM, PidE, 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(CylinderFact f1, CylinderFact f2){
return (
Math3d.IsApproximatelyEqual(f1.M, f2.M)
&& Math3d.IsApproximatelyEqual(f1.E, f2.E)
&& Math3d.IsApproximatelyEqual(f1.T, f2.T)
);
}
public bool isEqual(CylinderFact f2){
return EquivalentWrapped(this, f2);
}
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new){
return new CylinderFact(this.PidM, this.PidE, this.PidT);
}
public override MMTFact MakeMMTDeclaration()
{
SOMDoc tp = new OMS(MMTConstants.CylinderType);
return new MMTGeneralFact(_LastLabel, tp, Defines());
}
public override SOMDoc Defines()
=> new OMA(
new OMS(MMTConstants.CylinderCons),
new[] {
new OMS(PidM),
new OMS(PidE),
new OMS(PidT),
}
);
}