github.com/unidoc/unidoc@v2.2.0+incompatible/pdf/creator/curve_test.go (about) 1 /* 2 * This file is subject to the terms and conditions defined in 3 * file 'LICENSE.md', which is part of this source code package. 4 */ 5 6 package creator 7 8 import "testing" 9 10 func TestNewCurve(t *testing.T) { 11 creator := New() 12 creator.NewPage() 13 curve := NewCurve(20, 20, 15, 35, 40, 150) 14 curve.SetWidth(3.0) 15 curve.SetColor(ColorGreen) 16 err := creator.Draw(curve) 17 if err != nil { 18 t.Errorf("Fail: %v", err) 19 return 20 } 21 22 err = creator.WriteToFile("/tmp/curve.pdf") 23 if err != nil { 24 t.Errorf("Fail: %v", err) 25 return 26 } 27 } 28 29 func CreateCurve(x1, y1, cx, cy, x2, y2 float64, color Color) *Curve { 30 curve := NewCurve(x1, y1, cx, cy, x2, y2) 31 curve.SetWidth(1) 32 curve.SetColor(color) 33 return curve 34 } 35 36 func CreateLine(x1, y1, x2, y2, width float64) *Line { 37 line := NewLine(x1, y1, x2, y2) 38 line.SetLineWidth(width) 39 line.SetColor(ColorRed) 40 return line 41 } 42 43 func TestNewCurveWithGlass(t *testing.T) { 44 creator := New() 45 creator.NewPage() 46 47 // Width 200 48 creator.Draw(CreateLine(30, 200, 270, 200, 1)) 49 50 // Curve up 51 creator.Draw(CreateCurve(50, 200, 75, 145, 150, 150, ColorRed)) 52 creator.Draw(CreateCurve(150, 150, 205, 145, 250, 200, ColorGreen)) 53 54 // Curve down 55 creator.Draw(CreateCurve(50, 200, 75, 245, 150, 250, ColorBlue)) 56 creator.Draw(CreateCurve(150, 250, 225, 245, 250, 200, ColorBlack)) 57 58 // Vertical line 59 creator.Draw(CreateLine(50, 200, 51, 400, 1)) 60 creator.Draw(CreateLine(250, 200, 251, 400, 1)) 61 62 // Curve down 63 creator.Draw(CreateCurve(51, 399, 75, 445, 150, 450, ColorRed)) 64 creator.Draw(CreateCurve(150, 450, 225, 445, 251, 399, ColorGreen)) 65 66 err := creator.WriteToFile("/tmp/curve_glass.pdf") 67 if err != nil { 68 t.Errorf("Fail: %v", err) 69 return 70 } 71 }