public void ChangeTransform() { TestShape s = new TestShape(); s.Transform = new Translate(2, 3, 4).GetTransform(); Assert.AreEqual(s.Transform, new Translate(2, 3, 4).GetTransform()); }
public void NormalOnTranslatedShape() { var s = new TestShape(Translation(0f, 1f, 0f)); var n = s.Normal(Point(0f, 1.70711f, -.70711f)); Assert.That.VectorsAreEqual(n, Direction(0f, .70711f, -.70711f)); }
public void Material() { TestShape s = new TestShape(); Material m = s.Material; Assert.AreEqual(m, new Material()); }
void SetRandomBrushes(TestShape s, Random r) { int i = r.Next(0, 10); if (_strokeBrushes[i] == null) { Color color = Color.FromRgb((byte)r.Next(0, 255), (byte)r.Next(0, 255), (byte)r.Next(0, 255)); HlsColor hls = new HlsColor(color); Color c1 = hls.Darker(0.25f); Color c2 = hls.Lighter(0.25f); Brush fill = new LinearGradientBrush(Color.FromArgb(0x80, c1.R, c1.G, c1.B), Color.FromArgb(0x80, color.R, color.G, color.B), 45); Brush stroke = new LinearGradientBrush(Color.FromArgb(0x80, color.R, color.G, color.B), Color.FromArgb(0x80, c2.R, c2.G, c2.B), 45); _colorNames[i] = "#" + color.R.ToString("X2", CultureInfo.InvariantCulture) + color.G.ToString("X2", CultureInfo.InvariantCulture) + color.B.ToString("X2", CultureInfo.InvariantCulture); _strokeBrushes[i] = stroke; _fillBrushes[i] = fill; } s.Label = _colorNames[i]; s.Stroke = _strokeBrushes[i]; s.Fill = _fillBrushes[i]; }
private void AllocateNodes() { zoom.Zoom = 1; zoom.Offset = new Point(0, 0); // Fill a sparse grid of rectangular color palette nodes with each tile being 50x30. // with hue across x-axis and saturation on y-axis, brightness is fixed at 100; Random r = new Random(Environment.TickCount); grid.VirtualChildren.Clear(); double w = _tileWidth + _tileMargin; double h = _tileHeight + _tileMargin; int count = (rows * cols) / 20; double width = (w * (cols - 1)); double height = (h * (rows - 1)); while (count > 0) { double x = r.NextDouble() * width; double y = r.NextDouble() * height; Point pos = new Point(_tileMargin + x, _tileMargin + y); Size s = new Size(r.Next((int)_tileWidth, (int)_tileWidth * 5), r.Next((int)_tileHeight, (int)_tileHeight * 5)); TestShapeType type = (TestShapeType)r.Next(0, (int)TestShapeType.Last); //Color color = HlsColor.ColorFromHLS((x * 240) / cols, 100, 240 - ((y * 240) / rows)); TestShape shape = new TestShape(new Rect(pos, s), type, r); SetRandomBrushes(shape, r); grid.AddVirtualChild(shape); count--; } }
public void RenderedGeometry () { TestShape e = new TestShape (); Geometry g = e.RenderedGeometry; StreamGeometry stream_geometry = (StreamGeometry)g; Assert.AreEqual (stream_geometry.ToString (), ""); }
public void TestHasBoundingBox() { var s = new TestShape(); var b = s.BoundingBox; Assert.AreEqual(b, Bounds.DefaultBox); }
public void IsAShape() { TestShape ts = new TestShape(); Sphere sp = new Sphere(); Assert.IsTrue(ts.IsAShape()); Assert.IsTrue(sp.IsAShape()); }
public void RenderedGeometry() { TestShape e = new TestShape(); Geometry g = e.RenderedGeometry; StreamGeometry stream_geometry = (StreamGeometry)g; Assert.AreEqual(stream_geometry.ToString(), ""); }
public void NormalOnTransformedShape() { var s = new TestShape(Scale(1f, .5f, 1f) * RotationZ(MathF.PI / 5f)); var val = MathF.Sqrt(2f) / 2f; var n = s.Normal(Point(0f, val, -val)); Assert.That.VectorsAreEqual(n, Direction(0f, .97014f, -.24254f)); }
public void NormalTranslated() { TestShape s = new TestShape(); s.Transform = new Translate(0, 1, 0).GetTransform(); Tuple n = s.NormalAt(Tuple.Point(0, 1.70711, -0.70711), new Intersection(0, s)); Assert.AreEqual(n, Tuple.Vector(0, 0.70711, -0.70711)); }
public void ChangeMaterial() { TestShape s = new TestShape(); Material m = new Material(); m.Ambient = 1; s.Material = m; Assert.AreEqual(s.Material, m); }
public void AssigningATransformation() { var shape = new TestShape { Transform = Transform.Translation(2, 3, 4) }; Assert.AreEqual(Transform.Translation(2, 3, 4), shape.Transform); }
public void AddChild() { var g = new Group(); var t = new TestShape(); g.AddChild(t); Assert.AreEqual(g.Count, 1); Assert.IsTrue(g.Contains(t)); Assert.AreEqual(t.Parent, g); }
public void ComputingTheNormalOnATranslatedShape() { var shape = new TestShape { Transform = Transform.Translation(0, 1, 0) }; var n = shape.NormalAt(new Point(0, 1.70711, -0.70711), null); Assert.AreEqual(new Vector(0, 0.70711, -0.70711), n); }
public void AddChildrenToGroup() { Group g = new Group(); Shape s = new TestShape(); g.AddShape(s); Assert.AreNotEqual(g.Shapes.Count, 0); Assert.IsTrue(g.Shapes.Contains(s)); Assert.AreEqual(s.Parent, g); }
public void IntersectScaledShape() { var r = new Ray(Point(0f, 0f, -5f), Direction(0f, 0f, 1f)); var s = new TestShape(Scale(2f, 2f, 2f)); var xs = new List <Intersection>(); s.Intersect(ref r, ref xs); Assert.AreEqual(s.SavedRay.GetValueOrDefault().Origin, Point(0f, 0f, -2.5f)); Assert.AreEqual(s.SavedRay.GetValueOrDefault().Direction, Direction(0f, 0f, .5f)); }
public void NormalTransformed() { TestShape s = new TestShape(); Matrix m = new Scale(1, 0.5, 1).GetTransform() * new RotateZ(Math.PI / 5).GetTransform(); s.Transform = m; Tuple n = s.NormalAt(Tuple.Point(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2), new Intersection(0, s)); Assert.AreEqual(n, Tuple.Vector(0, 0.97014, -0.24254)); }
public void IntersectTranslatedShape() { var r = new Ray(Point(0f, 0f, -5f), Direction(0f, 0f, 1f)); var s = new TestShape(Translation(5f, 0f, 0f)); var xs = new List <Intersection>(); s.Intersect(ref r, ref xs); Assert.AreEqual(xs.Count, 0); Assert.AreEqual(s.SavedRay.GetValueOrDefault().Origin, Point(-5f, 0f, -5f)); Assert.AreEqual(s.SavedRay.GetValueOrDefault().Direction, Direction(0f, 0f, 1f)); }
public void ComputingTheNormalOnATransformedShape() { var matrix = Transform.Scaling(1, 0.5, 1) * Transform.RotationZ(Math.PI / 5); var shape = new TestShape { Transform = matrix }; var n = shape.NormalAt(new Point(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2), null); Assert.AreEqual(new Vector(0, 0.97014, -0.24254), n); }
public void TranslatedShapeIntersectRay() { Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); TestShape s = new TestShape(); s.Transform = new Translate(5, 0, 0).GetTransform(); List <Intersection> xs = s.Intersect(r); Assert.AreEqual(s.savedRay.Origin, Tuple.Point(-5, 0, -5)); Assert.AreEqual(s.savedRay.Direction, Tuple.Vector(0, 0, 1)); }
public void IntersectingATranslatedShapeWithARay() { var ray = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1)); var shape = new TestShape { Transform = Transform.Translation(5, 0, 0) }; var xs = shape.Intersects(ray); Assert.AreEqual(new Point(-5, 0, -5), shape.SavedRay.Origin); Assert.AreEqual(new Vector(0, 0, 1), shape.SavedRay.Direction); }
public void IntersectingAScaledShapedWithARay() { var ray = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1)); var shape = new TestShape { Transform = Transform.Scaling(2, 2, 2) }; var xs = shape.Intersects(ray); Assert.AreEqual(new Point(0, 0, -2.5), shape.SavedRay.Origin); Assert.AreEqual(new Vector(0, 0, 0.5), shape.SavedRay.Direction); }
public void AssignMaterial() { var m = PhongMaterial.Default; m.Ambient = 1f; var s = new TestShape { Material = m }; Assert.AreEqual(s.Material.Ambient, 1f); }
public void AssigningAMaterial() { var m = new Material { Ambient = 1 }; var s = new TestShape { Material = m }; Assert.AreEqual(m, s.Material); }
public void IntersectDoesNotTestChildIfMissed() { var c = new TestShape(); var s = new Group(); s.AddChild(c); var r = new Ray(0, 0, -5, 0, 1, 0); var xs = new List <Intersection>(); s.Intersect(ref r, ref xs); Assert.AreNotEqual(c.SavedRay, r); Assert.IsNull(c.SavedRay); }
public void SavedRayIsSetIfHit() { var c = new TestShape(); var s = new Group(); s.AddChild(c); var r = new Ray(0, 0, -5, 0, 0, 1); var xs = new List <Intersection>(); s.Intersect(ref r, ref xs); Assert.IsNotNull(c.SavedRay); Assert.AreEqual(c.SavedRay, r); }
public void CanCreatePainterAndDrawShapes() { var painter = new Painter(); var canvas = new Canvas(); var draft = new PictureDraft(); var shape1 = new TestShape(); var shape2 = new TestShape(); draft.AddShape(shape1); draft.AddShape(shape2); painter.DrawPicture(draft, canvas); Assert.IsTrue(shape1.IsActivated); Assert.IsTrue(shape2.IsActivated); }
public static List <IntVector3.IndexedIntVector3> GetPoints(IntVector3 size, TestShape testShape) { var result = new List <IntVector3.IndexedIntVector3>(); var center = size / 2; foreach (var iv in size.IteratorXYZ) { var dif = iv.v - center; switch (testShape) { case TestShape.Cube: default: result.Add(iv); break; case TestShape.Sphere: if (dif.SquareMagnitude < center.SquareMagnitude / 4) { result.Add(iv); } break; case TestShape.Ramp: if (iv.v.x + iv.v.y < size.x) { result.Add(iv); } break; case TestShape.InvertedRamp: if (iv.v.x + iv.v.y > size.x) { result.Add(iv); } break; } } return(result); }
public void TheDefaultMaterial() { var s = new TestShape(); Assert.AreEqual(new Material(), s.Material); }
public void GeometryTransform () { TestShape e = new TestShape (); Assert.AreSame (e.GeometryTransform, Transform.Identity); }
public void GeometryTransform() { TestShape e = new TestShape(); Assert.AreSame(e.GeometryTransform, Transform.Identity); }