From 8afc46bd48d3c4db88808936b32ee1e1aa6e1dcb Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Sun, 14 Aug 2022 22:55:46 -0700 Subject: [PATCH] fix typescript type errors, sketchModel --- modules/math/vectorFactory.ts | 4 ++-- modules/ui/components/Row.jsx | 2 +- web/app/cad/sketch/sketchModel.ts | 36 +++++++++++++++++------------- web/app/cad/sketch/sketchReader.ts | 27 ++++++---------------- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/modules/math/vectorFactory.ts b/modules/math/vectorFactory.ts index dc94614d..b0f3f42f 100644 --- a/modules/math/vectorFactory.ts +++ b/modules/math/vectorFactory.ts @@ -5,7 +5,7 @@ export default class VectorFactory { vectors: Vector[]; - constructor(tolerance) { + constructor() { this.vectors = []; } @@ -24,7 +24,7 @@ export default class VectorFactory { return null; } - create(x, y, z, onExistent): Vector { + create(x, y, z, onExistent?): Vector { let vector = this.find(x, y, z); if (vector === null) { vector = new Vector(x, y, z); diff --git a/modules/ui/components/Row.jsx b/modules/ui/components/Row.jsx index 7ee45324..18df31d6 100644 --- a/modules/ui/components/Row.jsx +++ b/modules/ui/components/Row.jsx @@ -2,6 +2,6 @@ import React from 'react'; import ls from './Row.less'; import cx from 'classnames'; -export default function Row({className, props, children}) { +export default function Row({className, children, ...props}) { return
{children}
; } \ No newline at end of file diff --git a/web/app/cad/sketch/sketchModel.ts b/web/app/cad/sketch/sketchModel.ts index 2d1278c4..1d4b3da3 100644 --- a/web/app/cad/sketch/sketchModel.ts +++ b/web/app/cad/sketch/sketchModel.ts @@ -11,7 +11,7 @@ import {OCCCommandInterface} from "cad/craft/e0/occCommandInterface"; const RESOLUTION = 20; -class SketchPrimitive { +export class SketchPrimitive { id: string; inverted: boolean; @@ -195,6 +195,11 @@ export class Arc extends SketchPrimitive { } export class BezierCurve extends SketchPrimitive { + a: Vector; + b: Vector; + cp1: Vector; + cp2: Vector; + constructor(id, a, b, cp1, cp2) { super(id); this.a = a; @@ -209,6 +214,14 @@ export class BezierCurve extends SketchPrimitive { } export class EllipticalArc extends SketchPrimitive { + + c: Vector; + rx: number; + ry: number; + rot: number + a: Vector; + b: Vector; + constructor(id, c, rx, ry, rot, a, b) { super(id); this.c = c; @@ -266,6 +279,12 @@ export class Circle extends SketchPrimitive { } export class Ellipse extends SketchPrimitive { + + c: Vector; + rx: number; + ry: number; + rot: number + constructor(id, c, rx, ry, rot) { super(id); this.c = c; @@ -345,21 +364,6 @@ export class Contour { } } -class CompositeCurve { - - constructor() { - this.curves = []; - this.points = []; - this.groups = []; - } - - add(curve, point, group) { - this.curves.push(curve); - this.points.push(point); - this.groups.push(group); - } -} - function adjustEnds(arc, a, b) { let data = arc.asNurbs(); diff --git a/web/app/cad/sketch/sketchReader.ts b/web/app/cad/sketch/sketchReader.ts index 8b0e78e6..5a13bdde 100644 --- a/web/app/cad/sketch/sketchReader.ts +++ b/web/app/cad/sketch/sketchReader.ts @@ -5,14 +5,15 @@ import Joints from 'gems/joints'; import sketchObjectGlobalId from './sketchObjectGlobalId'; import VectorFactory from 'math/vectorFactory'; import {strictEqual2D} from "math/equality"; -import {Contour, Segment} from "./sketchModel"; +import {Contour, Segment, SketchPrimitive} from "./sketchModel"; +import Vector from "math/vector"; export class SketchGeom { - private connections: Segment[]; - private loops: Segment[]; - private constructionSegments: Segment[]; - private _contours: Contour[]; + connections: SketchPrimitive[]; + loops: SketchPrimitive[]; + constructionSegments: SketchPrimitive[]; + _contours: Contour[]; constructor() { this.connections = []; @@ -31,20 +32,6 @@ export class SketchGeom { get contours(): Contour[] { return this.fetchContours(); } - - findById(id) { - function _find() { - for (let arr of arguments) { - for (let segment of arr) { - if (segment.id === id) { - return segment; - } - } - } - return null; - } - return _find(this.connections, this.loops, this.constructionSegments); - } getAllObjects() { return [...this.connections, ...this.loops, ...this.constructionSegments]; @@ -69,7 +56,7 @@ export function ReadSketch(sketch, sketchId, readConstructionSegments) { } let vectorFactory = new VectorFactory(); let pointsById = new Map(); - function ReadSketchPoint(pt) { + function ReadSketchPoint(pt): Vector { return vectorFactory.create(pt.x, pt.y, 0); } if (sketch.version !== 3) {