public PathRequest(Vector3 _start, Vector3 _end, PathCallback _callback, PathParameters _pathParameters) { pathStart = _start; pathEnd = _end; callback = _callback; pathParameters = _pathParameters; }
/// <summary> /// Regenerates the path given the parameters. /// </summary> /// <param name="parameters"></param> /// <param name="lod"></param> /// <param name="split"></param> /// <param name="isSculpted"></param> /// <param name="sculptSize"></param> /// <returns>true if the path has actually changed.</returns> public bool Generate(PathParameters parameters, float lod = 1f, int split = 0, bool isSculpted = false, int sculptSize = 1) { // TODO: Possibly do some testing that would enable us to quit early here if no generation is needed. Points.Clear(); IsOpen = true; switch (parameters.PathType) { case PathType.Line: GenerateLine(parameters, lod, split, isSculpted, sculptSize); break; case PathType.Circle: GenerateCircle(parameters, lod, split, isSculpted, sculptSize); break; case PathType.Circle2: GenerateCircle2(parameters, lod, split, isSculpted, sculptSize); break; case PathType.Test: GenerateTest(parameters, lod, split, isSculpted, sculptSize); break; } return(true); }
protected void GenerateLine(PathParameters parameters, float lod, int split, bool isSculpted, int sculptSize) { // Take the begin/end twist into account for detail. int nPoints = Mathf.FloorToInt(Mathf.Abs(parameters.TwistBegin - parameters.TwistEnd) * 3.5f * (lod - 0.5f)) + 2; if (nPoints < split + 2) { nPoints = split + 2; } Step = 1.0f / (nPoints - 1); Vector2 startScale = parameters.BeginScale; Vector2 endScale = parameters.EndScale; for (int i = 0; i < nPoints; i++) { float t = Mathf.Lerp(parameters.Begin, parameters.End, i * Step); Points.Add(new PathPoint { Position = new Vector3(Mathf.Lerp(0, parameters.Shear.x, t), Mathf.Lerp(0, parameters.Shear.y, t), t - 0.5f), Rotation = Matrix4x4.Rotate(Quaternion.AngleAxis(Mathf.Lerp(Mathf.PI * parameters.TwistBegin, Mathf.PI * parameters.TwistEnd, t) * Mathf.Rad2Deg, new Vector3(0f, 0f, 1f))), Scale = new Vector2(Mathf.Lerp(startScale.x, endScale.x, t), Mathf.Lerp(startScale.y, endScale.y, t)), ExtrusionT = t }); } }
public OWINApplication AddApplication(string path, PathParameters parameters, AppFunc application) { var app = new OWINApplication(path, parameters, application); applications.Add(app); return(app); }
protected void AddNGonPoint(PathParameters parameters, float radiusStart, float radiusEnd, float holeX, float holeY, float taperXBegin, float taperXEnd, float taperYBegin, float taperYEnd, float twistScale, float t) { float ang = 2.0f * Mathf.PI * parameters.Revolutions * t; float c = Mathf.Cos(ang) * Mathf.Lerp(radiusStart, radiusEnd, t); float s = Mathf.Sin(ang) * Mathf.Lerp(radiusStart, radiusEnd, t); // Twist rotates the path along the x,y plane (I think) - DJS 04/05/02 Quaternion twist = Quaternion.AngleAxis((2f * Mathf.PI * Mathf.Lerp(parameters.TwistBegin * twistScale, parameters.TwistEnd * twistScale, t)) * Mathf.Rad2Deg, // Note: Indra subtracts PI from this angle, but that makes torus shapes weird new Vector3(0f, 0f, 1f)); // Rotate the point around the circle's center. Quaternion qang = Quaternion.AngleAxis(ang * Mathf.Rad2Deg, new Vector3(1f, 0f, 0f)); Points.Add(new PathPoint { Position = new Vector3(0f + Mathf.Lerp(0, parameters.Shear.x, s) + Mathf.Lerp(-parameters.Skew, parameters.Skew, t) * 0.5f, c + Mathf.Lerp(0, parameters.Shear.y, s), s), Scale = new Vector2(holeX * Mathf.Lerp(taperXBegin, taperXEnd, t), holeY * Mathf.Lerp(taperYBegin, taperYEnd, t)), Rotation = Matrix4x4.Rotate(twist * qang), ExtrusionT = t }); }
private double ConvertUnit(UnitOfMeasure targetUOM) { // get path factors in each system PathParameters thisParameters = TraversePath(); PathParameters targetParameters = targetUOM.TraversePath(); double thisPathFactor = thisParameters.PathFactor; UnitOfMeasure thisBase = thisParameters.PathUOM; double targetPathFactor = targetParameters.PathFactor; UnitOfMeasure targetBase = targetParameters.PathUOM; // check for a base conversion unit bridge double?bridgeFactor = thisBase.GetBridgeFactor(targetBase); if (bridgeFactor.HasValue) { thisPathFactor = thisPathFactor * bridgeFactor.Value; } // new path amount double scalingFactor = thisPathFactor / targetPathFactor; return(scalingFactor); }
/// <summary>Adds a parameter value.</summary> /// <param name="type">Type of the parameter (must be 'Path' or 'Query').</param> /// <param name="name">Parameter name.</param> /// <param name="value">Parameter value.</param> public void AddParameter(RequestParameterType type, string name, string value) { name.ThrowIfNull("name"); if (value == null) { Logger.Warning("Add parameter should not get null values. type={0}, name={1}", type, name); return; } switch (type) { case RequestParameterType.Path: if (!PathParameters.ContainsKey(name)) { PathParameters[name] = new List <string> { value }; } else { PathParameters[name].Add(value); } break; case RequestParameterType.Query: QueryParameters.Add(new KeyValuePair <string, string>(name, value)); break; default: throw new ArgumentOutOfRangeException("type"); } }
public void MoveTo(string pointName, float speed) { float dist = FullDist(pointName); PathParameters pp = new PathParameters(pointName, dist); currentPointName = pp.destinationName; AddTime(pp.dist / speed); }
public void SetParameterPort() { const int value = 8088; var parameters = new PathParameters { Port = value }; var expected = string.Format(@" /port:{0}", value); parameters.ToString().Should().Be(expected); }
public void SetParameterPath() { const string value = @"C:\My Path\MySiteFolder"; var parameters = new PathParameters { Path = value }; var expected = string.Format(@" /path:""{0}""", value); parameters.ToString().Should().Be(expected); }
public void SetParameterClrVersion() { const string value = @"v4.0"; var parameters = new PathParameters { ClrVersion = value }; var expected = string.Format(@" /clr:""{0}""", value); parameters.ToString().Should().Be(expected); }
public float FullDist(string pointName) { float dist = 0; PathParameters[] all = PathParameters.FromTo(currentPointName, pointName); foreach (PathParameters f in all) { dist += f.dist; } return(dist); }
public void SetParameterTraceLevel(TraceLevel traceLevel) { var configFileParameters = new ConfigFileParameters { TraceLevel = traceLevel }; var pathParameters = new PathParameters { TraceLevel = traceLevel }; var expected = " /trace:" + traceLevel.ToString().ToLower(); configFileParameters.ToString().Should().Be(expected); pathParameters.ToString().Should().Be(expected); }
public void SetParameterSystray(bool value) { var configFileParameters = new ConfigFileParameters { Systray = value }; var pathParameters = new PathParameters { Systray = value }; var expected = " /systray:" + value.ToString().ToLower(); configFileParameters.ToString().Should().Be(expected); pathParameters.ToString().Should().Be(expected); }
protected void GenerateCircle(PathParameters parameters, float lod, int split, bool isSculpted, int sculptSize) { float twistMag = Mathf.Abs(parameters.TwistBegin - parameters.TwistEnd); int nSides = Mathf.FloorToInt(Mathf.Floor(Volume.MIN_DETAIL_FACES * lod + twistMag * 3.5f * (lod - 0.5f)) * parameters.Revolutions); if (isSculpted) { nSides = Mathf.Max(sculptSize, 1); } if (nSides > 0) { GenNGon(parameters, nSides); } }
/// <summary> /// Construct a URI as defined by the parts of this request builder. /// </summary> /// <returns>A <see cref="System.Uri"/> for this request.</returns> /// <remarks>Method is not included in the Uri.</remarks> public Uri BuildUri() { var restPath = new StringBuilder(PathParameters .Select(param => new { Token = "{" + param.Key + "}", Value = Uri.EscapeDataString(param.Value) }) .Aggregate(this.Path, (path, param) => path.Replace(param.Token, param.Value))); if (QueryParameters.Count > 0) { restPath.Append("?"); restPath.Append(String.Join("&", QueryParameters.Select( x => String.Format("{0}={1}", Uri.EscapeDataString(x.Key), Uri.EscapeDataString(x.Value))) .ToArray())); } return(UriFactory.Create(this.BaseUri, restPath.ToString())); }
public static PathParameters[] FromTo(string fr, string to) { List <PathParameters> pps = PathParameters.pathParametersAll.ToList(); PathParameters start = pps.FirstOrDefault((PathParameters pp) => pp.destinationName == fr); PathParameters end = pps.FirstOrDefault((PathParameters pp) => pp.destinationName == to); int s = pps.IndexOf(start); int e = pps.IndexOf(end); return(pps.Where((PathParameters pp) => { int i = pps.IndexOf(pp); return i > s && !(i > e); }).ToArray()); }
protected void GenerateCircle2(PathParameters parameters, float lod, int split, bool isSculpted, int sculptSize) { if (parameters.End - parameters.Begin >= 0.99f && parameters.Scale.x >= 0.99f) { IsOpen = false; } GenNGon(parameters, Mathf.FloorToInt(Volume.MIN_DETAIL_FACES * lod)); float x = 0.5f; foreach (PathPoint point in Points) { point.Position.x = x; x *= -1f; } }
/// <summary> /// Construct a URI as defined by the parts of this request builder. /// </summary> /// <returns>A <see cref="System.Uri"/> for this request.</returns> /// <remarks>Method is not included in the Uri.</remarks> public Uri BuildUri() { var restPath = new StringBuilder(PathParameters .Select(param => new { Token = "{" + param.Key + "}", Value = Uri.EscapeDataString(param.Value) }) .Aggregate(this.Path, (path, param) => path.Replace(param.Token, param.Value))); if (QueryParameters.Count > 0) { restPath.Append("?"); // If paramter value is empty - just add the "name", otherwise "name=value" restPath.Append(String.Join("&", QueryParameters.Select( x => x.Value.IsNullOrEmpty() ? Uri.EscapeDataString(x.Key) : String.Format("{0}={1}", Uri.EscapeDataString(x.Key), Uri.EscapeDataString(x.Value))) .ToArray())); } return(UriFactory.Create(this.BaseUri, restPath.ToString())); }
protected void GenerateTest(PathParameters parameters, float lod, int split, bool isSculpted, int sculptSize) { int nPoints = 5; Step = 1.0f / (nPoints - 1); for (int i = 0; i < nPoints; i++) { float t = i * Step; Points.Add(new PathPoint { Position = new Vector3(0f, Mathf.Lerp(0, -Mathf.Sin(Mathf.PI * parameters.TwistEnd * t) * 0.5f, t), Mathf.Lerp(-0.5f, Mathf.Cos(Mathf.PI * parameters.TwistEnd * t) * 0.5f, t)), Scale = new Vector2(Mathf.Lerp(1f, parameters.Scale.x, t), Mathf.Lerp(1f, parameters.Scale.y, t)), ExtrusionT = t, Rotation = Matrix4x4.Rotate(Quaternion.AngleAxis(Mathf.PI * parameters.TwistEnd * t * Mathf.Rad2Deg, new Vector3(1f, 0f, 0f))) }); } }
/// <summary> /// Adds a parameter value. /// </summary> /// <param name="type">Type of the parameter (must be Path or Query).</param> /// <param name="name">Parameter name.</param> /// <param name="value">Parameter value.</param> public void AddParameter(RequestParameterType type, string name, string value) { switch (type) { case RequestParameterType.Path: if (string.IsNullOrEmpty(value)) { throw new ArgumentException("Path parameters cannot be null or empty."); } PathParameters.Add(name, value); break; case RequestParameterType.Query: if (value == null) // don't allow null values on query (empty value is valid) { break; } QueryParameters.Add(new KeyValuePair <string, string>(name, value)); break; default: throw new ArgumentOutOfRangeException("type"); } }
new MessageRulesRequestBuilder(PathParameters, RequestAdapter);
public void DefaultPathParametersShouldBeEmpty() { var parameters = new PathParameters(); parameters.ToString().Should().Be(string.Empty); }
public void SetPathParameters(PathParameters pathParameters) { this.pathParameters = pathParameters; }
private IEnumerator FindPath(Vector3 start, Vector3 target, PathParameters parameters) { Vector3[] waypoints = new Vector3[0]; bool pathSuccess = false; var startNode = grid.NodeFromWorldPoint(start); var targetNode = grid.NodeFromWorldPoint(target); if (startNode == null || targetNode == null) { requestManager.FinishedProcessingPath(waypoints, pathSuccess, parameters); yield break; } var openSet = new Heap <Node>(grid.MaxSize); var closedSet = new HashSet <Node>(); openSet.Add(startNode); while (openSet.Count > 0) { Node currentNode = openSet.RemoveFirst(); closedSet.Add(currentNode); if (currentNode == targetNode) { pathSuccess = true; break; } foreach (Node neighbour in grid.GetNeighbours(currentNode)) { if (!neighbour.Walkable || closedSet.Contains(neighbour)) { continue; } if (Diagonal(currentNode, neighbour)) { var n1 = grid.GetNode(currentNode.xGrid, neighbour.yGrid); var n2 = grid.GetNode(neighbour.xGrid, currentNode.yGrid); if (!n1.Walkable || !n2.Walkable) { continue; } } int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, neighbour) + neighbour.MovementPenalty; if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour)) { neighbour.gCost = newMovementCostToNeighbour; neighbour.hCost = GetDistance(neighbour, targetNode); neighbour.parent = currentNode; if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); } else { openSet.UpdateItem(neighbour); } } } } if (pathSuccess) { waypoints = RetracePath(start, startNode, targetNode, parameters.AllAngles); } requestManager.FinishedProcessingPath(waypoints, pathSuccess, parameters); }
new ChildFoldersRequestBuilder(PathParameters, RequestAdapter);
public void StartFindPath(Vector3 startPos, Vector3 targetPos, PathParameters parameters) { StartCoroutine(FindPath(startPos, targetPos, parameters)); }
public OWINApplication(string path, PathParameters parameters, AppFunc appfunc) { this.Path = path; this.Parameters = parameters; this.AppFunc = appfunc; }
/// <summary> /// Builds the REST path string builder based on <see cref="PathParameters"/> and the URI template spec /// http://tools.ietf.org/html/rfc6570. /// </summary> /// <returns></returns> private StringBuilder BuildRestPath() { if (string.IsNullOrEmpty(Path)) { return(new StringBuilder(string.Empty)); } var restPath = new StringBuilder(Path); var matches = PathParametersPattern.Matches(restPath.ToString()); foreach (var match in matches) { var matchStr = match.ToString(); // Strip the first and last characters: '{' and '}'. var content = matchStr.Substring(1, matchStr.Length - 2); var op = string.Empty; // If the content's first character is an operator, save and remove it from the content string. if (OPERATORS.Contains(content[0].ToString())) { op = content[0].ToString(); content = content.Substring(1); } var newContent = new StringBuilder(); // Iterate over all possible parameters. var parameters = content.Split(','); for (var index = 0; index < parameters.Length; ++index) { var parameter = parameters[index]; var parameterName = parameter; var containStar = false; var numOfChars = 0; // Check if it ends with '*'. if (parameterName[parameterName.Length - 1] == '*') { containStar = true; parameterName = parameterName.Substring(0, parameterName.Length - 1); } // Check if it contains :n which means we should only use the first n characters of this parameter. if (parameterName.Contains(":")) { if (!int.TryParse(parameterName.Substring(parameterName.IndexOf(":") + 1), out numOfChars)) { throw new ArgumentException( string.Format("Can't parse number after ':' in Path \"{0}\". Parameter is \"{1}\"", Path, parameterName), Path); } parameterName = parameterName.Substring(0, parameterName.IndexOf(":")); } // We can improve the following if statement, but for readability we will leave it like that. var joiner = op; var start = op; switch (op) { case "+": start = index == 0 ? "" : ","; joiner = ","; break; case ".": if (!containStar) { joiner = ","; } break; case "/": if (!containStar) { joiner = ","; } break; case "#": start = index == 0 ? "#" : ","; joiner = ","; break; case "?": start = (index == 0 ? "?" : "&") + parameterName + "="; joiner = ","; if (containStar) { joiner = "&" + parameterName + "="; } break; case "&": case ";": start = op + parameterName + "="; joiner = ","; if (containStar) { joiner = op + parameterName + "="; } break; // No operator, in that case just ','. default: if (index > 0) { start = ","; } joiner = ","; break; } // Check if a path parameter equals the name which appears in the REST path. if (PathParameters.ContainsKey(parameterName)) { var value = string.Join(joiner, PathParameters[parameterName]); // Check if we need to use a substring of the value. if (numOfChars != 0 && numOfChars < value.Length) { value = value.Substring(0, numOfChars); } if (op != "+" && op != "#" && PathParameters[parameterName].Count == 1) { value = Uri.EscapeDataString(value); } value = start + value; newContent.Append(value); } else { throw new ArgumentException( string.Format("Path \"{0}\" misses a \"{1}\" parameter", Path, parameterName), Path); } } if (op == ";") { if (newContent[newContent.Length - 1] == '=') { newContent = newContent.Remove(newContent.Length - 1, 1); } newContent = newContent.Replace("=;", ";"); } restPath = restPath.Replace(matchStr, newContent.ToString()); } return(restPath); }
public void RequestPath(Vector3 pathStart, Vector3 pathEnd, PathCallback callback, PathParameters parameters) { PathRequest newRequest = new PathRequest( pathStart, pathEnd, callback, parameters == null ? PathParameters.Default : parameters ); pathRequestQueue.Enqueue(newRequest); TryProcessNext(); }
public void FinishedProcessingPath(Vector3[] path, bool success, PathParameters parameters) { currentPathRequest.callback(path, success, parameters); isProcessingPath = false; TryProcessNext(); }