Skip to content

Commit

Permalink
feat(dimensionq): add angular dimension and more.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikjabiri committed Aug 24, 2022
1 parent b5cee5f commit df2b994
Show file tree
Hide file tree
Showing 52 changed files with 408 additions and 849 deletions.
6 changes: 1 addition & 5 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
};
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Ignore artifacts:
build
coverage
*/**/*.md
*.md
tsconfig.json
node_modules
www
lib
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"tabWidth": 4,
"semi": true,
"useTabs": true,
"bracketSameLine": true
"bracketSameLine": true,
"printWidth": 120
}
11 changes: 11 additions & 0 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ const { writeFileSync } = require('fs');
const d = new DxfWriter();
d.setVariable('$DIMTXT', { 40: 10 });
d.modelSpace.addRadialDim(point3d(0, 0, 0), point3d(100, 0, 0));
d.addAngularLinesDim(
{
start: point3d(200, 200),
end: point3d(200, 300),
},
{
start: point3d(300, 100),
end: point3d(400, 200),
},
point3d(300, 300)
);
const _str = d.stringify();
writeFileSync('examples/example.dxf', _str);
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
],
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@types/node": "^18.7.9",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"@types/node": "^18.7.11",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
"c8": "^7.12.0",
"del": "^7.0.0",
"esbuild": "^0.15.5",
Expand All @@ -40,7 +40,7 @@
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "^4.7.4",
"vitepress": "1.0.0-alpha.9",
"vitepress": "1.0.0-alpha.10",
"vitest": "^0.22.1",
"vue": "^3.2.37"
},
Expand Down
27 changes: 11 additions & 16 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import typescript from 'rollup-plugin-typescript2';
import dts from 'rollup-plugin-dts';
import { deleteAsync } from 'del';
import json from '@rollup/plugin-json';
import { readFileSync } from 'fs';
const { compilerOptions } = JSON.parse(readFileSync(new URL('./tsconfig.json', import.meta.url)));

function folderDelete(folders) {
return {
Expand All @@ -12,20 +14,6 @@ function folderDelete(folders) {
};
}

const tsconfigBuild = {
compilerOptions: {
declaration: true,
declarationDir: './lib',
moduleResolution: 'node',
esModuleInterop: true,
strict: true,
skipLibCheck: true,
noUnusedLocals: true,
types: ['vitest/globals'],
},
include: ['./src', './package.json'],
};

const esModule = {
file: 'lib/esm/index.js',
format: 'es',
Expand All @@ -37,7 +25,6 @@ const commonJs = {
};

const typescriptOptions = {
tsconfigDefaults: tsconfigBuild,
useTsconfigDeclarationDir: true,
};

Expand All @@ -54,6 +41,14 @@ export default [
{
input: './lib/src/index.d.ts',
output: [{ file: 'lib/index.d.ts', format: 'es' }],
plugins: [folderDelete(['./lib/src']), dts()],
plugins: [
folderDelete(['./lib/src']),
dts({
compilerOptions: {
baseUrl: './lib/src',
paths: compilerOptions.paths,
},
}),
],
},
];
57 changes: 12 additions & 45 deletions specs/DxfWriter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, expect, it } from 'vitest';
import { LWPolylineFlags, lwPolylineVertex_t, point2d, point3d } from '../src';
import { DxfWriter } from 'src/DxfWriter';
import { LWPolylineFlags, LWPolylineVertex, point2d, point3d } from '../src';
import { DxfWriter } from 'DxfWriter';

describe('DxfWriter class', () => {
describe('DxfWriter', () => {
it('should cover all code source', () => {
const dxf = new DxfWriter();
dxf.addPoint(0, 0, 0);
const vertices: lwPolylineVertex_t[] = [
const vertices: LWPolylineVertex[] = [
{
point: point2d(0, 0),
startingWidth: 5,
Expand Down Expand Up @@ -45,19 +45,11 @@ describe('DxfWriter class', () => {

const circleBlock = dxf.addBlock('circle');
circleBlock.addCircle(point3d(0, 0, 0), 50);
circleBlock.addRectangle(
point2d(-35.3553, 35.3553),
point2d(35.3553, -35.3553)
);
circleBlock.addRectangle(point2d(-35.3553, 35.3553), point2d(35.3553, -35.3553));

dxf.addInsert(circleBlock.name, point3d(0, 0, 0));

const controlPoints = [
point3d(0, 0, 0),
point3d(10, 10, 0),
point3d(20, 10, 0),
point3d(30, 20, 0),
];
const controlPoints = [point3d(0, 0, 0), point3d(10, 10, 0), point3d(20, 10, 0), point3d(30, 20, 0)];

dxf.addSpline({
controlPoints,
Expand All @@ -66,20 +58,9 @@ describe('DxfWriter class', () => {

dxf.addArc(point3d(0, 0, 0), 10, 0, 45);

dxf.addEllipse(
point3d(100, 100, 0),
point3d(50, 0, 0),
0.5,
0,
2 * Math.PI
);

const face = dxf.add3dFace(
point3d(0, 0, 50),
point3d(0, 100, 50),
point3d(100, 100, 50),
point3d(100, 0, 50)
);
dxf.addEllipse(point3d(100, 100, 0), point3d(50, 0, 0), 0.5, 0, 2 * Math.PI);

const face = dxf.add3dFace(point3d(0, 0, 50), point3d(0, 100, 50), point3d(100, 100, 50), point3d(100, 0, 50));
face.setEdgesVisible(true);
face.setFirstEdgeVisible(false);
face.setSecondEdgeVisible(true);
Expand All @@ -90,23 +71,9 @@ describe('DxfWriter class', () => {

dxf.addCircle(point3d(0, 0, 0), 50);

dxf.addPolyline3D([
point3d(0, 0, 0),
point3d(50, 40, 0),
point3d(70, 63, 2),
]);

dxf.addPolyline3D([point2d(0, 0), point2d(50, 40), point2d(70, 63)]);

dxf.addImage(
'.\\test - image.png',
'test - image',
point3d(700, 600, 0),
1792,
1280,
433.54,
360 - 359.74
);
dxf.addPolyline3D([{ point: point3d(0, 0, 0) }, { point: point3d(50, 40, 0) }, { point: point3d(70, 63, 2) }]);

dxf.addImage('.\\test - image.png', 'test - image', point3d(700, 600, 0), 1792, 1280, 433.54, 360 - 359.74);

dxf.tables.addView({
name: 'testview',
Expand Down
27 changes: 3 additions & 24 deletions specs/Sections/Entities/Entities/Ellipse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,15 @@ describe('Ellipse', () => {
};

it('should return the center given.', () => {
const entity = new Ellipse(
point3d(10, 1250, 63.3),
point3d(100, 50, 0),
0.4243,
0,
2 * Math.PI,
{}
);
const entity = new Ellipse(point3d(10, 1250, 63.3), point3d(100, 50, 0), 0.4243, 0, 2 * Math.PI, {});
dataState.instancesCount++;
expect(entity.center.x).toBe(10);
expect(entity.center.y).toBe(1250);
expect(entity.center.z).toBe(63.3);
});

it('should return the given parameters', () => {
const entity = new Ellipse(
point3d(10, 1250, 63.3),
point3d(100, 50, 0),
0.4243,
0,
2 * Math.PI,
{}
);
const entity = new Ellipse(point3d(10, 1250, 63.3), point3d(100, 50, 0), 0.4243, 0, 2 * Math.PI, {});
dataState.instancesCount++;
expect(entity.endPointOfMajorAxis.x).toBe(100);
expect(entity.endPointOfMajorAxis.y).toBe(50);
Expand All @@ -41,14 +27,7 @@ describe('Ellipse', () => {
});

it('should return the correct dxf string.', () => {
const entity = new Ellipse(
point3d(10, 1250, 63.3),
point3d(100, 50, 0),
0.4243,
0,
2 * Math.PI,
{}
);
const entity = new Ellipse(point3d(10, 1250, 63.3), point3d(100, 50, 0), 0.4243, 0, 2 * Math.PI, {});
dataState.instancesCount++;
const handle = dataState.instancesCount.toString(16).toUpperCase();
let entityString = `0\nELLIPSE\n5\n${handle}\n100\nAcDbEntity\n8\n0\n100\nAcDbEllipse\n`;
Expand Down
16 changes: 2 additions & 14 deletions specs/Sections/Entities/Entities/Face.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ describe('Face', () => {
};

it('should return the point given.', () => {
const entity = new Face(
point3d(0, 0, 50),
point3d(3, 0, 0),
point3d(0, 2, 0),
point3d(90, 0, 0),
{}
);
const entity = new Face(point3d(0, 0, 50), point3d(3, 0, 0), point3d(0, 2, 0), point3d(90, 0, 0), {});
dataState.instancesCount++;
expect(entity.firstCorner.x).toBe(0);
expect(entity.firstCorner.y).toBe(0);
Expand All @@ -35,13 +29,7 @@ describe('Face', () => {
});

it('should return the correct dxf string.', () => {
const entity = new Face(
point3d(0, 0, 50),
point3d(3, 0, 0),
point3d(0, 2, 0),
point3d(90, 0, 0),
{}
);
const entity = new Face(point3d(0, 0, 50), point3d(3, 0, 0), point3d(0, 2, 0), point3d(90, 0, 0), {});
dataState.instancesCount++;
const handle = dataState.instancesCount.toString(16).toUpperCase();
let entityString = `0\n3DFACE\n5\n${handle}\n100\nAcDbEntity\n8\n0\n100\nAcDbFace\n`;
Expand Down
18 changes: 4 additions & 14 deletions specs/Sections/Entities/Entities/LWPolyline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,17 @@ describe('Polyline', () => {
};

it('should return the given parameters.', () => {
const entity = new LWPolyline(
[{ point: point2d(0, 0) }, { point: point2d(120, 54) }],
{}
);
const entity = new LWPolyline([{ point: point2d(0, 0) }, { point: point2d(120, 54) }], {});
dataState.instancesCount++;
expect(entity.vertices).toEqual([
{ point: point2d(0, 0) },
{ point: point2d(120, 54) },
]);
expect(entity.vertices).toEqual([{ point: point2d(0, 0) }, { point: point2d(120, 54) }]);
});

it('should return the correct dxf string.', function () {
const entity = new LWPolyline(
[{ point: point2d(0, 0) }, { point: point2d(120, 54) }],
{}
);
const entity = new LWPolyline([{ point: point2d(0, 0) }, { point: point2d(120, 54) }], {});
dataState.instancesCount++;
const handle = dataState.instancesCount.toString(16).toUpperCase();
let entityString = `0\nLWPOLYLINE\n5\n${handle}\n100\nAcDbEntity\n8\n0\n100\nAcDbPolyline\n`;
entityString +=
'90\n2\n70\n0\n43\n0\n38\n0\n39\n0\n10\n0\n20\n0\n10\n120\n20\n54';
entityString += '90\n2\n70\n0\n43\n0\n38\n0\n39\n0\n10\n0\n20\n0\n10\n120\n20\n54';
const dx = new Dxifier();
entity.dxify(dx);
expect(dx.stringify()).toBe(entityString);
Expand Down
12 changes: 2 additions & 10 deletions specs/Sections/Entities/Entities/Line.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ describe('Line', () => {
};

it('should return the given points.', () => {
const entity = new Line(
point3d(0, 0, 0.22),
point3d(125, 85.23, 0.336),
{}
);
const entity = new Line(point3d(0, 0, 0.22), point3d(125, 85.23, 0.336), {});
dataState.instancesCount++;
expect(entity.startPoint.x).toBe(0);
expect(entity.startPoint.y).toBe(0);
Expand All @@ -25,11 +21,7 @@ describe('Line', () => {
});

it('should return the correct dxf string.', () => {
const entity = new Line(
point3d(1.32, 1, 0.22),
point3d(135, 855.23, 0.336),
{}
);
const entity = new Line(point3d(1.32, 1, 0.22), point3d(135, 855.23, 0.336), {});
dataState.instancesCount++;
const handle = dataState.instancesCount.toString(16).toUpperCase();
let entityString = `0\nLINE\n5\n${handle}\n100\nAcDbEntity\n8\n0\n100\nAcDbLine\n`;
Expand Down
10 changes: 2 additions & 8 deletions specs/Sections/Entities/Entities/Point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ describe('Point', () => {
});

it('should return the correct dxf string.', () => {
const entity = new Point(
24445787874545.336,
47854548454.54874,
0.14111122215556,
{}
);
const entity = new Point(24445787874545.336, 47854548454.54874, 0.14111122215556, {});
dataState.instancesCount++;
const handle = dataState.instancesCount.toString(16).toUpperCase();
let entityString = `0\nPOINT\n5\n${handle}\n100\nAcDbEntity\n8\n0\n100\nAcDbPoint\n`;
entityString +=
'10\n24445787874545.336\n20\n47854548454.54874\n30\n0.14111122215556';
entityString += '10\n24445787874545.336\n20\n47854548454.54874\n30\n0.14111122215556';
const dx = new Dxifier();
entity.dxify(dx);
expect(dx.stringify()).toBe(entityString);
Expand Down
17 changes: 7 additions & 10 deletions specs/Sections/Entities/Entities/Polyline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ describe('Polyline3D', () => {
const dataState = {
instancesCount: 0,
};
it('should return the subClassName given.', () => {
const entity = new Polyline([point3d(0, 0, 0), point3d(120, 54, 45)]);
dataState.instancesCount++;
expect(entity.subclassMarker).toBe('AcDb3dPolyline');
});

it('should return the given parameters.', () => {
const entity = new Polyline([
point3d(121.326, 0.4152, 8787),
point3d(120, 5544, 45),
]);
dataState.instancesCount++;
expect(entity.flags).toBe(0);
expect(entity.vertices).toEqual([
point3d(121.326, 0.4152, 8787),
point3d(120, 5544, 45),
]);
const entity = new Polyline([{ point: point3d(121.326, 0.4152, 8787) }, { point: point3d(120, 5544, 45) }]);
expect(entity.vertices.length).toBe(2);
});

/*it('should return the correct dxf string.', function () {
Expand Down
Loading

0 comments on commit df2b994

Please sign in to comment.