using Annulus; using Azimuth; using Blacklight.Core; using static Glass.Blacklight.UnitTests.PictureTests; namespace Glass.Blacklight.UnitTests { public class PictureMaterialTests : UnitTestSharp.TestFixture { public static Census Rendered(PictureMaterial material, Rect rect) { var cel = new Cel(); PictureMaterial.Render(null, cel, material, rect, new DrawState()); return Count(cel); } public static Picture RingAndCurve() { return new Picture(aspect: 1) .AddCircle(Vector.Zero, 0.8, Prism.Colors.Black, 2) .AddCurve(new Vector(-0.65, 0), new Vector(0, -1.3), new Vector(0, 1.3), new Vector(0.65, 0), Prism.Colors.Black, 2); } public class NaturalSizeTests : UnitTestSharp.TestFixture { public void WhenSet_IsThePreferredSize() { var material = new PictureMaterial { NaturalSize = new Vector(16, 12) }; CheckEqual(new Vector(16, 12), material.PreferredSize(Constraints.Unbounded)); } public void WhenSet_IsHeldToTheConstraints() { var material = new PictureMaterial { NaturalSize = new Vector(16, 12) }; CheckEqual(new Vector(10, 12), material.PreferredSize(Constraints.Loose(new Vector(10, 100)))); } public void WhenNotSet_AsksForNothing() { CheckEqual(Vector.Zero, new PictureMaterial().PreferredSize(Constraints.Unbounded)); } } public class RenderTests : UnitTestSharp.TestFixture { public void DrawsThePictureInTheRect() { var material = new PictureMaterial { Picture = RingAndCurve() }; Census census = Rendered(material, At(0, 0, 73, 73)); CheckEqual(1, census.Ellipses); CheckEqual(12, census.LineSegments); CheckEqual(new Vector(37, 37), census.EllipseCenters[0]); } public void DrawsNothingWithoutAPicture() { Census census = Rendered(new PictureMaterial(), At(0, 0, 73, 73)); CheckEqual(0, census.Ellipses + census.LineSegments + census.Polygons); } public void DrawsNothingInAnEmptyRect() { var material = new PictureMaterial { Picture = RingAndCurve() }; Census census = Rendered(material, At(5, 5, 0, 73)); CheckEqual(0, census.Ellipses + census.LineSegments + census.Polygons); } } } }