Skip to content

Feature/hatch patterns - #318

Merged
dubstar-04 merged 27 commits into
mainfrom
feature/hatch-patterns
May 23, 2026
Merged

Feature/hatch patterns#318
dubstar-04 merged 27 commits into
mainfrom
feature/hatch-patterns

Conversation

@dubstar-04

@dubstar-04 dubstar-04 commented May 3, 2026

Copy link
Copy Markdown
Owner

Add support for user defined and custom hatch patterns.

fixes dubstar-04/Design#437

@dubstar-04 dubstar-04 linked an issue May 3, 2026 that may be closed by this pull request
@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.22807% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.95%. Comparing base (3a71513) to head (be0f738).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
core/entities/hatch.js 91.83% 7 Missing and 1 partial ⚠️
core/entities/insert.js 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #318      +/-   ##
==========================================
+ Coverage   91.87%   91.95%   +0.08%     
==========================================
  Files         128      128              
  Lines        9352     9451      +99     
  Branches     1966     2003      +37     
==========================================
+ Hits         8592     8691      +99     
- Misses        684      685       +1     
+ Partials       76       75       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for user-defined and custom hatch patterns, including parsing/writing inline DXF hatch pattern definitions and exposing additional hatch-related properties for UI/editing. This fits into the CAD core by extending Hatch DXF round-tripping and property handling, plus a few related robustness tweaks (zoom-to-window guard, missing block handling).

Changes:

  • Extend Hatch to support DXF pattern type (group code 76) with inline pattern lines (user-defined/custom) and library pattern cloning.
  • Add hatch-specific properties (hatchSpacing, hatchDouble) and support callable readOnly evaluation in the property system.
  • Add/extend Jest coverage for hatch patterns and property manager helpers; update spellchecker dictionary.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/properties/propertyManager.test.js Adds tests for new PropertyManager helper methods and callback behaviour.
test/entities/hatch.test.js Adds tests for unknown patterns, patternLines behaviour, inline DXF parsing, and DXF output for code 76/78.
cspell.json Adds hatch-related tokens to cspell word list.
core/tables/block.js Changes Block.boundingBox() behaviour for empty blocks.
core/properties/propertyManager.js Adds getEntityForProperty() helper for resolving an entity to evaluate property metadata/readOnly.
core/properties/property.js Adjusts Property.value setter semantics when readOnly is callable.
core/properties/entityProperties.js Evaluates callable readOnly(entity) when setting properties.
core/lib/canvas.js Guards zoom-to-window scale calculation against non-finite/invalid scale deltas.
core/entities/insert.js Logs warning when referenced block is missing; adjusts bounding box behaviour for empty blocks.
core/entities/hatch.js Implements inline/user-defined/custom hatch pattern handling, caching, DXF 76/77/78 handling, and pattern selection options.
Comments suppressed due to low confidence (1)

core/tables/block.js:272

  • Block.boundingBox() now returns null when entities is empty, but the method is documented as returning BoundingBox and inherited methods like Entity.within() assume boundingBox() is non-null. Also, the loop does not guard against child entities returning null bounding boxes (e.g. Insert.boundingBox() can now return null), which will throw when accessing entityBoundingBox.xMin. Consider returning an empty BoundingBox for empty blocks (consistent with other entities) and/or skipping null child bounding boxes (similar to BoundingBox.fromEntities).
  boundingBox() {
    if (!this.entities.length) return null;

    let xmin = Infinity;
    let xmax = -Infinity;
    let ymin = Infinity;
    let ymax = -Infinity;

    for (let idx = 0; idx < this.entities.length; idx++) {
      const entityBoundingBox = this.entities[idx].boundingBox();

      xmin = Math.min(xmin, entityBoundingBox.xMin);
      xmax = Math.max(xmax, entityBoundingBox.xMax);
      ymin = Math.min(ymin, entityBoundingBox.yMin);
      ymax = Math.max(ymax, entityBoundingBox.yMax);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/entities/insert.js Outdated
*/
boundingBox() {
const blockBB = this.block.boundingBox();
if (!blockBB) return null;
Comment thread core/entities/hatch.js Outdated
// User-defined hatches (76=0) are normalised to the sentinel name 'U'
// so the pattern type is implied by the name rather than stored separately.
const resolvedPatternName = data?.[70] === 1 ? 'SOLID' : patternType === 0 ? 'U' : rawPatternName;
if (resolvedPatternName !== 'U' && !Patterns.patternExists(resolvedPatternName)) {
Comment thread core/entities/hatch.js
Comment on lines +196 to +205
/**
* Build PatternLine objects from inline DXF pattern data (group code 76 = 0 or 2).
* DXF stores deltas pre-multiplied by scale; we divide by scale and convert
* inches→mm (×25.4) to match the library's mm-based PatternLine format.
* @param {Object} data - raw DXF group-code data for the HATCH entity
* @return {Array<PatternLine>} array of PatternLine objects
*/
#buildInlinePatternLines(data) {
const scale = data[41] ?? 1;
// DXF group code 53 per-family angles are written by AutoCAD as absolute
@dubstar-04
dubstar-04 marked this pull request as ready for review May 23, 2026 11:04
@dubstar-04
dubstar-04 merged commit 1d96eb6 into main May 23, 2026
2 of 3 checks passed
@dubstar-04
dubstar-04 deleted the feature/hatch-patterns branch May 23, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hatch Pattern Fixes Hatch in dxf file & Viewer are not same

2 participants