# HG changeset patch # User Nir Krakauer # Date 1669660632 18000 # Mon Nov 28 13:37:12 2022 -0500 # Node ID c1e3041ede80ef7d8d51a8723c5eb8b75cd68935 # Parent 04965cda30b5f9e51774194c67879e7336df1710 ispolycw: allow x and y cell inputs; add tests; other small doc fixes diff -r 04965cda30b5 -r c1e3041ede80 inst/ispolycw.m --- a/inst/ispolycw.m Wed Jul 07 23:18:01 2021 +0200 +++ b/inst/ispolycw.m Mon Nov 28 13:37:12 2022 -0500 @@ -1,5 +1,6 @@ ## Copyright (C) 2016 - Juan Pablo Carbajal ## Copyright (C) 2017 - Piyush Jain +## Copyright (C) 2022 - Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -17,19 +18,19 @@ ## -*- texinfo -*- ## @deftypefn {} {@var{ccw} =} ispolycw (@var{p}) ## @deftypefnx {} {@var{ccw} =} ispolycw (@var{px}, @var{py}) -## Returns true if the polygon @var{p} are oriented Clockwise. +## Returns true if the polygon @var{p} are oriented clockwise. ## ## @var{p} is a N-by-2 array containing coordinates of vertices. The coordinates -## of the vertices of the polygon can also be given as two N-by-1 arrways +## of the vertices of the polygon can also be given as two N-by-1 arrays ## @var{px}, @var{py}. ## ## If polygon is self-crossing, the result is undefined. ## -## If x and y contain multiple contours, either in NaN-separated vector form or in cell array form, ispolycw returns a logical array containing one true or false value per contour. +## If @var{px}, @var{py} contain multiple contours, either in NaN-separated vector form or in cell array form, ispolycw returns a logical array containing one true or false value per contour. ## ## If a contour contains two or fewer vertices, ispolycw returns true. ## -## If @var{points} is a cell, each element is considered a polygon, the +## If @var{p} (or @var{px}, @var{py}) is a cell, each element is considered a polygon, the ## resulting @var{cw} array has the same shape as the cell. ## ## @seealso{polygonArea} @@ -38,7 +39,11 @@ function cw = ispolycw (px, py) if iscell (px) - cw = cellfun (@ispolycw, px); + if nargin == 2 + cw = cellfun (@ispolycw, px, py); + else + cw = cellfun (@ispolycw, px); + endif else if nargin == 2; @@ -70,6 +75,8 @@ %!assert (ispolycw (pcw)); %!assert (ispolycw ({pccw;pcw}), [false;true]); %!assert (ispolycw ({pccw,pcw}), [false,true]); +%!assert (ispolycw ({pccw(:, 1);pcw(:, 1)}, {pccw(:, 2);pcw(:, 2)}), [false;true]); +%!assert (ispolycw ({pccw(:, 1),pcw(:, 1)}, {pccw(:, 2),pcw(:, 2)}), [false,true]); %!assert (ispolycw(ph),[false;true]); %!test