private static void test02() //****************************************************************************80 // // Purpose: // // TEST02 tests product Gauss-Legendre rules for the Legendre 3D integral. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 16 August 2014 // // Author: // // John Burkardt // { double[] a = new double[3]; double[] b = new double[3]; a[0] = -1.0; a[1] = -1.0; a[2] = -1.0; b[0] = +1.0; b[1] = +1.0; b[2] = +1.0; Console.WriteLine(""); Console.WriteLine("TEST02"); Console.WriteLine(" Product Gauss-Legendre rules for the 3D Legendre integral."); Console.WriteLine(" Density function rho(x) = 1."); Console.WriteLine(" Region: -1 <= x <= +1."); Console.WriteLine(" -1 <= y <= +1."); Console.WriteLine(" -1 <= z <= +1."); Console.WriteLine(" Exactness: 3 = 2 * min ( 2, 3, 4 ) - 1"); Console.WriteLine(" Order: N = 2 * 3 * 4"); const int nx = 2; const int ny = 3; const int nz = 4; int n = nx * ny * nz; double[] x = new double[n]; double[] y = new double[n]; double[] z = new double[n]; double[] w = new double[n]; legendre_3d_set(a, b, nx, ny, nz, ref x, ref y, ref z, ref w); const int p_max = 4; Exactness.legendre_3d_exactness(a, b, n, x, y, z, w, p_max); }
Vector3 Snap(ABPath path, Exactness mode, bool start, out bool forceAddPoint) { var index = start ? 0 : path.path.Count - 1; var node = path.path[index]; var nodePos = (Vector3)node.position; forceAddPoint = false; switch (mode) { case Exactness.ClosestOnNode: return(GetClampedPoint(nodePos, start ? path.startPoint : path.endPoint, node)); case Exactness.SnapToNode: return(nodePos); case Exactness.Original: case Exactness.Interpolate: case Exactness.NodeConnection: Vector3 relevantPoint; if (start) { relevantPoint = adjustStartPoint != null?adjustStartPoint() : path.originalStartPoint; } else { relevantPoint = path.originalEndPoint; } switch (mode) { case Exactness.Original: return(GetClampedPoint(nodePos, relevantPoint, node)); case Exactness.Interpolate: var clamped = GetClampedPoint(nodePos, relevantPoint, node); // Adjacent node to either the start node or the end node in the path var adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count - 1)]; return(VectorMath.ClosestPointOnSegment(nodePos, (Vector3)adjacentNode.position, clamped)); case Exactness.NodeConnection: // This code uses some tricks to avoid allocations // even though it uses delegates heavily // The connectionBufferAddDelegate delegate simply adds whatever node // it is called with to the connectionBuffer connectionBuffer = connectionBuffer ?? new List <GraphNode>(); connectionBufferAddDelegate = connectionBufferAddDelegate ?? (GraphNodeDelegate)connectionBuffer.Add; // Adjacent node to either the start node or the end node in the path adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count - 1)]; // Add all neighbours of #node to the connectionBuffer node.GetConnections(connectionBufferAddDelegate); var bestPos = nodePos; var bestDist = float.PositiveInfinity; // Loop through all neighbours // Do it in reverse order because the length of the connectionBuffer // will change during iteration for (int i = connectionBuffer.Count - 1; i >= 0; i--) { var neighbour = connectionBuffer[i]; // Find the closest point on the connection between the nodes // and check if the distance to that point is lower than the previous best var closest = VectorMath.ClosestPointOnSegment(nodePos, (Vector3)neighbour.position, relevantPoint); var dist = (closest - relevantPoint).sqrMagnitude; if (dist < bestDist) { bestPos = closest; bestDist = dist; // If this node is not the adjacent node // then the path should go through the start node as well forceAddPoint = neighbour != adjacentNode; } } connectionBuffer.Clear(); return(bestPos); default: throw new System.ArgumentException("Cannot reach this point, but the compiler is not smart enough to realize that."); } #if BNICKSON_UPDATED case Exactness.VisibilityCheck: if (start) { return(GetClampedPoint((Vector3)path.path[0].position, path.originalStartPoint, path.path[0], true)); } else { return(GetClampedPoint((Vector3)path.path[path.path.Count - 1].position, path.originalEndPoint, path.path[path.path.Count - 1], true)); } #endif default: throw new System.ArgumentException("Invalid mode"); } }
Vector3 Snap (ABPath path, Exactness mode, bool start, out bool forceAddPoint) { var index = start ? 0 : path.path.Count - 1; var node = path.path[index]; var nodePos = (Vector3)node.position; forceAddPoint = false; switch (mode) { case Exactness.ClosestOnNode: return GetClampedPoint(nodePos, start ? path.startPoint : path.endPoint, node); case Exactness.SnapToNode: return nodePos; case Exactness.Original: case Exactness.Interpolate: case Exactness.NodeConnection: Vector3 relevantPoint; if (start) { relevantPoint = adjustStartPoint != null ? adjustStartPoint() : path.originalStartPoint; } else { relevantPoint = path.originalEndPoint; } switch (mode) { case Exactness.Original: return GetClampedPoint(nodePos, relevantPoint, node); case Exactness.Interpolate: var clamped = GetClampedPoint(nodePos, relevantPoint, node); // Adjacent node to either the start node or the end node in the path var adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count-1)]; return VectorMath.ClosestPointOnSegment(nodePos, (Vector3)adjacentNode.position, clamped); case Exactness.NodeConnection: // This code uses some tricks to avoid allocations // even though it uses delegates heavily // The connectionBufferAddDelegate delegate simply adds whatever node // it is called with to the connectionBuffer connectionBuffer = connectionBuffer ?? new List<GraphNode>(); connectionBufferAddDelegate = connectionBufferAddDelegate ?? (GraphNodeDelegate)connectionBuffer.Add; // Adjacent node to either the start node or the end node in the path adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count-1)]; // Add all neighbours of #node to the connectionBuffer node.GetConnections(connectionBufferAddDelegate); var bestPos = nodePos; var bestDist = float.PositiveInfinity; // Loop through all neighbours // Do it in reverse order because the length of the connectionBuffer // will change during iteration for (int i = connectionBuffer.Count - 1; i >= 0; i--) { var neighbour = connectionBuffer[i]; // Find the closest point on the connection between the nodes // and check if the distance to that point is lower than the previous best var closest = VectorMath.ClosestPointOnSegment(nodePos, (Vector3)neighbour.position, relevantPoint); var dist = (closest - relevantPoint).sqrMagnitude; if (dist < bestDist) { bestPos = closest; bestDist = dist; // If this node is not the adjacent node // then the path should go through the start node as well forceAddPoint = neighbour != adjacentNode; } } connectionBuffer.Clear(); return bestPos; default: throw new System.ArgumentException("Cannot reach this point, but the compiler is not smart enough to realize that."); } default: throw new System.ArgumentException("Invalid mode"); } }
private static void test01() //****************************************************************************80 // // Purpose: // // TEST01 tests product Gauss-Legendre rules for the Legendre 3D integral. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 16 August 2014 // // Author: // // John Burkardt // { double[] a = new double[3]; double[] b = new double[3]; int l; a[0] = -1.0; a[1] = -1.0; a[2] = -1.0; b[0] = +1.0; b[1] = +1.0; b[2] = +1.0; Console.WriteLine(""); Console.WriteLine("TEST01"); Console.WriteLine(" Product Gauss-Legendre rules for the 3D Legendre integral."); Console.WriteLine(" Density function rho(x) = 1."); Console.WriteLine(" Region: -1 <= x <= +1."); Console.WriteLine(" -1 <= y <= +1."); Console.WriteLine(" -1 <= z <= +1."); Console.WriteLine(" Level: L"); Console.WriteLine(" Exactness: 2*L+1"); Console.WriteLine(" Order: N = (L+1)*(L+1)*(L+1)"); for (l = 0; l <= 5; l++) { int nx = l + 1; int ny = l + 1; int nz = l + 1; int n = nx * ny * nz; int t = 2 * l + 1; double[] x = new double[n]; double[] y = new double[n]; double[] z = new double[n]; double[] w = new double[n]; legendre_3d_set(a, b, nx, ny, nz, ref x, ref y, ref z, ref w); int p_max = t + 1; Exactness.legendre_3d_exactness(a, b, n, x, y, z, w, p_max); } }
private Vector3 Snap(ABPath path, Exactness mode, bool start, out bool forceAddPoint) { Vector3 originalEndPoint; GraphNode node2; int num = !start ? (path.path.Count - 1) : 0; GraphNode hint = path.path[num]; Vector3 position = (Vector3)hint.position; forceAddPoint = false; switch (mode) { case Exactness.SnapToNode: return(position); case Exactness.Original: case Exactness.Interpolate: case Exactness.NodeConnection: if (!start) { originalEndPoint = path.originalEndPoint; break; } originalEndPoint = (this.adjustStartPoint == null) ? path.originalStartPoint : this.adjustStartPoint(); break; case Exactness.ClosestOnNode: return(this.GetClampedPoint(position, !start ? path.endPoint : path.startPoint, hint)); default: throw new ArgumentException("Invalid mode"); } switch (mode) { case Exactness.Original: return(this.GetClampedPoint(position, originalEndPoint, hint)); case Exactness.Interpolate: { Vector3 point = this.GetClampedPoint(position, originalEndPoint, hint); node2 = path.path[Mathf.Clamp(num + (!start ? -1 : 1), 0, path.path.Count - 1)]; return(VectorMath.ClosestPointOnSegment(position, (Vector3)node2.position, point)); } case Exactness.NodeConnection: { if (this.connectionBuffer == null) { } this.connectionBuffer = new List <GraphNode>(); if (this.connectionBufferAddDelegate == null) { } this.connectionBufferAddDelegate = new GraphNodeDelegate(this.connectionBuffer.Add); node2 = path.path[Mathf.Clamp(num + (!start ? -1 : 1), 0, path.path.Count - 1)]; hint.GetConnections(this.connectionBufferAddDelegate); Vector3 vector4 = position; float positiveInfinity = float.PositiveInfinity; for (int i = this.connectionBuffer.Count - 1; i >= 0; i--) { GraphNode node3 = this.connectionBuffer[i]; Vector3 vector5 = VectorMath.ClosestPointOnSegment(position, (Vector3)node3.position, originalEndPoint); Vector3 vector6 = vector5 - originalEndPoint; float sqrMagnitude = vector6.sqrMagnitude; if (sqrMagnitude < positiveInfinity) { vector4 = vector5; positiveInfinity = sqrMagnitude; forceAddPoint = node3 != node2; } } this.connectionBuffer.Clear(); return(vector4); } } throw new ArgumentException("Cannot reach this point, but the compiler is not smart enough to realize that."); }