...

Source file src/gonum.org/v1/plot/plotter/polygon_test.go

Documentation: gonum.org/v1/plot/plotter

     1  // Copyright ©2016 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package plotter_test
     6  
     7  import (
     8  	"image/color"
     9  	"testing"
    10  
    11  	"gonum.org/v1/plot"
    12  	"gonum.org/v1/plot/cmpimg"
    13  	"gonum.org/v1/plot/plotter"
    14  	"gonum.org/v1/plot/vg"
    15  	"gonum.org/v1/plot/vg/draw"
    16  	"gonum.org/v1/plot/vg/recorder"
    17  )
    18  
    19  func TestPolygon_holes(t *testing.T) {
    20  	cmpimg.CheckPlot(ExamplePolygon_holes, t, "polygon_holes.png", "polygon_holes.svg", "polygon_holes.pdf", "polygon_holes.eps")
    21  }
    22  
    23  func TestPolygon_hexagons(t *testing.T) {
    24  	cmpimg.CheckPlot(ExamplePolygon_hexagons, t, "polygon_hexagons.png")
    25  }
    26  
    27  // This test ensures that the plotter doesn't panic if there are
    28  // polygons wholly outside of the plotting range.
    29  func TestPolygon_clip(t *testing.T) {
    30  	poly, err := plotter.NewPolygon(
    31  		plotter.XYs{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}},
    32  	)
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  	poly.Color = color.Black // Give the polygon a color to fill.
    37  	p := plot.New()
    38  	// Set the plotting range so that the polygon is outside of it.
    39  	p.X.Min = 2
    40  	p.X.Max = 5
    41  
    42  	p.Add(poly)
    43  	c := new(recorder.Canvas)
    44  	dc := draw.NewCanvas(c, vg.Centimeter, vg.Centimeter)
    45  	p.Draw(dc) // If this does not panic, then the test passes.
    46  }
    47  

View as plain text