Skip to content

Commit

Permalink
refactor(plotter, renderer): add proof-of-concept renderer (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Jul 10, 2022
1 parent c78492d commit b7a8779
Show file tree
Hide file tree
Showing 85 changed files with 4,985 additions and 2,002 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@35ab4267a1a21c8e8cb1c087cf1642e891ff57bd
with:
version: '7.0.0'
version: '7.5.0'
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
Expand All @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@35ab4267a1a21c8e8cb1c087cf1642e891ff57bd
with:
version: '7.0.0'
version: '7.5.0'
- uses: actions/setup-node@v3
with:
node-version: '16'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage
*.tgz
.vscode
.DS_Store
packages/cli/bin/*.d.ts
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ CHANGELOG.md
dist
lib
coverage
packages/cli/bin/*.d.ts
3 changes: 2 additions & 1 deletion config/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"isolatedModules": true
}
}
6 changes: 3 additions & 3 deletions config/vite.config.base.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {defineConfig} from 'vite'
import {UserConfig, defineConfig} from 'vite'

export const baseConfig = defineConfig({
export const baseConfig: UserConfig = defineConfig({
resolve: {
conditions: ['source'],
},
})
}) as UserConfig

export const getDefineConstants = (pkg: {
name: string
Expand Down
16 changes: 16 additions & 0 deletions config/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {expect} from 'vitest'

expect.extend({
approx(received: unknown, expected: number) {
const difference =
typeof received === 'number'
? Math.abs(received - expected)
: Number.POSITIVE_INFINITY

return {
message: () =>
`expected ${String(received)} to be approximately ${expected}`,
pass: difference < 1e-12,
}
},
})
32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"build": "concurrently -g pnpm:build:*",
"build:packages": "pnpm -r build",
"build:types": "tsc --build",
"clean": "concurrently -g pnpm:clean:*",
"clean:packages": "pnpm -r clean",
"clean:types": "tsc --build --clean",
"clean": "tsc --build --clean",
"dev": "pnpm -C www dev"
},
"engines": {
Expand All @@ -31,16 +29,15 @@
"whats-that-gerber": "workspace:*"
},
"devDependencies": {
"@types/node": "^17.0.30",
"c8": "^7.11.2",
"concurrently": "^7.1.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"testdouble": "^3.16.5",
"typescript": "^4.6.4",
"vite": "^2.9.6",
"vitest": "^0.10.0",
"xo": "^0.48.0"
"@types/node": "^18.0.1",
"c8": "^7.11.3",
"concurrently": "^7.2.2",
"prettier": "^2.7.1",
"testdouble": "^3.16.6",
"typescript": "^4.7.4",
"vite": "^2.9.13",
"vitest": "^0.17.0",
"xo": "^0.50.0"
},
"pnpm": {
"peerDependencyRules": {
Expand Down Expand Up @@ -74,6 +71,8 @@
"@typescript-eslint/naming-convention": "off",
"import/extensions": "off",
"unicorn/no-array-callback-reference": "off",
"unicorn/no-array-reduce": "off",
"n/file-extension-in-import": "off",
"default-case": "off"
},
"overrides": [
Expand All @@ -97,6 +96,8 @@
],
"rules": {
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/prefer-function-type": "off",
"import/no-unassigned-import": "off"
}
},
Expand All @@ -107,8 +108,11 @@
],
"rules": {
"@typescript-eslint/consistent-type-assertions": "off",
"@typescript-eslint/no-namespace": "off",
"import/no-extraneous-dependencies": "off",
"unicorn/no-array-for-each": "off"
"max-nested-callbacks": "off",
"unicorn/no-array-for-each": "off",
"unicorn/prefer-module": "off"
}
}
]
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"types": "lib/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "vite build",
"clean": "rimraf dist"
"build": "vite build"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function cli(
const typesByName = Wtg.identifyLayers(filenames)
const layers = filenames
.map(filename => makeLayerFromFilename(filename, typesByName))
.filter((ly): ly is InputLayer => Boolean(ly))
.filter((ly): ly is InputLayer => ly !== null)

if (layers.length === 0) {
throw new Error('No valid Gerber or drill files found')
Expand Down
18 changes: 9 additions & 9 deletions packages/fixtures/gerbers/pads/polygon.gbr
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
D10*
X0Y0D03*
D11*
X6000Y0D03*
X0Y6000D03*
D12*
X12000Y0D03*
X0Y12000D03*
D13*
X18000Y0D03*
X0Y18000D03*
D14*
X24000Y0D03*
X0Y24000D03*
D15*
X30000Y0D03*
X0Y30000D03*
D16*
X36000Y0D03*
X0Y36000D03*
D17*
X42000Y0D03*
X0Y42000D03*
D18*
X48000Y0D03*
X0Y48000D03*
D19*
X54000Y0D03*
X0Y54000D03*
M02*
3 changes: 1 addition & 2 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"directory": "packages/parser"
},
"scripts": {
"build": "vite build",
"clean": "rimraf dist"
"build": "vite build"
},
"keywords": [
"gerber",
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export function simplifyTokens(tokens: Token[]): Array<{
}

export function position(
start: [number, number, number],
end: [number, number, number]
start: [line: number, column: number, offset: number],
end: [line: number, column: number, offset: number]
): Position {
return {
start: {line: start[0], column: start[1], offset: start[2]},
Expand Down
4 changes: 3 additions & 1 deletion packages/parser/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export const MACRO_SHAPE = 'macroShape'

// Macro primitive codes
export const MACRO_CIRCLE = '1'
export const MACRO_VECTOR_LINE_DEPRECATED = '2'
export const MACRO_VECTOR_LINE = '20'
export const MACRO_CENTER_LINE = '21'
export const MACRO_LOWER_LEFT_LINE_DEPRECATED = '22'
export const MACRO_OUTLINE = '4'
export const MACRO_POLYGON = '5'
export const MACRO_MOIRE = '6'
export const MACRO_MOIRE_DEPRECATED = '6'
export const MACRO_THERMAL = '7'

// Drawing constants
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/syntax/__tests__/drill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ const SPECS: Array<{
type: Tree.GRAPHIC,
position: pos([1, 1, 0], [1, 16, 15]),
graphic: SLOT,
coordinates: {x1: '07', y1: '08', x2: '09', y2: '10'},
coordinates: {x0: '07', y0: '08', x: '09', y: '10'},
},
],
},
Expand All @@ -584,7 +584,7 @@ const SPECS: Array<{
type: Tree.GRAPHIC,
position: pos([1, 1, 0], [1, 10, 9]),
graphic: SLOT,
coordinates: {x1: '07', y2: '10'},
coordinates: {x0: '07', y: '10'},
},
],
},
Expand Down
55 changes: 45 additions & 10 deletions packages/parser/src/syntax/__tests__/gerber-macros.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
MACRO_CENTER_LINE,
MACRO_OUTLINE,
MACRO_POLYGON,
MACRO_MOIRE,
MACRO_MOIRE_DEPRECATED,
MACRO_THERMAL,
} from '../../constants'

Expand Down Expand Up @@ -85,7 +85,7 @@ const SPECS: Array<{
type: Tree.MACRO_PRIMITIVE,
position: pos([1, 11, 10], [1, 22, 21]),
code: MACRO_CIRCLE,
modifiers: [1, 0.5, 0, 0],
parameters: [1, 0.5, 0, 0],
},
],
},
Expand Down Expand Up @@ -126,7 +126,7 @@ const SPECS: Array<{
type: Tree.MACRO_PRIMITIVE,
position: pos([1, 11, 10], [1, 32, 31]),
code: MACRO_VECTOR_LINE,
modifiers: [1, 0.25, 0, 0, 0.5, 0.5, 0],
parameters: [1, 0.25, 0, 0, 0.5, 0.5, 0],
},
],
},
Expand Down Expand Up @@ -165,7 +165,7 @@ const SPECS: Array<{
type: Tree.MACRO_PRIMITIVE,
position: pos([1, 15, 14], [1, 34, 33]),
code: MACRO_CENTER_LINE,
modifiers: [1, 0.5, 0.25, 0, 0, 0],
parameters: [1, 0.5, 0.25, 0, 0, 0],
},
],
},
Expand Down Expand Up @@ -214,7 +214,7 @@ const SPECS: Array<{
type: Tree.MACRO_PRIMITIVE,
position: pos([1, 12, 11], [1, 41, 40]),
code: MACRO_OUTLINE,
modifiers: [1, 3, 0, 0, 0, 0.5, 0.5, 0.5, 0, 0, 0],
parameters: [1, 3, 0, 0, 0, 0.5, 0.5, 0.5, 0, 0, 0],
},
],
},
Expand Down Expand Up @@ -253,7 +253,7 @@ const SPECS: Array<{
type: Tree.MACRO_PRIMITIVE,
position: pos([1, 12, 11], [1, 27, 26]),
code: MACRO_POLYGON,
modifiers: [1, 5, 0, 0, 0.5, 0],
parameters: [1, 5, 0, 0, 0.5, 0],
},
],
},
Expand Down Expand Up @@ -297,8 +297,8 @@ const SPECS: Array<{
{
type: Tree.MACRO_PRIMITIVE,
position: pos([1, 10, 9], [1, 43, 42]),
code: MACRO_MOIRE,
modifiers: [0, 0, 0.5, 0.04, 0.03, 2, 0.01, 0.55, 0],
code: MACRO_MOIRE_DEPRECATED,
parameters: [0, 0, 0.5, 0.04, 0.03, 2, 0.01, 0.55, 0],
},
],
},
Expand Down Expand Up @@ -337,7 +337,7 @@ const SPECS: Array<{
type: Tree.MACRO_PRIMITIVE,
position: pos([1, 12, 11], [1, 31, 30]),
code: MACRO_THERMAL,
modifiers: [0, 0, 0.5, 0.4, 0.1, 0],
parameters: [0, 0, 0.5, 0.4, 0.1, 0],
},
],
},
Expand Down Expand Up @@ -448,7 +448,42 @@ $5=(1+(2-$4))x4*
type: Tree.MACRO_PRIMITIVE,
position: pos([6, 1, 59], [6, 14, 72]),
code: MACRO_CIRCLE,
modifiers: [1, {left: '$5', right: 1, operator: '+'}, '$2', 0],
parameters: [1, {left: '$5', right: 1, operator: '+'}, '$2', 0],
},
],
},
],
},
{
// Macro using `X` instead of `x` for multiplication
source: `%AMBAD_MULTIPLY*
$1=1X2*
%`,
expectedTokens: [
t(Lexer.PERCENT, '%'),
t(Lexer.GERBER_TOOL_MACRO, 'BAD_MULTIPLY'),
t(Lexer.ASTERISK, '*'),
t(Lexer.NEWLINE, '\n'),
t(Lexer.GERBER_MACRO_VARIABLE, '$1'),
t(Lexer.EQUALS, '='),
t(Lexer.NUMBER, '1'),
t(Lexer.COORD_CHAR, 'X'),
t(Lexer.NUMBER, '2'),
t(Lexer.ASTERISK, '*'),
t(Lexer.NEWLINE, '\n'),
t(Lexer.PERCENT, '%'),
],
expectedNodes: [
{
type: Tree.TOOL_MACRO,
position: pos([1, 2, 1], [2, 8, 24]),
name: 'BAD_MULTIPLY',
children: [
{
type: Tree.MACRO_VARIABLE,
position: pos([2, 1, 17], [2, 7, 23]),
name: '$1',
value: {left: 1, right: 2, operator: 'x'},
},
],
},
Expand Down
8 changes: 6 additions & 2 deletions packages/parser/src/syntax/__tests__/gerber-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ const SPECS: Array<{
type: Tree.TOOL_DEFINITION,
position: pos([1, 2, 1], [1, 14, 13]),
code: '23',
shape: {type: MACRO_SHAPE, name: 'MyMacro', params: []},
shape: {type: MACRO_SHAPE, name: 'MyMacro', variableValues: []},
hole: null,
},
],
Expand All @@ -386,7 +386,11 @@ const SPECS: Array<{
type: Tree.TOOL_DEFINITION,
position: pos([1, 2, 1], [1, 26, 25]),
code: '24',
shape: {type: MACRO_SHAPE, name: 'MyMacro', params: [0.1, 0.2, 0.3]},
shape: {
type: MACRO_SHAPE,
name: 'MyMacro',
variableValues: [0.1, 0.2, 0.3],
},
hole: null,
},
],
Expand Down

0 comments on commit b7a8779

Please sign in to comment.