1// Copyright 2015 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cairo
16
17import "unsafe"
18
19// PathSegments are produced by iterating paths.
20type PathSegment struct {
21	Type   PathDataType
22	Points []PathPoint
23}
24
25// PathPoints are produced by iterating paths.
26type PathPoint struct {
27	X, Y float64
28}
29
30// Matches cairo_path_data_t.header.
31type pathDataHeader struct {
32	dataType int32
33	length   int32
34}
35
36// decodePathSegment extracts a series of points out of a cairo_path_data_t array.
37func decodePathSegment(pathData unsafe.Pointer) (*PathSegment, int) {
38	header := (*pathDataHeader)(pathData)
39	seg := PathSegment{
40		Type:   PathDataType(header.dataType),
41		Points: make([]PathPoint, header.length-1),
42	}
43	parts := (*[1 << 30]PathPoint)(pathData)
44	copy(seg.Points, parts[1:])
45	return &seg, int(header.length)
46}
47