Dash returns a new path that consists of dashes. The elements in d specify the width of the dashes and gaps. It will alternate between dashes and gaps when picking widths. If d is an array of odd length, it is equivalent of passing d twice in sequence. The offset specifies the offset used into d (or
(offset float64, d ...float64)
| 1854 | |
| 1855 | // Dash returns a new path that consists of dashes. The elements in d specify the width of the dashes and gaps. It will alternate between dashes and gaps when picking widths. If d is an array of odd length, it is equivalent of passing d twice in sequence. The offset specifies the offset used into d (or negative offset into the path). Dash will be applied to each subpath independently. |
| 1856 | func (p *Path) Dash(offset float64, d ...float64) *Path { |
| 1857 | offset, d = dashCanonical(offset, d) |
| 1858 | if len(d) == 0 { |
| 1859 | return p |
| 1860 | } else if len(d) == 1 && d[0] == 0.0 { |
| 1861 | return &Path{} |
| 1862 | } |
| 1863 | |
| 1864 | if len(d)%2 == 1 { |
| 1865 | // if d is uneven length, dash and space lengths alternate. Duplicate d so that uneven indices are always spaces |
| 1866 | d = append(d, d...) |
| 1867 | } |
| 1868 | |
| 1869 | i0, pos0 := dashStart(offset, d) |
| 1870 | |
| 1871 | q := &Path{} |
| 1872 | for _, ps := range p.Split() { |
| 1873 | i := i0 |
| 1874 | pos := pos0 |
| 1875 | |
| 1876 | t := []float64{} |
| 1877 | length := ps.Length() |
| 1878 | for pos+d[i]+Epsilon < length { |
| 1879 | pos += d[i] |
| 1880 | if 0.0 < pos { |
| 1881 | t = append(t, pos) |
| 1882 | } |
| 1883 | i++ |
| 1884 | if i == len(d) { |
| 1885 | i = 0 |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | j0 := 0 |
| 1890 | endsInDash := i%2 == 0 |
| 1891 | if len(t)%2 == 1 && endsInDash || len(t)%2 == 0 && !endsInDash { |
| 1892 | j0 = 1 |
| 1893 | } |
| 1894 | |
| 1895 | qd := &Path{} |
| 1896 | pd := ps.SplitAt(t...) |
| 1897 | for j := j0; j < len(pd)-1; j += 2 { |
| 1898 | qd = qd.Append(pd[j]) |
| 1899 | } |
| 1900 | if endsInDash { |
| 1901 | if ps.Closed() { |
| 1902 | qd = pd[len(pd)-1].Join(qd) |
| 1903 | } else { |
| 1904 | qd = qd.Append(pd[len(pd)-1]) |
| 1905 | } |
| 1906 | } |
| 1907 | q = q.Append(qd) |
| 1908 | } |
| 1909 | return q |
| 1910 | } |
| 1911 | |
| 1912 | // Reverse returns a new path that is the same path as p but in the reverse direction. |
| 1913 | func (p *Path) Reverse() *Path { |