public void GenerateVelocityConstraints() { Constraints = new TimingContraint[0]; if (Points.Length <= 2) { return; } double current = 0.0; for (int i = 0; i < Points.Length - 1; i++) { double dist = CalcDistance(i); if (Points[i].Velocity < MaxVelocity && i > 0 || (Points[i].Velocity < MaxVelocity && i == 0 && Points[i].Velocity > 0)) { // // We need a velocity contraint for this point // DistanceVelocityConstraint d = new DistanceVelocityConstraint(current, current + dist, Points[i].Velocity); Array.Resize <TimingContraint>(ref Constraints, Constraints.Length + 1); Constraints[Constraints.Length - 1] = d; } current += dist; } }
public override TimingContraint ReadJson(JsonReader reader, Type objectType, TimingContraint existingValue, bool hasExistingValue, JsonSerializer serializer) { TimingContraint ret = null; if (reader.TokenType == JsonToken.Null) { return(ret); } JObject obj = JObject.Load(reader); JToken token = obj["type"]; if (token == null) { throw new JsonSerializationException("Error deserializing TimingContstraint, no 'type' field"); } if (token.ToString() == "centripetal") { double maxacc = 0.0; try { token = obj["maxaccel"]; if (token == null) { throw new JsonSerializationException("Error deserializing TimingContstraint (type = DistanceVelocityConstraint), no 'maxaccel' field"); } maxacc = token.ToObject <Double>(); } catch (Exception ex) { throw new JsonSerializationException("Error deserializing TimingContstraint, 'maxaccel' field was not a valid number", ex); } ret = new CentripetalAccelerationConstraint(maxacc); } else if (token.ToString() == "distance_velocity") { double before = 0.0, after = 0.0, velocity = 0.0; try { token = obj["after"]; if (token == null) { throw new JsonSerializationException("Error deserializing TimingContstraint (type = DistanceVelocityConstraint), no 'after' field"); } after = token.ToObject <Double>(); } catch (Exception ex) { throw new JsonSerializationException("Error deserializing TimingContstraint, 'after' field was not a valid number", ex); } try { token = obj["before"]; if (token == null) { throw new JsonSerializationException("Error deserializing TimingContstraint (type = DistanceVelocityConstraint), no 'before' field"); } before = token.ToObject <Double>(); } catch (Exception ex) { throw new JsonSerializationException("Error deserializing TimingContstraint, 'before' field was not a valid number", ex); } try { token = obj["velocity"]; if (token == null) { throw new JsonSerializationException("Error deserializing TimingContstraint (type = DistanceVelocityConstraint), no 'velocity' field"); } velocity = token.ToObject <Double>(); } catch (Exception ex) { throw new JsonSerializationException("Error deserializing TimingContstraint, 'velocity' field was not a valid number", ex); } ret = new DistanceVelocityConstraint(after, before, velocity); } else { throw new JsonSerializationException("Error deserializing TimingContstraint, type '" + token.ToString() + "' is not valid"); } return(ret); }