MCPcopy
hub / github.com/tdewolff/canvas / Same

Method Same

path.go:212–244  ·  view source on GitHub ↗

Same returns true if p and q are equal shapes within tolerance Epsilon. Path q may start at an offset into path p or may be in the reverse direction.

(q *Path)

Source from the content-addressed store, hash-verified

210
211// Same returns true if p and q are equal shapes within tolerance Epsilon. Path q may start at an offset into path p or may be in the reverse direction.
212func (p *Path) Same(q *Path) bool {
213 // TODO: improve, does not handle subpaths or Close vs LineTo
214 if len(p.d) != len(q.d) {
215 return false
216 }
217 qr := q.Reverse() // TODO: can we do without?
218 for j := 0; j < len(q.d); {
219 equal := true
220 for i := 0; i < len(p.d); i++ {
221 if !Equal(p.d[i], q.d[(j+i)%len(q.d)]) {
222 equal = false
223 break
224 }
225 }
226 if equal {
227 return true
228 }
229
230 // backwards
231 equal = true
232 for i := 0; i < len(p.d); i++ {
233 if !Equal(p.d[i], qr.d[(j+i)%len(qr.d)]) {
234 equal = false
235 break
236 }
237 }
238 if equal {
239 return true
240 }
241 j += cmdLen(q.d[j])
242 }
243 return false
244}
245
246// Closed returns true if the last subpath of p is a closed path.
247func (p *Path) Closed() bool {

Callers 1

TestPathSameFunction · 0.80

Calls 3

EqualFunction · 0.85
cmdLenFunction · 0.85
ReverseMethod · 0.45

Tested by 1

TestPathSameFunction · 0.64