Skip to content

Commit

Permalink
Merge pull request #117 from jsconan/release-1.8.0
Browse files Browse the repository at this point in the history
Release 1.8.0
  • Loading branch information
jsconan authored Jun 19, 2022
2 parents fe411c9 + 1463986 commit de24712
Show file tree
Hide file tree
Showing 96 changed files with 5,481 additions and 51 deletions.
31 changes: 31 additions & 0 deletions core/constants.scad
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,34 @@ DEFAULT_BUILD_VOLUME_SIZE = DEFAULT_BUILD_PLATE_SIZE;
* @type Number
*/
DEFAULT_BUILD_PLATE_CELL = 10;

/**
* The color for the testbed.
* @type String
*/
TESTBED_COLOR = "orange";

/**
* The thickness of the testbed.
* @type String
*/
TESTBED_THICKNESS = .005;

/**
* Show the testbed for the visual tests.
* @type Boolean
*/
TESTBED_SHOW = true;

/**
* Reduces the range of visual tests. By default all tests are presented.
* The range relates to the indexes of the tests.
* @type Vector
*/
TESTBED_RANGE = [0, INFINITY];

/**
* Selects the index of a single test to show. By default all tests are presented.
* @type Number
*/
TESTBED_SELECT = -1;
11 changes: 5 additions & 6 deletions core/util.scad
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function after(position) = float(position) > 0;

/**
* Gets a numeric representation of a cardinal point.
* West and Eath are related to X-coordinate (resp. -1 and 1, or 2 if both).
* West and East are related to X-coordinate (resp. -1 and 1, or 2 if both).
* South and North are related to Y-coordinate (resp. -1 and 1, or 2 if both).
*
* A cardinal expression is a string that contains cardinal point literals:
Expand All @@ -90,9 +90,9 @@ function after(position) = float(position) > 0;
*
* Combinations are allowed, for instance
* - "ne" means North East, and will be translated to [1, 1]
* - "nwe" means North Weast East, and will be translated to [2, 1]
* - "nsw" means North South Weast, and will be translated to [-1, 2]
* - "nswe" means North South Weast East, and will be translated to [2, 2]
* - "nwe" means North West East, and will be translated to [2, 1]
* - "nsw" means North South West, and will be translated to [-1, 2]
* - "nswe" means North South West East, and will be translated to [2, 2]
*
* @param Vector|String p - A vector or a cardinal expression.
* @returns Vector - A 2D vector that contains position values for horizontal and vertical axis.
Expand Down Expand Up @@ -123,13 +123,12 @@ function align(value, direction, center) =
let(
direction = cardinal(uor(direction, 2)).y,
value = divisor(value),
absv = abs(value),
adjust = direction ? (direction == 2 ? ALIGN2 : ALIGN) : 0,
offset = center ? (direction == 2 || direction == 0 ? 0 : direction * ALIGN / 2)
: (direction == 2 || direction == -1 ? -ALIGN : 0)
)
[
absv + adjust,
abs(value) + adjust,
offset + (value < 0 && !center ? value : 0)
]
;
4 changes: 2 additions & 2 deletions operator/extrude/negative.scad
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ module negativeExtrude(height, direction, center, convexity, twist, slices, scal
convexity = numberOr(convexity, 10);
height = align(value=height, direction=direction, center=center);

translateZ(height.y) {
linear_extrude(height=height.x, center=center, convexity=convexity, twist=twist, slices=slices, scale=scale) {
translateZ(height[1]) {
linear_extrude(height=height[0], center=center, convexity=convexity, twist=twist, slices=slices, scale=scale) {
children();
}
}
Expand Down
25 changes: 13 additions & 12 deletions operator/operation.scad
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@
/**
* Applies a boolean operation on the children modules.
*
* @param Number [mode] - The operation to apply: -1: difference, 0:union, 1: intersection.
* @param Number [mode] - The operation to apply: -1:difference, 0:union, 1:intersection.
*/
module operation(mode) {
mode = sign(mode);
if (mode < 0) {
difference() {
children(0);
children([1 : $children - 1]);
let( mode = $children > 1 ? sign(float(mode)) : 0 ) {
if (mode < 0) {
difference() {
children(0);
children([1 : $children - 1]);
}
} else if (mode > 0) {
intersection_for(i = [0 : $children - 1]) {
children(i);
}
} else {
children();
}
} else if (mode > 0) {
intersection_for(i = [0 : $children - 1]) {
children(i);
}
} else {
children();
}
}
4 changes: 2 additions & 2 deletions operator/repeat/rotate.scad
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module repeatRotate(count = 2,
interval = apply3D(interval, intervalX, intervalY, intervalZ);
origin = apply3D(origin, originX, originY, originZ);
angle = deg(angle);
partAngle = angle / (angle % DEGREES ? count - 1 : count);
partAngle = angle / divisor(angle % DEGREES ? count - 1 : count);
axis = apply3D(axis, axisX, axisY, axisZ) * partAngle;
offset = center ? -interval * (count - 1) / 2 : ORIGIN_3D;

Expand Down Expand Up @@ -163,7 +163,7 @@ module repeatRotate3D(countX = 2,
* Repeats the children modules on every angle given in the `map`.
*
* @param Vector[] map - The list of angles at which place the children.
* @param Vector [offset] - An offset to add before the ratation is applied.
* @param Vector [offset] - An offset to add before the rotation is applied.
* @param Number [x] - The X-coordinate to apply on the offset.
* @param Number [y] - The Y-coordinate to apply on the offset.
* @param Number [z] - The Z-coordinate to apply on the offset.
Expand Down
2 changes: 2 additions & 0 deletions operator/rotate/origin.scad
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
* @param Vector [o] - The rotate origin.
*/
module rotateOrigin(a, v, o) {
a = is_num(a) ? a : vector3D(a);
v = is_undef(v) ? undef : vector3D(v);
o = vector3D(o);
translate(o) {
rotate(a=a, v=v) {
Expand Down
6 changes: 3 additions & 3 deletions operator/sample.scad
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@
* @param Number [x] - The horizontal offset.
* @param Number [y] - The depth offset.
* @param Number [z] - The vertical offset.
* @param Boolean [center] - Whether or not center the sample on the vertical axis.
* @param Boolean [center] - Whether or not center the sample on all axis.
*/
module sample(size, offset, l, w, h, x, y, z, center) {
size = apply3D(size, l, w, h);
offset = apply3D(offset, x, y, z);
offset = apply3D(offset, x, y, z) / (center ? 2 : 1);

translate(-offset) {
intersection() {
translate(offset) {
box(size, center=center);
cube(size, center=center);
}
children();
}
Expand Down
186 changes: 186 additions & 0 deletions operator/test/test.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* @license
* MIT License
*
* Copyright (c) 2022 Jean-Sebastien CONAN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Part of the camelSCAD library.
*
* Testing helpers for visual tests.
*
* @package shape/context
* @author jsconan
*/

/**
* Renders a test element. If no children is given, a cube with an arrow on top is rendered.
* @param String|Vector [c] - The color of the element.
* @param Number|Vector [angle] - The angle of the element.
* @param Number|Vector [size] - The size of the element. It only applies if no children is given.
* @param Boolean [center] - Whether or not the element is centered. It only applies if no children is given.
*/
module testElement(c="red", angle=0, size=1, center=false) {
color(c) {
rotate(angle) {
if ($children) {
children();
} else let(
size = vector3D(size),
half = size / 2,
quarter = size / 4,
offset = center ? -half : vector3D()
) {
translate(offset) {
linear_extrude(height=size.z, convexity=10) {
polygon(
points = path([
["P", half.x, size.y],
["L", half.x, -half.y],
["H", -quarter.x],
["V", -half.y],
["H", -half.x],
["V", half.y],
["H", -quarter.x],
]),
convexity = 10
);
}
translateZ(quarter.z) {
cube(size=[size.x, size.y, half.z]);
}
}
}
}
}
}

/**
* Colorizes a test element.
* @param Number alpha - The alpha level for the testbed color.
*/
module testbedColor(alpha) {
%color(TESTBED_COLOR, alpha) {
children();
}
}

/**
* Extrudes and colorizes a test element.
* @param Number alpha - The alpha level for the testbed color.
*/
module testbedExtrude(alpha) {
testbedColor(alpha) {
linear_extrude(height=TESTBED_THICKNESS, convexity=10, center=true) {
children();
}
}
}

/**
* Renders a test area, moving the tested shapes in it.
* A testbed is shown, unless the global variable `TESTBED_SHOW` is set to `false`.
* @param Number index - The index number of the test.
* @param Number length - The length of the test area.
* @param Number width - The width of the test area.
* @param String [title] - The title for the test.
* @param Number|Vector [margin] - A margin between each test.
* @param Number [cols] - The number of columns per lines.
*/
module visualTest(index, length, width, title="test", margin=1, cols=0) {
title = str(title, " ", index);
fontSize = min(length, width) / len(title);
margin = vector2D(margin);
height = (length + width) / 2;
x = cols ? index % cols : index;
y = cols ? floor(index / cols) : 0;
offset = [length, width, 0] / 2;
testPosition = [(length + margin.x) * x, (width + margin.y) * y, 0] + offset;
titlePosition = [length * .1, width * .9, 0] - offset;

translate(testPosition) {
// test area
if (TESTBED_SHOW) {
// Plate
testbedExtrude(.1) {
square([length, width], center=true);
}
// Z-axis
rotateY(90) {
testbedExtrude(.5) {
square([height, TESTBED_THICKNESS], center=true);
}
}
testbedExtrude(.5) {
// X-axis
square([length, TESTBED_THICKNESS], center=true);
// Y-axis
square([TESTBED_THICKNESS, width], center=true);
}
// Title
translate(titlePosition) {
testbedExtrude(1) {
text(title, size=fontSize, font="Liberation Sans", valign="top", halign="left");
}
}
}

// tested elements
children();
}
}

/**
* Renders a test area for each child module, moving the tested shapes in it.
* A single test can be selected by its index thanks to the global variable `TESTBED_SELECT`.
* A subset of the tests can be selected thanks to the global variable `TESTBED_RANGE`.
* @param Number length - The length of the test area.
* @param Number width - The width of the test area.
* @param String [title] - The title for the test.
* @param Number|Vector [margin] - A margin between each test.
* @param Number [cols] - The number of columns per lines.
* @param Boolean [center] - Whether or not center the whole suite.
*/
module visualTestSuite(length, width, title="test", margin=1, cols=0, center=false) {
margin = vector2D(margin);
count = $children;
TESTBED_RANGE = is_num(TESTBED_SELECT) && TESTBED_SELECT >= 0 ? [TESTBED_SELECT, TESTBED_SELECT] : TESTBED_RANGE;
start = max(min(TESTBED_RANGE), 0);
end = min(max(TESTBED_RANGE), count - 1);
lines = cols ? ceil(count / cols) : 1;
offset = center ? -([margin.x * (cols - 1), margin.y * (lines - 1), 0] + [length * cols, width * lines, 0]) / 2 : ORIGIN_3D;

translate(offset) {
for (i = [start : end]) {
visualTest(
index = i,
length = length,
width = width,
title = title,
margin = margin,
cols = cols
) {
children(i);
}
}
}
}
2 changes: 2 additions & 0 deletions operators.scad
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ include <operator/repeat/translate.scad>
include <operator/rotate/axis.scad>
include <operator/rotate/origin.scad>

include <operator/test/test.scad>

include <operator/translate/axis.scad>

include <operator/operation.scad>
Expand Down
6 changes: 4 additions & 2 deletions samples/tube-cap.scad
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ holeDiameter = 30;
tubeDiameter = holeDiameter + 2 * thickness;
tubeDepth = 5;

// Sets the minimum facet angle and size using the defined render mode.
// Displays a build box visualization to preview the printer area.
buildBox(mode=renderMode) {
buildBox(center=true);

// Sets the minimum facet angle and size using the defined render mode.
applyMode(mode=renderMode) {
difference() {
union() {
pipe(d=tubeDiameter, w=thickness, h=tubeDepth + thickness);
Expand Down
6 changes: 3 additions & 3 deletions shape/3D/polyhedron.scad
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ module box(size, l, w, h, center) {
* @param Boolean [center] - Whether or not center the box on the vertical axis.
*/
module chamferedBox(size, chamfer, l, w, h, cl, cw, center) {
size = sizeBox(size=size, chamfer=chamfer, l=l, w=w, h=h, cl=cl, cw=cw);
linear_extrude(height=size.z, center=center, convexity=10) {
chamferedRectangle(size, chamfer);
size = sizeChamferedBox(size=size, chamfer=chamfer, l=l, w=w, h=h, cl=cl, cw=cw);
linear_extrude(height=size[0].z, center=center, convexity=10) {
chamferedRectangle(size=size[0], chamfer=size[1]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion shape/3D/rounded.scad
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ module roundedCornerWedge(size, r, h, d, p, convex, adjust, center) {
* @param Boolean [center] - Whether or not center the solid on the vertical axis.
*/
module link(neck, bulb, height, w, h, rx, ry, dx, dy, distance = 0, center=false) {
linear_extrude(height=height, center=center, convexity=10) {
linear_extrude(height=divisor(height), center=center, convexity=10) {
linkProfile(
neck = neck,
bulb = bulb,
Expand Down
Loading

0 comments on commit de24712

Please sign in to comment.