sVector updateVal(float lr, int includes, sVector xs, sVector weights) { xs.scale(includes); xs.scale(lr); weights.add(xs); return(weights); }
public void add(sVector other) { if (this.mag() == other.mag()) { for (int i = 0; i < this.mag(); i++) { vec[i] = vec[i] + other.get(i); } } }
public float dot(sVector other) { float ret = 0; if (this.mag() == other.mag()) { for (int i = 0; i < this.mag(); i++) { ret += this.get(i) * other.get(i); } } return(ret); }
/// <summary> /// Load pre saved memory /// </summary> /// <param name="data">Memory data</param> /// <param name="Clear">Clear memory before load ?</param> public void Load(byte[] data, bool Clear = true) { byte[] decryptedData = MoonSecurity.AES_Decrypt(data); if (decryptedData == null || decryptedData.Length == 0) { return; } if (Clear) { memory.Clear(); } MemoryStream mem = new MemoryStream(decryptedData); BinaryFormatter formatter = new BinaryFormatter(); Dictionary <string, object> dic = (Dictionary <string, object>)formatter.Deserialize(mem); mem.Close(); string[] keys = new string[dic.Keys.Count]; dic.Keys.CopyTo(keys, 0); for (int i = 0; i < keys.Length; i++) { object currentValue; if (dic.TryGetValue(keys[i], out currentValue)) { System.Type etype = currentValue.GetType(); string ekey = keys[i]; if (etype == typeof(sColor)) { Color col = (sColor)currentValue; SetValue(ekey, col); } else if (etype == typeof(sVector)) { sVector svec = (sVector)currentValue; switch (svec.Type) { case sVector.VectorType.Vector2: Vector2 v2 = svec; SetValue(ekey, v2); break; case sVector.VectorType.Vector3: Vector3 v3 = svec; SetValue(ekey, v3); break; case sVector.VectorType.Vector4: Vector4 v4 = svec; SetValue(ekey, v4); break; } } else if (etype == typeof(sLayerMask)) { LayerMask mask = (sLayerMask)currentValue; SetValue(ekey, mask); } else { SetValue(ekey, currentValue); } } } }
void setValues() { CoM = centerOfMass(); Dist = distToCoM(); }