Draws polyline with straight segments, quadratic Bezier, or cubic Bezier (2D only) # Input `points` -- (n × 2) matrix of `(x, y)` coordinates `codes` -- slice of [`PolyCode`] values, one per point `closed` -- if `true`, closes the path back to the first point Note:** The first and last commands are ignored.
(&mut self, points: &'a T, codes: &[PolyCode], closed: bool)
| 422 | /// |
| 423 | /// **Note:** The first and last commands are ignored. |
| 424 | pub fn draw_polycurve<'a, T, U>(&mut self, points: &'a T, codes: &[PolyCode], closed: bool) -> Result<(), StrError> |
| 425 | where |
| 426 | T: AsMatrix<'a, U>, |
| 427 | U: 'a + std::fmt::Display, |
| 428 | { |
| 429 | let (npoint, ndim) = points.size(); |
| 430 | if npoint < 3 { |
| 431 | return Err("npoint must be ≥ 3"); |
| 432 | } |
| 433 | if ndim != 2 { |
| 434 | return Err("ndim must be equal to 2"); |
| 435 | } |
| 436 | if codes.len() != npoint { |
| 437 | return Err("codes.len() must be equal to npoint"); |
| 438 | } |
| 439 | write!( |
| 440 | &mut self.buffer, |
| 441 | "dat=[[pth.Path.MOVETO,({},{})]", |
| 442 | points.at(0, 0), |
| 443 | points.at(0, 1) |
| 444 | ) |
| 445 | .unwrap(); |
| 446 | for i in 1..npoint { |
| 447 | let keyword = match codes[i] { |
| 448 | PolyCode::MoveTo => "MOVETO", |
| 449 | PolyCode::LineTo => "LINETO", |
| 450 | PolyCode::Curve3 => "CURVE3", |
| 451 | PolyCode::Curve4 => "CURVE4", |
| 452 | }; |
| 453 | write!( |
| 454 | &mut self.buffer, |
| 455 | ",[pth.Path.{},({},{})]", |
| 456 | keyword, |
| 457 | points.at(i, 0), |
| 458 | points.at(i, 1) |
| 459 | ) |
| 460 | .unwrap(); |
| 461 | } |
| 462 | if closed { |
| 463 | write!(&mut self.buffer, ",[pth.Path.CLOSEPOLY,(None,None)]").unwrap(); |
| 464 | } |
| 465 | let opt = self.options_shared(); |
| 466 | write!( |
| 467 | &mut self.buffer, |
| 468 | "]\n\ |
| 469 | cmd,pts=zip(*dat)\n\ |
| 470 | h=pth.Path(pts,cmd)\n\ |
| 471 | p=pat.PathPatch(h{})\n\ |
| 472 | plt.gca().add_patch(p)\n", |
| 473 | &opt |
| 474 | ) |
| 475 | .unwrap(); |
| 476 | Ok(()) |
| 477 | } |
| 478 | |
| 479 | /// Begins adding points to a 3D polyline |
| 480 | /// |