-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmarshal_test.go
More file actions
69 lines (49 loc) · 5.63 KB
/
marshal_test.go
File metadata and controls
69 lines (49 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package graphics2d_test
import (
"encoding/json"
"encoding/xml"
"fmt"
g2d "github.com/jphsd/graphics2d"
)
func ExampleShape_MarshalText() {
s := g2d.NewShape(g2d.Circle([]float64{200, 200}, 100))
b, _ := s.MarshalText()
fmt.Println(string(b))
// Output:
// S P 300.000000,200.000000 3 300.000000,226.521649 289.464316,251.957040 270.710678,270.710678 3 251.957040,289.464316 226.521649,300.000000 200.000000,300.000000 3 173.478351,300.000000 148.042960,289.464316 129.289322,270.710678 3 110.535684,251.957040 100.000000,226.521649 100.000000,200.000000 3 100.000000,173.478351 110.535684,148.042960 129.289322,129.289322 3 148.042960,110.535684 173.478351,100.000000 200.000000,100.000000 3 226.521649,100.000000 251.957040,110.535684 270.710678,129.289322 3 289.464316,148.042960 300.000000,173.478351 300.000000,200.000000 C
}
func ExamplePath_MarshalText() {
p := g2d.Circle([]float64{200, 200}, 100)
b, _ := p.MarshalText()
fmt.Println(string(b))
// Output:
// P 300.000000,200.000000 3 300.000000,226.521649 289.464316,251.957040 270.710678,270.710678 3 251.957040,289.464316 226.521649,300.000000 200.000000,300.000000 3 173.478351,300.000000 148.042960,289.464316 129.289322,270.710678 3 110.535684,251.957040 100.000000,226.521649 100.000000,200.000000 3 100.000000,173.478351 110.535684,148.042960 129.289322,129.289322 3 148.042960,110.535684 173.478351,100.000000 200.000000,100.000000 3 226.521649,100.000000 251.957040,110.535684 270.710678,129.289322 3 289.464316,148.042960 300.000000,173.478351 300.000000,200.000000 C
}
func ExampleShape_MarshalJSON() {
s := g2d.NewShape(g2d.Circle([]float64{200, 200}, 100))
b, _ := json.Marshal(s)
fmt.Println(string(b))
// Output:
// {"Paths":[{"Steps":[[[300,200]],[[300,226.52164898395438],[289.4643159634582,251.95704027385128],[270.71067811865476,270.71067811865476]],[[251.9570402738513,289.4643159634582],[226.5216489839544,300],[200,300]],[[173.47835101604562,300],[148.04295972614872,289.4643159634582],[129.28932188134524,270.71067811865476]],[[110.5356840365418,251.9570402738513],[100.00000000000001,226.5216489839544],[100,200]],[[100.00000000000001,173.47835101604562],[110.5356840365418,148.04295972614872],[129.28932188134524,129.28932188134524]],[[148.04295972614867,110.53568403654182],[173.47835101604554,100.00000000000003],[199.99999999999994,100]],[[226.5216489839544,100.00000000000001],[251.9570402738513,110.53568403654181],[270.71067811865476,129.28932188134527]],[[289.46431596345815,148.04295972614867],[300,173.47835101604554],[300,199.99999999999994]]],"Closed":true}]}
}
func ExamplePath_MarshalJSON() {
p := g2d.Circle([]float64{200, 200}, 100)
b, _ := json.Marshal(p)
fmt.Println(string(b))
// Output:
// {"Steps":[[[300,200]],[[300,226.52164898395438],[289.4643159634582,251.95704027385128],[270.71067811865476,270.71067811865476]],[[251.9570402738513,289.4643159634582],[226.5216489839544,300],[200,300]],[[173.47835101604562,300],[148.04295972614872,289.4643159634582],[129.28932188134524,270.71067811865476]],[[110.5356840365418,251.9570402738513],[100.00000000000001,226.5216489839544],[100,200]],[[100.00000000000001,173.47835101604562],[110.5356840365418,148.04295972614872],[129.28932188134524,129.28932188134524]],[[148.04295972614867,110.53568403654182],[173.47835101604554,100.00000000000003],[199.99999999999994,100]],[[226.5216489839544,100.00000000000001],[251.9570402738513,110.53568403654181],[270.71067811865476,129.28932188134527]],[[289.46431596345815,148.04295972614867],[300,173.47835101604554],[300,199.99999999999994]]],"Closed":true}
}
func ExampleShape_MarshalXML() {
s := g2d.NewShape(g2d.Circle([]float64{200, 200}, 100))
b, _ := xml.Marshal(s)
fmt.Println(string(b))
// Output:
// <g><path d="M 300.00 200.00 L 299.51 209.88 298.06 219.60 295.68 229.08 292.39 238.27 288.22 247.09 283.20 255.48 277.35 263.38 270.71 270.71 263.38 277.35 255.48 283.20 247.09 288.22 238.27 292.39 229.08 295.68 219.60 298.06 209.88 299.51 200.00 300.00 190.12 299.51 180.40 298.06 170.92 295.68 161.73 292.39 152.91 288.22 144.52 283.20 136.62 277.35 129.29 270.71 122.65 263.38 116.80 255.48 111.78 247.09 107.61 238.27 104.32 229.08 101.94 219.60 100.49 209.88 100.00 200.00 100.49 190.12 101.94 180.40 104.32 170.92 107.61 161.73 111.78 152.91 116.80 144.52 122.65 136.62 129.29 129.29 136.62 122.65 144.52 116.80 152.91 111.78 161.73 107.61 170.92 104.32 180.40 101.94 190.12 100.49 200.00 100.00 209.88 100.49 219.60 101.94 229.08 104.32 238.27 107.61 247.09 111.78 255.48 116.80 263.38 122.65 270.71 129.29 277.35 136.62 283.20 144.52 288.22 152.91 292.39 161.73 295.68 170.92 298.06 180.40 299.51 190.12 300.00 200.00 z"></path></g>
}
func ExamplePath_MarshalXML() {
p := g2d.Circle([]float64{200, 200}, 100)
b, _ := xml.Marshal(p)
fmt.Println(string(b))
// Output:
// <path d="M 300.00 200.00 L 299.51 209.88 298.06 219.60 295.68 229.08 292.39 238.27 288.22 247.09 283.20 255.48 277.35 263.38 270.71 270.71 263.38 277.35 255.48 283.20 247.09 288.22 238.27 292.39 229.08 295.68 219.60 298.06 209.88 299.51 200.00 300.00 190.12 299.51 180.40 298.06 170.92 295.68 161.73 292.39 152.91 288.22 144.52 283.20 136.62 277.35 129.29 270.71 122.65 263.38 116.80 255.48 111.78 247.09 107.61 238.27 104.32 229.08 101.94 219.60 100.49 209.88 100.00 200.00 100.49 190.12 101.94 180.40 104.32 170.92 107.61 161.73 111.78 152.91 116.80 144.52 122.65 136.62 129.29 129.29 136.62 122.65 144.52 116.80 152.91 111.78 161.73 107.61 170.92 104.32 180.40 101.94 190.12 100.49 200.00 100.00 209.88 100.49 219.60 101.94 229.08 104.32 238.27 107.61 247.09 111.78 255.48 116.80 263.38 122.65 270.71 129.29 277.35 136.62 283.20 144.52 288.22 152.91 292.39 161.73 295.68 170.92 298.06 180.40 299.51 190.12 300.00 200.00 z"></path>
}