public void CloneCubeDescription() { BSP cube = new Cube(); BSP cube2 = cube.Clone(); Assert.IsTrue(cube.Description.Zip(cube2.Description, (a, b) => a.Equals(b)).Aggregate((a, b) => a & b)); BSP sphere = new Sphere(1); Assert.IsFalse(sphere.Description.Zip(cube2.Description, (a, b) => a.Equals(b)).Aggregate((a, b) => a & b)); }
public void TransformBounds() { BSP a = new Cube().Transform(Matrix.CreateTranslation(0.1f, 0, 0)); Assert.IsTrue(a.Bounds.HasValue); float epsilon = 0.00001f; Assert.AreEqual(-0.4f, a.Bounds.Value.Min.X, epsilon); Assert.AreEqual(-0.5f, a.Bounds.Value.Min.Y, epsilon); Assert.AreEqual(-0.5f, a.Bounds.Value.Min.Z, epsilon); Assert.AreEqual(0.6f, a.Bounds.Value.Max.X, epsilon); Assert.AreEqual(0.5f, a.Bounds.Value.Max.Y, epsilon); Assert.AreEqual(0.5f, a.Bounds.Value.Max.Z, epsilon); }
public void CreateCube() { Cube c = new Cube(); Assert.AreEqual(6, c.Polygons.Count()); Assert.AreEqual(24, c.Polygons.SelectMany(p => p.Vertices).GroupBy(a => a).Count()); foreach (var face in c.Polygons) { foreach (var vertex in face.Vertices) { Assert.AreEqual(face.Plane.Normal, vertex.Normal); } } }
public void ConstructBounds() { BSP a = new Cube(); Assert.IsTrue(a.Bounds.HasValue); //Assert.AreEqual(new BoundingBox(new Vector3(-0.5f), new Vector3(0.5f)), a.Bounds.Value); float epsilon = 0.00001f; Assert.AreEqual(-0.5f, a.Bounds.Value.Min.X, epsilon); Assert.AreEqual(-0.5f, a.Bounds.Value.Min.Y, epsilon); Assert.AreEqual(-0.5f, a.Bounds.Value.Min.Z, epsilon); Assert.AreEqual(0.5f, a.Bounds.Value.Max.X, epsilon); Assert.AreEqual(0.5f, a.Bounds.Value.Max.Y, epsilon); Assert.AreEqual(0.5f, a.Bounds.Value.Max.Z, epsilon); }
public void UnionDescription() { Cube cube = new Cube(); Cylinder cyl = new Cylinder(3); var shape = cube.Clone(); shape.Union(cyl); var desc = shape.Description.ToArray(); Assert.AreEqual(4, desc.Length); Assert.AreEqual("union", desc[0]); Assert.AreEqual("cube", desc[1]); Assert.AreEqual("cylinder", desc[2]); Assert.AreEqual((uint)3, desc[3]); }
public void CubeDescription() { Cube c = new Cube(); Assert.AreEqual(1, c.Description.Count()); }
public virtual void Split(out BSP topLeftFront, out BSP topLeftBack, out BSP topRightBack, out BSP topRightFront, out BSP bottomLeftFront, out BSP bottomLeftBack, out BSP bottomRightBack, out BSP bottomRightFront, Func<Vector3, Vector3, Vertex> vertexFactory = null) { if (!Bounds.HasValue) throw new InvalidOperationException("Cannot split a BSP tree without bounds"); vertexFactory = vertexFactory ?? ((p, n) => new Vertex(p, n)); var bounds = Bounds.Value; var size = (bounds.Max - bounds.Min); float halfWidth = size.X / 2; float halfHeight = size.Y / 2; float halfDepth = size.Z / 2; float qtrWidth = halfWidth / 2; float qtrHeight = halfHeight / 2; float qtrDepth = halfDepth / 2; topLeftFront = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(-qtrWidth, qtrHeight, -qtrDepth)); topLeftFront.Intersect(this); topLeftBack = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(-qtrWidth, qtrHeight, qtrDepth)); topLeftBack.Intersect(this); topRightFront = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(qtrWidth, qtrHeight, -qtrDepth)); topRightFront.Intersect(this); topRightBack = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(qtrWidth, qtrHeight, qtrDepth)); topRightBack.Intersect(this); bottomLeftFront = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(-qtrWidth, -qtrHeight, -qtrDepth)); bottomLeftFront.Intersect(this); bottomLeftBack = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(-qtrWidth, -qtrHeight, qtrDepth)); bottomLeftBack.Intersect(this); bottomRightFront = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(qtrWidth, -qtrHeight, -qtrDepth)); bottomRightFront.Intersect(this); bottomRightBack = new Cube(vertexFactory).Transform(Matrix.CreateScale(halfWidth, halfHeight, halfDepth) * Matrix.CreateTranslation(qtrWidth, -qtrHeight, qtrDepth)); bottomRightBack.Intersect(this); }
public void CreateCubeWithFactory() { Cube s = new Cube((a, b) => new VertexTest(a, b)); Assert.IsTrue(s.Polygons.SelectMany(a => a.Vertices).All(a => a is VertexTest)); }