public void CheckDivide <V> () where V : struct, IVec <V, float> { (from vec in Prop.ForAll <V> () from scalar in Prop.ForAll <float> () let divided = vec.Divide(scalar) let multiplied = vec.Multiply(1f / scalar) select new { vec, scalar, divided, multiplied }) .Check(p => Vec.ApproxEquals(p.divided, p.multiplied), label: $"{typeof (V).Name}: vec / scalar = vec * (1 / scalar)"); }
public void CheckDivide <V> () where V : struct, IVec <V, float> { var prop = from vec in Prop.Choose <V> () from scalar in Prop.Choose <float> () let divided = vec.Divide(scalar) let multiplied = vec.Multiply(1f / scalar) select new { vec, scalar, divided, multiplied }; prop.Label("{0}: vec / scalar = vec * (1 / scalar)", typeof(V).Name) .Check(p => Vec.ApproxEquals(p.divided, p.multiplied)); }
private IEnumerable <Node> FindNodesWithPosition(Node node, V position) { if (Vec.ApproxEquals(node.Positional.position, position)) { yield return(node); } var child = node.Children [ChooseChild(node, position)]; if (child != null) { foreach (var childNode in FindNodesWithPosition(child, position)) { yield return(childNode); } } }
public static Geometry <V> Stretch <V> (this Geometry <V> frontFace, IEnumerable <Mat4> transforms, bool includeFrontFace, bool includeBackFace) where V : struct, IVertex3D { var vertices = frontFace.Vertices; if (!vertices.AreCoplanar()) { throw new ArgumentException("Geometry is not on completely on the same plane.", "frontFace"); } var firstNormal = vertices[0].normal; if (!vertices.All(v => Vec.ApproxEquals(v.normal, firstNormal))) { throw new ArgumentException("All the normals need to point towards the same direction.", "frontFace"); } var edges = frontFace.GetEdges(BeginMode.Triangles).ToArray(); var outerEdges = DetermineOuterEdges(edges).ToArray(); var geometries = new Geometry <V> [(outerEdges.Length * transforms.Count()) + BoolToInt(includeFrontFace) + BoolToInt(includeBackFace)]; var backFace = frontFace; var i = 0; if (includeFrontFace) { geometries[i++] = frontFace; } foreach (var transform in transforms) { backFace = frontFace.ManipulateVertices(v => v.With(transform.Transform(v.position), -v.normal), false); var backVertices = backFace.Vertices; i = ExtrudeOut(geometries, i, vertices, backVertices, outerEdges); vertices = backVertices; } if (includeBackFace) { geometries[i++] = backFace.ReverseWinding(); } return(Composite.Create(geometries)); }