Skip to content

Commit

Permalink
Merge pull request #104 from jsconan/release-1.3.0
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
jsconan authored Feb 6, 2022
2 parents ded2b5c + 43e240d commit 91f826a
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 40 deletions.
12 changes: 12 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# camelSCAD history

## [Version 1.3.0](https://github.com/jsconan/camelSCAD/releases/tag/v1.3.0)

Add core functions:

- `iToX()`: Extract the X-coordinate from a linear position.
- `iToY()`: Extract the Y-coordinate from a linear position.

Refactor operators:

- `distributeGrid()`: Use the functions converting linear to 2D coordinates.
- `repeatGrid()`: Use the functions converting linear to 2D coordinates.

## [Version 1.2.0](https://github.com/jsconan/camelSCAD/releases/tag/v1.2.0)

Add core functions:
Expand Down
89 changes: 57 additions & 32 deletions core/maths.scad
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ function fragments(r, d) =
function astep(r, a=DEGREES, d) = min(DEGREES / fragments(r=r, d=d), float(a));

/**
* Computes the angle of a point on a circle
* Computes the angle of a point on a circle.
*
* @param Number [x] - The X coordinate of the point
* @param Number [y] - The Y coordinate of the point
* @param Number [x] - The X coordinate of the point.
* @param Number [y] - The Y coordinate of the point.
* @returns Number
*/
function getAngle(x, y) =
Expand All @@ -114,10 +114,11 @@ function getAngle(x, y) =
;

/**
* Gets the length of an arc given the radius and the angle
* @param Number angle - The angle of the arc
* @param Number [radius] - The radius of the circle
* @param Number [diameter] - The diameter of the circle
* Gets the length of an arc given the radius and the angle.
*
* @param Number angle - The angle of the arc.
* @param Number [radius] - The radius of the circle.
* @param Number [diameter] - The diameter of the circle.
* @returns Number
*/
function getArcLength(angle, radius, diameter) =
Expand All @@ -129,10 +130,11 @@ function getArcLength(angle, radius, diameter) =
;

/**
* Gets the angle of an arc given the radius and the length
* @param Number length - The length of the arc
* @param Number [radius] - The radius of the circle
* @param Number [diameter] - The diameter of the circle
* Gets the angle of an arc given the radius and the length.
*
* @param Number length - The length of the arc.
* @param Number [radius] - The radius of the circle.
* @param Number [diameter] - The diameter of the circle.
* @returns Number
*/
function getArcAngle(length, radius, diameter) =
Expand All @@ -145,10 +147,11 @@ function getArcAngle(length, radius, diameter) =
;

/**
* Gets the length of a chord given the radius and the angle
* @param Number angle - The angle of the chord
* @param Number [radius] - The radius of the circle
* @param Number [diameter] - The diameter of the circle
* Gets the length of a chord given the radius and the angle.
*
* @param Number angle - The angle of the chord.
* @param Number [radius] - The radius of the circle.
* @param Number [diameter] - The diameter of the circle.
* @returns Number
*/
function getChordLength(angle, radius, diameter) =
Expand All @@ -160,9 +163,10 @@ function getChordLength(angle, radius, diameter) =
;

/**
* Gets the height of a chord given the radius and the angle
* @param Number angle - The angle of the chord
* @param Number [radius] - The radius of the circle
* Gets the height of a chord given the radius and the angle.
*
* @param Number angle - The angle of the chord.
* @param Number [radius] - The radius of the circle.
* @param Number [diameter] - The diameter of the circle
* @returns Number
*/
Expand All @@ -175,10 +179,11 @@ function getChordHeight(angle, radius, diameter) =
;

/**
* Gets the distance to a chord given the radius and the angle
* @param Number angle - The angle of the chord
* @param Number [radius] - The radius of the circle
* @param Number [diameter] - The diameter of the circle
* Gets the distance to a chord given the radius and the angle.
*
* @param Number angle - The angle of the chord.
* @param Number [radius] - The radius of the circle.
* @param Number [diameter] - The diameter of the circle.
* @returns Number
*/
function getChordDistance(angle, radius, diameter) =
Expand All @@ -190,10 +195,11 @@ function getChordDistance(angle, radius, diameter) =
;

/**
* Gets the angle of a chord given the radius and the length
* @param Number length - The length of the chord
* @param Number [radius] - The radius of the circle
* @param Number [diameter] - The diameter of the circle
* Gets the angle of a chord given the radius and the length.
*
* @param Number length - The length of the chord.
* @param Number [radius] - The radius of the circle.
* @param Number [diameter] - The diameter of the circle.
* @returns Number
*/
function getChordAngle(length, radius, diameter) =
Expand All @@ -207,9 +213,10 @@ function getChordAngle(length, radius, diameter) =

/**
* Gets the angle value at a particular index in a regular polygon.
* @param Number index - The index of the angle
* @param Number [count] - The number of sides in the polygon
* @returns Number - The angle for the provided index
*
* @param Number index - The index of the angle.
* @param Number [count] - The number of sides in the polygon.
* @returns Number - The angle for the provided index.
*/
function getPolygonAngle(index, count = 4) =
let(
Expand Down Expand Up @@ -396,9 +403,9 @@ function decimals(value) =
* - the second value is for the result of (-b + sqrt(delta)) / (2 * a)
* If the equation cannot be resolved, returns an empty vector.
*
* @param Number a - The A term of the equation
* @param Number b - The B term of the equation
* @param Number c - The C term of the equation
* @param Number a - The A term of the equation.
* @param Number b - The B term of the equation.
* @param Number c - The C term of the equation.
* @returns Vector[]
*/
function quadraticEquation(a, b, c) =
Expand All @@ -414,3 +421,21 @@ function quadraticEquation(a, b, c) =
]
:[]
;

/**
* Extract the X-coordinate from a linear position.
*
* @param Number i - The linear position.
* @param Number count - The maximal value for the linear position.
* @returns Number
*/
function iToX(i, count) = float(i) % divisor(count);

/**
* Extract the X-coordinate from a linear position.
*
* @param Number i - The linear position.
* @param Number count - The maximal value for the linear position.
* @returns Number
*/
function iToY(i, count) = floor(float(i) / divisor(count));
2 changes: 1 addition & 1 deletion core/version.scad
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* The version of the library.
* @type Vector
*/
CAMEL_SCAD_VERSION = [1, 2, 0];
CAMEL_SCAD_VERSION = [1, 3, 0];

/**
* The minimal version of OpenSCAD required by the library.
Expand Down
4 changes: 2 additions & 2 deletions operator/distribute/grid.scad
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ module distributeGrid(intervalX = xAxis3D(),
count = $children;
line = max(floor(abs(float(line))), 1);
offsetX = center ? -intervalX * ((count > line ? line : count) - 1) / 2 : ORIGIN_3D;
offsetY = center ? -intervalY * (floor(count / line) - (count % line ? 0 : 1)) / 2 : ORIGIN_3D;
offsetY = center ? -intervalY * (iToY(count, line) - (iToX(count, line) ? 0 : 1)) / 2 : ORIGIN_3D;

for (i = [0 : count - 1]) {
translate(offsetX + intervalX * (i % line) + offsetY + intervalY * floor(i / line)) {
translate(offsetX + intervalX * iToX(i, line) + offsetY + intervalY * iToY(i, line)) {
children(i);
}
}
Expand Down
4 changes: 2 additions & 2 deletions operator/repeat/grid.scad
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ module repeatGrid(count = 2,
count = max(floor(abs(float(count))), 1);
line = max(floor(abs(float(line))), 1);
offsetX = center ? -intervalX * ((count > line ? line : count) - 1) / 2 : ORIGIN_3D;
offsetY = center ? -intervalY * (floor(count / line) - (count % line ? 0 : 1)) / 2 : ORIGIN_3D;
offsetY = center ? -intervalY * (iToY(count, line) - (iToX(count, line) ? 0 : 1)) / 2 : ORIGIN_3D;

for (i = [0 : count - 1]) {
translate(offsetX + intervalX * (i % line) + offsetY + intervalY * floor(i / line)) {
translate(offsetX + intervalX * iToX(i, line) + offsetY + intervalY * iToY(i, line)) {
children();
}
}
Expand Down
32 changes: 31 additions & 1 deletion test/core/maths.scad
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use <../../full.scad>
* @author jsconan
*/
module testCoreMaths() {
testPackage("core/maths.scad", 26) {
testPackage("core/maths.scad", 28) {
// test core/maths/deg()
testModule("deg()", 3) {
testUnit("no parameter", 1) {
Expand Down Expand Up @@ -883,6 +883,36 @@ module testCoreMaths() {
assertEqual(quadraticEquation(1, 2, 0), [-2, 0], "Should resolve the quadratic equation 1x^2 + 2x - 0 = 0");
}
}
// test core/maths/iToX()
testModule("iToX()", 2) {
testUnit("wrong value", 4) {
assertEqual(iToX(), 0, "When no parameter is given, it should return a 0");
assertEqual(iToX("1", "2"), 0, "When strings are given, it should return a 0");
assertEqual(iToX(true, true), 0, "When booleans are given, it should return a 0");
assertEqual(iToX([1], [2]), 0, "When vectorss are given, it should return a 0");
}
testUnit("number value", 4) {
assertEqual(iToX(0, 0), 0, "When parameters are position=0, count=0, the result must be 0");
assertEqual(iToX(3, 0), 0, "When parameters are position=3, count=0, the result must be 0");
assertEqual(iToX(3, 5), 3, "When parameters are position=3, count=5, the result must be 3");
assertEqual(iToX(5, 3), 2, "When parameters are position=5, count=3, the result must be 2");
}
}
// test core/maths/iToY()
testModule("iToY()", 2) {
testUnit("wrong value", 4) {
assertEqual(iToY(), 0, "When no parameter is given, it should return a 0");
assertEqual(iToY("1", "2"), 0, "When strings are given, it should return a 0");
assertEqual(iToY(true, true), 0, "When booleans are given, it should return a 0");
assertEqual(iToY([1], [2]), 0, "When vectorss are given, it should return a 0");
}
testUnit("number value", 4) {
assertEqual(iToY(0, 0), 0, "When parameters are position=0, count=0, the result must be 0");
assertEqual(iToY(3, 0), 3, "When parameters are position=3, count=0, the result must be 3");
assertEqual(iToY(3, 5), 0, "When parameters are position=3, count=5, the result must be 0");
assertEqual(iToY(5, 3), 1, "When parameters are position=5, count=3, the result must be 1");
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/core/version.scad
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ module testCoreVersion() {
// test camelSCAD()
testModule("camelSCAD()", 2) {
testUnit("as vector", 1) {
assertEqual(camelSCAD(), [1, 2, 0], "The current version of the library is 1.2.0");
assertEqual(camelSCAD(), [1, 3, 0], "The current version of the library is 1.3.0");
}
testUnit("as string", 1) {
assertEqual(camelSCAD(true), "1.2.0", "The current version of the library is 1.2.0");
assertEqual(camelSCAD(true), "1.3.0", "The current version of the library is 1.3.0");
}
}
}
Expand Down

0 comments on commit 91f826a

Please sign in to comment.