public void SizeF() { RectangularPolygon shape = new RectangularPolygon(10, 11, 12, 13); Assert.Equal(12, shape.Size.Width); Assert.Equal(13, shape.Size.Height); }
static void Main(string[] args) { using var module = PiTop4Board.Instance; var display = module.Display; Console.WriteLine("press enter key to render square"); Console.ReadLine(); display.Draw((d, cr) => { var square = new RectangularPolygon(0, 0, cr.Width / 2, cr.Height / 2); d.Fill(Color.White, square); }); Console.WriteLine("press enter key to render text"); Console.ReadLine(); var font = SystemFonts.Collection.Find("Roboto").CreateFont(10); module.Display.Draw((context, cr) => { context.Clear(Color.Black); var rect = TextMeasurer.Measure("Diego was here", new RendererOptions(font)); var x = (cr.Width - rect.Width) / 2; var y = (cr.Height + (rect.Height)) / 2; context.DrawText("Hello\nWorld", font, Color.White, new PointF(0, 0)); }); Console.WriteLine("press enter key to exit"); Console.ReadLine(); }
public void Intersections_0() { IPath shape = new RectangularPolygon(1, 1, 10, 10); IEnumerable <PointF> intersections = shape.FindIntersections(new PointF(0, 5), new PointF(-5, 5)); Assert.Equal(0, intersections.Count()); }
public void TransformIdnetityReturnsSahpeObject() { IPath shape = new RectangularPolygon(0, 0, 200, 60); IPath transformdShape = shape.Transform(Matrix3x2.Identity); Assert.Same(shape, transformdShape); }
public void BlendFillColorOverBackground <TPixel>( TestImageProvider <TPixel> provider, bool triggerFillRegion, string newColorName, float alpha, PixelColorBlendingMode blenderMode, float blendPercentage) where TPixel : unmanaged, IPixel <TPixel> { Color fillColor = TestUtils.GetColorByName(newColorName).WithAlpha(alpha); using (Image <TPixel> image = provider.GetImage()) { TPixel bgColor = image[0, 0]; var options = new DrawingOptions { GraphicsOptions = new GraphicsOptions { Antialias = false, ColorBlendingMode = blenderMode, BlendPercentage = blendPercentage } }; if (triggerFillRegion) { var path = new RectangularPolygon(0, 0, 16, 16); image.Mutate(c => c.SetGraphicsOptions(options.GraphicsOptions).Fill(new SolidBrush(fillColor), path)); } else { image.Mutate(c => c.Fill(options, new SolidBrush(fillColor))); } var testOutputDetails = new { triggerFillRegion, newColorName, alpha, blenderMode, blendPercentage }; image.DebugSave( provider, testOutputDetails, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); PixelBlender <TPixel> blender = PixelOperations <TPixel> .Instance.GetPixelBlender( blenderMode, PixelAlphaCompositionMode.SrcOver); TPixel expectedPixel = blender.Blend(bgColor, fillColor.ToPixel <TPixel>(), blendPercentage); image.ComparePixelBufferTo(expectedPixel); } }
private static void OutputClippedRectangle() { var rect1 = new RectangularPolygon(10, 10, 40, 40); var rect2 = new RectangularPolygon(20, 0, 20, 20); var paths = rect1.Clip(rect2); paths.SaveImage("Clipping", "RectangleWithTopClipped.png"); }
public void DistanceFromPath_Path(TestPoint point, float expectecDistance, float alongPath) { IPath shape = new RectangularPolygon(0, 0, 10, 10).AsPath(); PointInfo info = shape.Distance(point); Assert.Equal(expectecDistance, info.DistanceFromPath); Assert.Equal(alongPath, info.DistanceAlongPath); }
public void Fill_RectangularPolygon_Solid_TransformedUsingConfiguration <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { var polygon = new RectangularPolygon(25, 25, 50, 50); provider.Configuration.SetDrawingTransform(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))); provider.RunValidatingProcessorTest(c => c.Fill(Color.White, polygon)); }
public void Intersections_1() { IPath shape = new RectangularPolygon(1, 1, 10, 10); IEnumerable <PointF> intersections = shape.FindIntersections(new PointF(0, 5), new PointF(5, 5)); Assert.Single(intersections); Assert.Equal(new PointF(1, 5), intersections.First()); }
public void ClippingRectanglesCreateCorrectNumberOfPoints() { IEnumerable <ISimplePath> paths = new RectangularPolygon(10, 10, 40, 40).Clip(new RectangularPolygon(20, 0, 20, 20)).Flatten(); Assert.Single(paths); IReadOnlyList <PointF> points = paths.First().Points.ToArray(); Assert.Equal(8, points.Count); }
public void DrawRectangularPolygon_Transformed <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { var polygon = new RectangularPolygon(25, 25, 50, 50); provider.RunValidatingProcessorTest( c => c.SetDrawingTransform(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))) .Draw(Color.White, 2.5f, polygon)); }
public void ClippingEdgefromInside() { IPath simplePath = new RectangularPolygon(10, 10, 100, 100).Clip(new RectangularPolygon(20, 0, 20, 20)); IEnumerable <PointF> intersections = simplePath.FindIntersections(new PointF(float.MinValue, 20), new PointF(float.MaxValue, 20)); // returns an even number of points Assert.Equal(4, intersections.Count()); }
public void Bounds_Path() { IPath shape = new RectangularPolygon(10, 11, 12, 13).AsPath(); Assert.Equal(10, shape.Bounds.Left); Assert.Equal(22, shape.Bounds.Right); Assert.Equal(11, shape.Bounds.Top); Assert.Equal(24, shape.Bounds.Bottom); }
public void ClippingRectanglesCreateCorrectNumberOfPoints() { IEnumerable <ISimplePath> paths = new RectangularPolygon(10, 10, 40, 40).Clip(new RectangularPolygon(20, 0, 20, 20)).Flatten(); Assert.Equal(1, paths.Count()); var points = paths.First().Points; Assert.Equal(8, points.Count); }
public void Transform() { IPath shape = new RectangularPolygon(0, 0, 200, 60); IPath newShape = shape.Transform(new Matrix3x2(0, 1, 1, 0, 20, 2)); Assert.Equal(new PointF(20, 2), newShape.Bounds.Location); Assert.Equal(new SizeF(60, 200), newShape.Bounds.Size); }
[InlineData(620, 150, 50, Pi)] // wrap about end of path public void PointOnPath(float distance, float expectedX, float expectedY, float expectedAngle) { IPath shape = new RectangularPolygon(50, 50, 200, 60); var point = shape.PointAlongPath(distance); Assert.Equal(expectedX, point.Point.X); Assert.Equal(expectedY, point.Point.Y); Assert.Equal(expectedAngle, point.Angle); }
public override Image Render(string mode = "human") { float b, t, r, l; const int screen_width = 600; const int screen_height = 400; const float world_width = x_threshold * 2; const float scale = screen_width / world_width; const int carty = 300; const float polewidth = 10.0f; const float poleheight = scale * (2 * length); const float cartwidth = 50.0f; const float cartheight = 30.0f; if (_viewer == null) { lock (this) { //to prevent double initalization. if (_viewer == null) { if (_viewerFactory == null) { _viewerFactory = NullEnvViewer.Factory; } _viewer = _viewerFactory(screen_width, screen_height, "cartpole-v1"); } } } //pole l = -polewidth / 2; r = polewidth / 2; t = poleheight - polewidth / 2; b = -polewidth / 2; var pole = new RectangularPolygon(-polewidth / 2, carty - poleheight, polewidth, poleheight); var circle = new EllipsePolygon(0, carty - polewidth / 2, polewidth / 2); //cart l = -cartwidth / 2; r = cartwidth / 2; t = cartheight / 2; b = -cartheight / 2; var axleoffset = cartheight / 4.0; var cart = new RectangularPolygon(-cartwidth / 2, carty - cartheight / 2, cartwidth, cartheight); var draw = new List <(IPath, Rgba32)>(); if (!(state is null)) { var center_x = (float)(state.GetDouble(0) * scale + screen_width / 2.0f); //no y cuz it doesnt change. var cbounds = circle.Bounds; var pivotPoint = new PointF(cbounds.X + cbounds.Width / 2f, cbounds.Y + cbounds.Height / 2f); draw.Add((cart.Translate(center_x, 0), Rgba32.Black)); draw.Add((pole.Transform(Matrix3x2.CreateRotation((float)state.GetDouble(2), pivotPoint)).Translate(center_x, 0), new Rgba32(204, 153, 102))); draw.Add((circle.Translate(center_x, 0), Rgba32.Teal)); }
public void LienearSegements() { IPath shape = new RectangularPolygon(10, 11, 12, 13).AsPath(); var segemnts = shape.Flatten().ToArray()[0].Points; Assert.Equal(new PointF(10, 11), segemnts[0]); Assert.Equal(new PointF(22, 11), segemnts[1]); Assert.Equal(new PointF(22, 24), segemnts[2]); Assert.Equal(new PointF(10, 24), segemnts[3]); }
public void Create_FromRecangle() { var polygon = new RectangularPolygon(10, 20, 100, 50); PointF[] points = polygon.Flatten().Single().Points.Span.ToArray(); using var multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); VerifyRing(multipolygon[0], points, true, false); Assert.Equal(4, multipolygon.TotalVertexCount); }
public void Fill_RectangularPolygon <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { var polygon = new RectangularPolygon(10, 10, 190, 140); var color = Color.White; provider.RunValidatingProcessorTest( c => c.Fill(color, polygon), appendSourceFileOrDescription: false); }
public void DrawProgressBar(int percentage, int width, FontSize fontSize = FontSize.Medium, int borderThickness = 2, int cornerRadius = 16, int padding = 4) { // Clamp percentage to the [0;100] range var percents = percentage < 0 ? 0 : (percentage > 100 ? 100 : percentage); var text = $"{percents}%"; var font = fonts[fontSize]; #if IMAGESHARP_V2 var options = new TextOptions(font); #else var options = new RendererOptions(font); #endif // In order for the text to feel correctly vertically centered, we measure a string with characters // that go below (like g or j) and others that go up (like t or f). We say this should be the text height. var textHeight = TextMeasurer.Measure("gf", options).Height; var textWidth = TextMeasurer.Measure(text, options).Width; var textSizeWithPadding = new SizeF(textWidth + padding, textHeight + padding); var rectangleSize = new SizeF( width >= textSizeWithPadding.Width ? width : textSizeWithPadding.Width, textSizeWithPadding.Height); var color = palette[percents]; var borderRectangle = Align(rectangleSize, HorizontalAlignment.Center, VerticalAlignment.Center, 0); if (cornerRadius <= 0) // No rounded corners { var valueWidth = borderRectangle.Width * (percents / 100f); var valueRectangle = new RectangularPolygon( borderRectangle.Left, borderRectangle.Top, valueWidth, borderRectangle.Height); _ = Context.Fill(color.WithAlpha(0.33f), valueRectangle); _ = Context.Draw(Pens.Solid(color, borderThickness), borderRectangle); } else { var invertedValueWidth = borderRectangle.Width * (1f - percents / 100f); var invertedValueRectangle = new RectangularPolygon( borderRectangle.Right - invertedValueWidth, borderRectangle.Top, invertedValueWidth, borderRectangle.Height); var contour = borderRectangle.ToRoundedRectangle(cornerRadius); var clippedValueRectangle = contour.Clip(invertedValueRectangle); _ = Context.Fill(color.WithAlpha(0.33f), clippedValueRectangle); _ = Context.Draw(Pens.Solid(color, borderThickness), contour); } // Draw the text var alignedText = Align(textWidth, textHeight, HorizontalAlignment.Center, VerticalAlignment.Center, 0); _ = Context.DrawText(text, font, Color.White, new PointF(alignedText.X, alignedText.Y)); }
public RoundedRect(float x, float y, float width, float height, float rx, float ry) { IPath rect = new RectangularPolygon(x, y, width, height); if (rx > 0 && ry > 0) { rect = MakeRounded(rect, rx, ry); } innerPath = rect; }
public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) { var rect = new RectangularPolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); IPath cornerTopLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); float rightPos = imageWidth - cornerTopLeft.Bounds.Width + 1; float bottomPos = imageHeight - cornerTopLeft.Bounds.Height + 1; IPath cornerTopRight = cornerTopLeft.RotateDegree(90).Translate(rightPos, 0); IPath cornerBottomLeft = cornerTopLeft.RotateDegree(-90).Translate(0, bottomPos); IPath cornerBottomRight = cornerTopLeft.RotateDegree(180).Translate(rightPos, bottomPos); return(new PathCollection(cornerTopLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight)); }
public void CorrectlySetsBrushRectangleAndOptions() { this.operations.Fill(this.nonDefault, this.brush, this.rectangle); FillRegionProcessor processor = this.Verify <FillRegionProcessor>(); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType <ShapeRegion>(processor.Region); RectangularPolygon rect = Assert.IsType <RectangularPolygon>(region.Shape); Assert.Equal(rect.Location.X, this.rectangle.X); Assert.Equal(rect.Location.Y, this.rectangle.Y); Assert.Equal(rect.Size.Width, this.rectangle.Width); Assert.Equal(rect.Size.Height, this.rectangle.Height); Assert.Equal(this.brush, processor.Brush); }
public void RectangleFloatAndAntialias() { var imageSize = new Rectangle(0, 0, 500, 500); var floatRect = new RectangleF(10.5f, 10.5f, 400.6f, 400.9f); var expectedRect = new Rectangle(10, 10, 400, 400); var path = new RectangularPolygon(floatRect); var processor = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions() { GraphicsOptions = { Antialias = true } }, Brushes.Solid(Color.Red), path); var pixelProcessor = processor.CreatePixelSpecificProcessor <Rgba32>(null, null, imageSize); Assert.IsType <FillRegionProcessor <Rgba32> >(pixelProcessor); }
public void IntRectangle() { var imageSize = new Rectangle(0, 0, 500, 500); var expectedRect = new Rectangle(10, 10, 400, 400); var path = new RectangularPolygon(expectedRect); var processor = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions() { GraphicsOptions = { Antialias = true } }, Brushes.Solid(Color.Red), path); var pixelProcessor = processor.CreatePixelSpecificProcessor <Rgba32>(null, null, imageSize); var fill = Assert.IsType <FillProcessor <Rgba32> >(pixelProcessor); Assert.Equal(expectedRect, fill.GetProtectedValue <Rectangle>("SourceRectangle")); }
public void Draw(int[] pattern, Color colour) { var(row, column) = PyxcellConvert.GetGridPosition(_gridNumber); for (int i = 0; i < pattern.Length; i++) { if (pattern[i] == 1) { var topLeft = new PointF(column + i, row); var bottomRight = new PointF(topLeft.X + 1, topLeft.Y + Constraints.GridSize); var line = new RectangularPolygon(topLeft, bottomRight); _image.Mutate(x => x.Fill(colour, line)); } } _gridNumber++; }
static void Main(string[] args) { using var module = new PiTopModule(); var display = module.Display; Console.WriteLine("press enter key to render"); Console.ReadLine(); display.Draw(d => { var square = new RectangularPolygon(display.Width / 4, display.Height / 4, display.Width / 2, display.Height / 2); d.Fill(Color.White, square); }); Console.WriteLine("press enter key to exit"); Console.ReadLine(); }
private Image <Rgb24> GetMapImage(Map map) { var blockHeight = GetBlockHeight(map); var blockWidth = GetBlockWidth(map); var maxY = map.FloorPlan.Length; var maxX = map.FloorPlan.First().Length; var width = maxX * blockWidth; var height = maxY * blockHeight; var image = new Image <Rgb24>(width, height); for (var y = 0; y < map.FloorPlan.Length; y++) { for (var x = 0; x < map.FloorPlan[y].Length; x++) { Rgb24 color; var current = map.FloorPlan[y][x]; if (current == Map.OCCPD) { color = NamedColors <Rgb24> .Black; } else if (current == Map.START) { color = NamedColors <Rgb24> .Red; } else if (current == Map.DESTN) { color = NamedColors <Rgb24> .GreenYellow; } else { color = NamedColors <Rgb24> .White; } var tileX = x * blockWidth; var tileY = y * blockHeight; var tile = new RectangularPolygon(tileX, tileY, blockWidth, blockHeight); image.Mutate(c => c.Fill(color, tile)); } } return(image); }
public async Task ShareAppointmentImageAsync(CalendarEvent c) { var assembly = Assembly.GetExecutingAssembly(); var resourceName = "NSchedule.Fonts.font.ttf"; FontFamily font; FontCollection fonts = new FontCollection(); using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { font = fonts.Install(stream); } var Data = DependencyService.Get <DataHelper>(); var att = c.Appointment.Attendees; var rooms = Data.Schedulables.Where(x => x.GetType() == typeof(Room) && att.Contains(x.Id)).Cast <Room>().Select(x => x.Code); var teachers = Data.Schedulables.Where(x => x.GetType() == typeof(Teacher) && att.Contains(x.Id)).Cast <Teacher>().Select(x => x.Code); var groups = Data.Schedulables.Where(x => x.GetType() == typeof(Group) && att.Contains(x.Id)).Cast <Group>().Select(x => x.Code); string yourText = $"{c.Name}\n{c.ScheduleableCode} ({c.Times})\n\n\nRooms:\n{JoinPerTwo(rooms)}\n\nTeachers:\n{JoinPerTwo(teachers)}\n\nGroups:\n{JoinPerTwo(groups)}\n\n{Constants.SHARED_WITH}"; var f = font.CreateFont(25f); var measures = TextMeasurer.Measure(yourText, new RendererOptions(f)); var img = new Image <Rgba32>((int)measures.Width + 50, (int)measures.Height + 50); img.Mutate(x => x.Fill(Color.White)); IPath rect = new RectangularPolygon(15, 15, measures.Width + 20, measures.Height + 20); img.Mutate(x => x.Draw(Color.Gray, 5f, rect)); img.Mutate(x => x.DrawText(yourText, f, Color.Black, new PointF(25f, 25f))); var basePath = System.IO.Path.GetTempPath(); var path = System.IO.Path.Combine(basePath, "share.png"); await img.SaveAsPngAsync(path).ConfigureAwait(false); await Share.RequestAsync(new ShareFileRequest(c.Name, new ShareFile(path))).ConfigureAwait(false); // cleanup after share.. //File.Delete(path); }