From 49dd1eb0ff269184333f791387470517f3890d46 Mon Sep 17 00:00:00 2001 From: Prashal Ruchiranga Date: Mon, 3 Oct 2022 20:35:46 +0530 Subject: [PATCH 1/6] Add an algorithm to find length and area of an arc of a circle --- Maths/CircularArc.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Maths/CircularArc.js diff --git a/Maths/CircularArc.js b/Maths/CircularArc.js new file mode 100644 index 0000000000..5932937fea --- /dev/null +++ b/Maths/CircularArc.js @@ -0,0 +1,41 @@ +/** + * @function degreesToRadians + * @description convert from degrees to radians + * @param {Integer} angle in degrees + * @return {Integer} degrees * pi / 180 + * @see https://en.wikipedia.org/wiki/Degree_(angle) + * @example degreesToRadians(45) = 0.7853981633974483 + */ + function degreesToRadians(degrees) { + return angle = degrees * Math.PI / 180 +} + +/** + * @function circularArcLength + * @description calculate the length of a circular arc + * @param {Integer} radius + * @param {Integer} degrees + * @returns {Integer} radius * angle_in _adians + * @see https://en.wikipedia.org/wiki/Circular_arc + * @example circularArcLength(3, 45) = 2.356194490192345 + */ +function circularArcLength(radius, degrees) { + return length = radius * degreesToRadians(degrees) +} +/** + * @function circularArcArea + * @description calculate the area of the sector formed by an arc + * @param {Integer} radius + * @param {Integer} degrees + * @returns {Integer} 0.5 * r * r * angle_in_radians + * @see https://en.wikipedia.org/wiki/Circular_arc + * @example circularArcArea(3,45) = 3.5342917352885173 + */ +function circularArcArea(radius, degrees) { + return area = Math.pow(radius, 2) * degreesToRadians(degrees) / 2 +} + +export { + circularArcLength, + circularArcArea +} \ No newline at end of file From 0de33fa67d3fccc0d300995620ccae4696a4fe2d Mon Sep 17 00:00:00 2001 From: Prashal Ruchiranga Date: Mon, 3 Oct 2022 21:42:32 +0530 Subject: [PATCH 2/6] Updated to follow Javascript Standard Style --- Maths/CircularArc.js | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/Maths/CircularArc.js b/Maths/CircularArc.js index 5932937fea..57b4d4d16f 100644 --- a/Maths/CircularArc.js +++ b/Maths/CircularArc.js @@ -6,36 +6,36 @@ * @see https://en.wikipedia.org/wiki/Degree_(angle) * @example degreesToRadians(45) = 0.7853981633974483 */ - function degreesToRadians(degrees) { - return angle = degrees * Math.PI / 180 -} + function degreesToRadians (degrees) { + return degrees * Math.PI / 180 + } -/** - * @function circularArcLength - * @description calculate the length of a circular arc - * @param {Integer} radius - * @param {Integer} degrees - * @returns {Integer} radius * angle_in _adians - * @see https://en.wikipedia.org/wiki/Circular_arc - * @example circularArcLength(3, 45) = 2.356194490192345 - */ -function circularArcLength(radius, degrees) { - return length = radius * degreesToRadians(degrees) -} -/** - * @function circularArcArea - * @description calculate the area of the sector formed by an arc - * @param {Integer} radius - * @param {Integer} degrees - * @returns {Integer} 0.5 * r * r * angle_in_radians - * @see https://en.wikipedia.org/wiki/Circular_arc - * @example circularArcArea(3,45) = 3.5342917352885173 - */ -function circularArcArea(radius, degrees) { - return area = Math.pow(radius, 2) * degreesToRadians(degrees) / 2 -} + /** + * @function circularArcLength + * @description calculate the length of a circular arc + * @param {Integer} radius + * @param {Integer} degrees + * @returns {Integer} radius * angle_in _adians + * @see https://en.wikipedia.org/wiki/Circular_arc + * @example circularArcLength(3, 45) = 2.356194490192345 + */ + function circularArcLength (radius, degrees) { + return radius * degreesToRadians(degrees) + } + /** + * @function circularArcArea + * @description calculate the area of the sector formed by an arc + * @param {Integer} radius + * @param {Integer} degrees + * @returns {Integer} 0.5 * r * r * angle_in_radians + * @see https://en.wikipedia.org/wiki/Circular_arc + * @example circularArcArea(3,45) = 3.5342917352885173 + */ + function circularArcArea (radius, degrees) { + return Math.pow(radius, 2) * degreesToRadians(degrees) / 2 + } -export { + export { circularArcLength, circularArcArea -} \ No newline at end of file + } From 59663e938a477372a832270170cd8b9fa2ed8ef5 Mon Sep 17 00:00:00 2001 From: Prashal Ruchiranga Date: Mon, 3 Oct 2022 21:51:18 +0530 Subject: [PATCH 3/6] Update CircularArc.js --- Maths/CircularArc.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Maths/CircularArc.js b/Maths/CircularArc.js index 57b4d4d16f..57ab7e94b5 100644 --- a/Maths/CircularArc.js +++ b/Maths/CircularArc.js @@ -6,11 +6,11 @@ * @see https://en.wikipedia.org/wiki/Degree_(angle) * @example degreesToRadians(45) = 0.7853981633974483 */ - function degreesToRadians (degrees) { - return degrees * Math.PI / 180 - } +function degreesToRadians (degrees) { + return degrees * Math.PI / 180 +} - /** +/** * @function circularArcLength * @description calculate the length of a circular arc * @param {Integer} radius @@ -19,10 +19,10 @@ * @see https://en.wikipedia.org/wiki/Circular_arc * @example circularArcLength(3, 45) = 2.356194490192345 */ - function circularArcLength (radius, degrees) { - return radius * degreesToRadians(degrees) - } - /** +function circularArcLength (radius, degrees) { + return radius * degreesToRadians(degrees) +} +/** * @function circularArcArea * @description calculate the area of the sector formed by an arc * @param {Integer} radius @@ -31,11 +31,11 @@ * @see https://en.wikipedia.org/wiki/Circular_arc * @example circularArcArea(3,45) = 3.5342917352885173 */ - function circularArcArea (radius, degrees) { - return Math.pow(radius, 2) * degreesToRadians(degrees) / 2 - } +function circularArcArea (radius, degrees) { + return Math.pow(radius, 2) * degreesToRadians(degrees) / 2 +} - export { - circularArcLength, - circularArcArea - } +export { + circularArcLength, + circularArcArea +} From 2be2bce16030dc60c71da9d26d80fdde55969b64 Mon Sep 17 00:00:00 2001 From: Prashal Ruchiranga Date: Mon, 3 Oct 2022 23:59:11 +0530 Subject: [PATCH 4/6] Update CircularArc.js --- Maths/CircularArc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/CircularArc.js b/Maths/CircularArc.js index 57ab7e94b5..eab2dd0736 100644 --- a/Maths/CircularArc.js +++ b/Maths/CircularArc.js @@ -15,7 +15,7 @@ function degreesToRadians (degrees) { * @description calculate the length of a circular arc * @param {Integer} radius * @param {Integer} degrees - * @returns {Integer} radius * angle_in _adians + * @returns {Integer} radius * angle_in_radians * @see https://en.wikipedia.org/wiki/Circular_arc * @example circularArcLength(3, 45) = 2.356194490192345 */ From 83259b329b9799ae438b1c2ff2bdde74da9bd282 Mon Sep 17 00:00:00 2001 From: Prashal Ruchiranga Date: Fri, 7 Oct 2022 21:13:30 +0530 Subject: [PATCH 5/6] Add tests --- Maths/CircularArc.js | 16 +++------------- Maths/test/CircularArc.test.js | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 Maths/test/CircularArc.test.js diff --git a/Maths/CircularArc.js b/Maths/CircularArc.js index eab2dd0736..c82be2ae22 100644 --- a/Maths/CircularArc.js +++ b/Maths/CircularArc.js @@ -1,14 +1,4 @@ -/** - * @function degreesToRadians - * @description convert from degrees to radians - * @param {Integer} angle in degrees - * @return {Integer} degrees * pi / 180 - * @see https://en.wikipedia.org/wiki/Degree_(angle) - * @example degreesToRadians(45) = 0.7853981633974483 - */ -function degreesToRadians (degrees) { - return degrees * Math.PI / 180 -} +import { degreeToRadian } from "./DegreeToRadian.js" /** * @function circularArcLength @@ -20,7 +10,7 @@ function degreesToRadians (degrees) { * @example circularArcLength(3, 45) = 2.356194490192345 */ function circularArcLength (radius, degrees) { - return radius * degreesToRadians(degrees) + return radius * degreeToRadian(degrees) } /** * @function circularArcArea @@ -32,7 +22,7 @@ function circularArcLength (radius, degrees) { * @example circularArcArea(3,45) = 3.5342917352885173 */ function circularArcArea (radius, degrees) { - return Math.pow(radius, 2) * degreesToRadians(degrees) / 2 + return Math.pow(radius, 2) * degreeToRadian(degrees) / 2 } export { diff --git a/Maths/test/CircularArc.test.js b/Maths/test/CircularArc.test.js new file mode 100644 index 0000000000..a2509e5b24 --- /dev/null +++ b/Maths/test/CircularArc.test.js @@ -0,0 +1,20 @@ +import { circularArcLength } from "../CircularArc"; +import { circularArcArea } from "../CircularArc"; + +describe('circularArcLength', () => { + it('with natural number', () => { + const arcLengthOfOneThirty = circularArcLength(1, 30) + const arcLengthOfThreeSixty = circularArcLength(3, 60) + expect(arcLengthOfOneThirty).toBe(0.5235987755982988) + expect(arcLengthOfThreeSixty).toBe(3.141592653589793) + }) + }) + +describe('circularArcArea', () => { + it('with natural number', () => { + const arcAreaOfOneThirty = circularArcArea(1, 30) + const arcAreaOfThreeSixty = circularArcArea(3, 60) + expect(arcAreaOfOneThirty).toBe(0.2617993877991494) + expect(arcAreaOfThreeSixty).toBe(4.71238898038469) + }) + }) \ No newline at end of file From d50e1600054d4ceef8f82835f816f09463fcfdfc Mon Sep 17 00:00:00 2001 From: Prashal Ruchiranga Date: Fri, 7 Oct 2022 21:24:41 +0530 Subject: [PATCH 6/6] Followed Javascript standard style --- Maths/CircularArc.js | 2 +- Maths/test/CircularArc.test.js | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Maths/CircularArc.js b/Maths/CircularArc.js index c82be2ae22..27d690bcf4 100644 --- a/Maths/CircularArc.js +++ b/Maths/CircularArc.js @@ -1,4 +1,4 @@ -import { degreeToRadian } from "./DegreeToRadian.js" +import { degreeToRadian } from './DegreeToRadian.js' /** * @function circularArcLength diff --git a/Maths/test/CircularArc.test.js b/Maths/test/CircularArc.test.js index a2509e5b24..1819d30eed 100644 --- a/Maths/test/CircularArc.test.js +++ b/Maths/test/CircularArc.test.js @@ -1,20 +1,19 @@ -import { circularArcLength } from "../CircularArc"; -import { circularArcArea } from "../CircularArc"; +import { circularArcLength, circularArcArea } from '../CircularArc' describe('circularArcLength', () => { - it('with natural number', () => { - const arcLengthOfOneThirty = circularArcLength(1, 30) - const arcLengthOfThreeSixty = circularArcLength(3, 60) - expect(arcLengthOfOneThirty).toBe(0.5235987755982988) - expect(arcLengthOfThreeSixty).toBe(3.141592653589793) - }) + it('with natural number', () => { + const arcLengthOfOneThirty = circularArcLength(1, 30) + const arcLengthOfThreeSixty = circularArcLength(3, 60) + expect(arcLengthOfOneThirty).toBe(0.5235987755982988) + expect(arcLengthOfThreeSixty).toBe(3.141592653589793) }) +}) describe('circularArcArea', () => { - it('with natural number', () => { - const arcAreaOfOneThirty = circularArcArea(1, 30) - const arcAreaOfThreeSixty = circularArcArea(3, 60) - expect(arcAreaOfOneThirty).toBe(0.2617993877991494) - expect(arcAreaOfThreeSixty).toBe(4.71238898038469) - }) - }) \ No newline at end of file + it('with natural number', () => { + const arcAreaOfOneThirty = circularArcArea(1, 30) + const arcAreaOfThreeSixty = circularArcArea(3, 60) + expect(arcAreaOfOneThirty).toBe(0.2617993877991494) + expect(arcAreaOfThreeSixty).toBe(4.71238898038469) + }) +})