Cody

Problem 193. Smallest distance between a point and a rectangle

Solution 1819814

Submitted on 19 May 2019 by John Simpson
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
assessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','distanceRectangle2Point.m')

2   Pass
x = [-1,-1]; y = [1,1]; z = [4,5]; assert(isequal(distanceRectangle2Point(x,y,z),5)) d_correct = 5;

A = -1 -1 B = 1 1 P = 4 5 d = 5 k = 7

3   Pass
x = [-2,-1]; y = [3,1]; z = [1,2]; assert(isequal(distanceRectangle2Point(x,y,z),1)) d_correct = 1;

A = -2 -1 B = 3 1 P = 1 2 d = 1 k = 2

4   Pass
x = [1,2]; y = [3,4]; z = [-5,3]; assert(isequal(distanceRectangle2Point(x,y,z),6)) d_correct = 6;

A = 1 2 B = 3 4 P = -5 3 d = 6 k = 1

5   Pass
x = [2,2]; y = [4,4]; z = [3,4]; assert(isequal(distanceRectangle2Point(x,y,z),0)) d_correct = 0;

A = 2 2 B = 4 4 P = 3 4 d = 0 k = 2

6   Pass
x = [-1,0,1]; y = [0,2,4]; z = [4,5,3]; assert(isequal(distanceRectangle2Point(x,y,z),5)) d_correct = 5;

A = -1 0 1 B = 0 2 4 P = 4 5 3 d = 5 k = 7

7   Pass
x = [1,0,1]; y = [2,3,2]; z = [-1,-2,3]; assert(isequal(distanceRectangle2Point(x,y,z),3)) d_correct = 3;

A = 1 0 1 B = 2 3 2 P = -1 -2 3 d = 3 k = 51