Skip to content

Commit d049d5f

Browse files
authored
Merge pull request #8 from jgphilpott/copilot/fix-d634d99a-353b-454a-b7e8-0f35fc8b4c0e
Convert Polyslice to universal Node.js/browser package with CoffeeScript-first development
2 parents d115125 + 03e8954 commit d049d5f

25 files changed

+7381
-587
lines changed

.eslintrc.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": [
9+
"eslint:recommended"
10+
],
11+
"parserOptions": {
12+
"ecmaVersion": 12,
13+
"sourceType": "module"
14+
},
15+
"rules": {
16+
"indent": ["error", 2],
17+
"linebreak-style": ["error", "unix"],
18+
"quotes": ["error", "single"],
19+
"semi": ["error", "always"],
20+
"no-unused-vars": "warn",
21+
"no-console": "off"
22+
}
23+
}

.github/FUNDING.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
# These are the supported funding platforms:
22

33
github: [jgphilpott] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4-
patreon: # Replace with a single Patreon username
5-
open_collective: # Replace with a single Open Collective username
6-
ko_fi: # Replace with a single Ko-fi username
7-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9-
liberapay: # Replace with a single Liberapay username
10-
issuehunt: # Replace with a single IssueHunt username
11-
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12-
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13-
14-
# More info: docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository#about-funding-files
4+
custom: ["https://www.buymeacoffee.com/jgphilpott"] # Custom sponsorship URLs for Buy Me a Coffee.

.github/ISSUE_TEMPLATE/BUG_REPORT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ Please include the following information:
3838

3939
### Extra:
4040

41-
Add any other information about the problem here.
41+
Add any other information about the problem here.

.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Add a clear and concise description of any alternative solutions or features you
2020

2121
### Additional Information:
2222

23-
Add any extra information about your feature request here.
23+
Add any extra information about your feature request here.

.github/ISSUE_TEMPLATE/QUESTION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ assignees: jgphilpott
88

99
### Question:
1010

11-
Type your question here.
11+
Type your question here.

.github/WORKFLOWS/CHECKS.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
applyTo: '*.coffee'
3+
---
4+
5+
# CoffeeScript Contribution Instructions
6+
7+
These guidelines apply to all CoffeeScript source edits in this repository.
8+
9+
## Code Style: Indentation
10+
11+
- Use 4-space indentation for all code blocks (consistent with `.editorconfig`).
12+
- All indentation must be multiples of 4 spaces (4, 8, 12, 16, etc.).
13+
14+
## Code Style: Whitespace and Vertical Spacing
15+
16+
- Preserve and prefer generous vertical whitespace for readability.
17+
- Insert a blank line after the following situations:
18+
- function declarations/definitions
19+
- if/else blocks
20+
- loops
21+
- any change in indentation level
22+
- variable assignments before object creation/manipulation
23+
- between logical groups within functions
24+
- Do not collapse existing blank lines when editing.
25+
- In helper functions, add blank lines to separate logical groups (geometry creation, mesh setup, return statements).
26+
- Remove trailing whitespace consistently.
27+
- Always insert final newline at the end of files (consistent with `.editorconfig`).
28+
29+
If you are unsure, prefer the more spacious option to maintain consistency with the existing style.
30+
31+
## Variable Naming Conventions
32+
33+
- Follow standard JavaScript camelCase naming conventions for all variables.
34+
- **Do not use leading underscores** (`_variableName`) unless it's a true private convention.
35+
- **Use descriptive, full-form variable names** instead of cryptic abbreviations:
36+
- ✅ Good: `for previousState in previousStates`
37+
- ❌ Bad: `for s in previousStates`
38+
- ✅ Good: `temporaryVertex`, `currentPolygon`
39+
- ❌ Bad: `tmpV`, `curPoly`
40+
- Prefer clarity over brevity - code is read more often than written.
41+
42+
## G-code Generation Guidelines
43+
44+
- Maintain consistency with existing G-code command naming conventions.
45+
- Use descriptive method names like `codeLinearMovement`, `codeAutohome`.
46+
- Include proper G-code comments and references to Marlin documentation.
47+
- Ensure all temperature, speed, and coordinate parameters are validated.
48+
49+
## Test Code Style Preferences
50+
51+
- Add blank lines after geometry/material creation and before mesh creation.
52+
- Add blank lines after mesh setup and before return statements.
53+
- Align inline comments consistently using single space before # comment.
54+
- For comments explaining parameters, add period after comment for complete sentences.
55+
- Maintain consistent spacing around assignment operators.
56+
- Prefer single-line variable assignments with proper spacing.
57+
58+
## Reserved Word Note (Project Convention)
59+
60+
CoffeeScript reserves certain identifiers (e.g. `by` used in loop syntax). When needing coordinate component variables that might conflict, prefer capitalized suffix forms:
61+
62+
- Use `aX, aY, aZ` / `bX, bY, bZ` instead of `ax, ay, az` / `bx, by, bz` when there is risk of `by` being parsed as the keyword.
63+
- This avoids accidental parse errors in inline multi-assignment statements.
64+
65+
Adopt this naming in new geometry or test code when generating random coordinates.
66+
67+
## Three.js Integration
68+
69+
- When working with three.js objects, maintain clear separation between mesh processing and G-code generation.
70+
- Use proper three.js naming conventions for geometry manipulation.
71+
- Ensure mesh data extraction is compatible with both Node.js and browser environments.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
applyTo: '**'
3+
---
4+
5+
- Keep code DRY (Don't Repeat Yourself).
6+
- Use descriptive variable and function names.
7+
- Follow the existing code style and conventions.
8+
- Use double quotes on strings by default and single quotes inside strings.
9+
- Maintain compatibility with both Node.js and browser environments.
10+
- Preserve the existing G-code generation functionality.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Refactoring Guidelines
2+
3+
## Browser/Node.js Compatibility
4+
5+
- Ensure all code works in both Node.js and browser environments
6+
- Use feature detection rather than environment detection where possible.
7+
- Avoid Node.js-specific APIs in core functionality.
8+
- Test exports work correctly in both CommonJS and browser global contexts.
9+
10+
## G-code Generation
11+
12+
- Maintain backward compatibility for existing G-code methods.
13+
- Keep G-code output format consistent with established standards.
14+
- Validate all numerical parameters before generating commands.
15+
- Include proper error handling for invalid inputs.
16+
17+
## Three.js Integration
18+
19+
- Keep three.js integration optional and modular.
20+
- Ensure mesh processing doesn't break existing functionality.
21+
- Support both geometry and buffer geometry where applicable.
22+
- Handle coordinate system conversions properly.
23+
24+
## Performance Considerations
25+
26+
- Minimize string concatenation in G-code generation loops.
27+
- Use efficient algorithms for mesh processing.
28+
- Consider memory usage when processing large geometries.
29+
- Profile critical paths and optimize as needed.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Testing Guidelines
2+
3+
These notes define conventions and coverage expectations for the test suite.
4+
5+
## Framework
6+
7+
- Use Jest (already configured).
8+
- JavaScript test sources run directly with Jest.
9+
10+
## File / Naming
11+
12+
- Name pattern: `*.test.js`.
13+
- One logical unit per file (e.g. `polyslice.test.js`).
14+
- All helpers from the main class share a single consolidated test file (append new helper tests at bottom, do not create a separate file).
15+
16+
## Structure
17+
18+
- Use a small helper factory for repetitive data construction (e.g. `slicer()`).
19+
- Keep assertion helpers local (no global shared unless reused across 3+ files).
20+
- Avoid hidden magic numbers; define `EPS`, `TOL`, etc. at top of file.
21+
- Place any new shared helper functions (e.g. geometry builders, orientation wrappers) near the TOP of the consolidated test file so subsequent describe blocks can reuse them.
22+
- Formatting / Whitespace: Insert a blank line immediately after each `describe` declaration line and after each `it` line (before the body) to maintain generous vertical whitespace consistent with JavaScript style.
23+
24+
## Assertions
25+
26+
- Prefer strict equality expectations for G-code output validation.
27+
- When testing floating-point calculations (e.g., fan speeds), use appropriate precision handling.
28+
- Test both Node.js and browser environments when applicable.
29+
30+
## Coverage Expectations (G-code Generation)
31+
32+
Polyslice tests must include:
33+
34+
1. **Constructor and Options**
35+
- Default values initialization
36+
- Custom options handling
37+
- Invalid parameter rejection
38+
39+
2. **Parameter Setters/Getters**
40+
- Valid range checking
41+
- Type validation
42+
- Chaining behavior
43+
44+
3. **G-code Command Generation**
45+
- Basic movement commands (G0, G1)
46+
- Temperature control (M104, M109, M140, M190)
47+
- Fan control (M106, M107)
48+
- Home commands (G28)
49+
- Workspace plane setting (G17, G18, G19)
50+
- Unit setting (G20, G21)
51+
- Arc movements (G2, G3)
52+
- Bézier curves (G5)
53+
- Special commands (M117, M112, etc.)
54+
55+
4. **Environment Compatibility**
56+
- Node.js environment tests
57+
- Browser environment compatibility (when applicable)
58+
- Three.js integration tests
59+
60+
5. **Edge Cases**
61+
- Zero values handling
62+
- Maximum/minimum parameter values
63+
- Invalid parameter handling
64+
- Floating-point precision
65+
66+
Future (add later):
67+
68+
- Random fuzz testing for parameter validation
69+
- Stress test with large coordinate values
70+
- Performance benchmarks for G-code generation
71+
- Integration tests with actual three.js meshes
72+
- Browser environment automated testing
73+
74+
## Floating Point
75+
76+
- Use tolerance constant (default `1e-6`) for floating-point comparisons.
77+
- Do not equality-compare raw floats except against `0` with documented intent.
78+
- For fan speed calculations, test the actual rounded output values.
79+
80+
## Environment Testing
81+
82+
- Test CommonJS imports (`require`)
83+
- Test ES module imports (`import`) when applicable
84+
- Verify browser global availability
85+
- Test three.js integration in both environments
86+
87+
## DRY Principles
88+
89+
- Shared helper naming: `slicer()`, `assertGCode()`.
90+
- Keep helpers minimal; do not abstract prematurely.
91+
- If helper exceeds ~30 LOC or becomes multi-purpose, split.
92+
93+
## Test Output Clarity
94+
95+
- Include descriptive test names that explain what is being tested.
96+
- Use meaningful variable names in test setup.
97+
- Include comments for non-obvious expectations (especially G-code format specifics).
98+
99+
## Adding New G-code Tests
100+
101+
When adding a new G-code command or feature:
102+
103+
1. List expected G-code output format in comment header.
104+
2. Implement parameter validation tests first.
105+
3. Write "happy path" test with expected output.
106+
4. Test edge cases and invalid parameters.
107+
5. Add regression tests for any bugs fixed.
108+
109+
## Performance / Stability
110+
111+
- Long-running test suites should be opt-in via `process.env.LONG_TESTS`.
112+
- Default `npm test` must remain fast (< 5s typical).
113+
- Browser compatibility tests should be separate from core functionality tests.
114+
115+
## Lint / Style
116+
117+
- Follow JavaScript/ESLint formatting guidelines.
118+
- Keep tests readable over condensed.
119+
- Use descriptive assertion messages.
120+
121+
## TODO Tags
122+
123+
- Allowed only with issue reference: `# TODO(#123): add browser integration tests`.

0 commit comments

Comments
 (0)