LineTo adds a linear path to (x,y).
(x, y float64)
| 409 | |
| 410 | // LineTo adds a linear path to (x,y). |
| 411 | func (p *Path) LineTo(x, y float64) { |
| 412 | start := p.Pos() |
| 413 | end := Point{x, y} |
| 414 | if start.Equals(end) { |
| 415 | return |
| 416 | } else if cmdLen(LineToCmd) <= len(p.d) && p.d[len(p.d)-1] == LineToCmd { |
| 417 | prevStart := Point{} |
| 418 | if cmdLen(LineToCmd) < len(p.d) { |
| 419 | prevStart = Point{p.d[len(p.d)-cmdLen(LineToCmd)-3], p.d[len(p.d)-cmdLen(LineToCmd)-2]} |
| 420 | } |
| 421 | |
| 422 | // divide by length^2 since otherwise the perpdot between very small segments may be |
| 423 | // below Epsilon |
| 424 | da := start.Sub(prevStart) |
| 425 | db := end.Sub(start) |
| 426 | div := da.PerpDot(db) |
| 427 | if length := da.Length() * db.Length(); Equal(div/length, 0.0) { |
| 428 | // lines are parallel |
| 429 | extends := false |
| 430 | if da.Y < da.X { |
| 431 | extends = math.Signbit(da.X) == math.Signbit(db.X) |
| 432 | } else { |
| 433 | extends = math.Signbit(da.Y) == math.Signbit(db.Y) |
| 434 | } |
| 435 | if extends { |
| 436 | //if Equal(end.Sub(start).AngleBetween(start.Sub(prevStart)), 0.0) { |
| 437 | p.d[len(p.d)-3] = x |
| 438 | p.d[len(p.d)-2] = y |
| 439 | return |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if len(p.d) == 0 { |
| 445 | p.MoveTo(0.0, 0.0) |
| 446 | } else if p.d[len(p.d)-1] == CloseCmd { |
| 447 | p.MoveTo(p.d[len(p.d)-3], p.d[len(p.d)-2]) |
| 448 | } |
| 449 | p.d = append(p.d, LineToCmd, end.X, end.Y, LineToCmd) |
| 450 | } |
| 451 | |
| 452 | // QuadTo adds a quadratic Bézier path with control point (cpx,cpy) and end point (x,y). |
| 453 | func (p *Path) QuadTo(cpx, cpy, x, y float64) { |