MCPcopy Index your code
hub / github.com/endbasic/endbasic / parse_polygon_coordinates

Function parse_polygon_coordinates

std/src/gfx/mod.rs:77–99  ·  view source on GitHub ↗

Parses a variable-length sequence of X/Y coordinate pairs.

(scope: &Scope<'_>)

Source from the content-addressed store, hash-verified

75
76/// Parses a variable-length sequence of X/Y coordinate pairs.
77fn parse_polygon_coordinates(scope: &Scope<'_>) -> CallResult<Vec<PixelsXY>> {
78 match scope.nargs() {
79 0 => return Ok(vec![]),
80 1 => return parse_polygon_coordinates_from_array(scope),
81 _ => (),
82 }
83
84 if !scope.nargs().is_multiple_of(2) {
85 let narg = u8::try_from(scope.nargs() - 1).expect("Argument index must fit in u8");
86 return Err(CallError::Syntax(
87 scope.get_pos(narg),
88 "Expected an even number of coordinates".to_owned(),
89 ));
90 }
91
92 let mut points = Vec::with_capacity(scope.nargs() / 2);
93 for i in (0..scope.nargs()).step_by(2) {
94 let xarg = u8::try_from(i).expect("Argument index must fit in u8");
95 let yarg = u8::try_from(i + 1).expect("Argument index must fit in u8");
96 points.push(parse_coordinates(scope, xarg, yarg)?);
97 }
98 Ok(points)
99}
100
101/// Parses an array reference that contains a variable-length sequence of X/Y coordinate pairs.
102fn parse_polygon_coordinates_from_array(scope: &Scope<'_>) -> CallResult<Vec<PixelsXY>> {

Callers 1

execMethod · 0.85

Calls 5

parse_coordinatesFunction · 0.85
nargsMethod · 0.80
get_posMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected