From 1b00c58ce4fcc1c05fac05b85ea2f8d14030afc7 Mon Sep 17 00:00:00 2001 From: Acbox <850625057@qq.com> Date: Sat, 8 Apr 2023 21:07:49 +0800 Subject: [PATCH] [feat]The API of object `Line` --- README.md | 2 +- packages/objects/src/lib/line.ts | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0c59d51ac..c98e54eda 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Newcar is a modern animation engine. This repository basically contains a renderer using HTML Canvas API to render. **This repository cannot deal with the newcar filetype.** ## Document -The document is served on [newcar-docs.netlify.app](https://newcar-docs.netlify.app). +The document is served on [newcar.js.org](https://newcar.js.org). ## Contribution If you want to join the development or make a contribution, **please read the [Contribution Guide](./doc/README.md)** diff --git a/packages/objects/src/lib/line.ts b/packages/objects/src/lib/line.ts index ab2076513..fb4e58c30 100644 --- a/packages/objects/src/lib/line.ts +++ b/packages/objects/src/lib/line.ts @@ -3,16 +3,19 @@ import { type Point } from "./point"; import { type carobject } from "./carobj"; import { IPositionedMut } from "src/interfaces/Positioned"; -export type lineobject = { points: Point[] }; +export type lineobject = { + startPoint: Point; + endPoint: Point; +}; export class Line extends Carobj implements IPositionedMut { - #point1: Point; - #point2: Point; + #startPoint: Point; + #endPoint: Point; constructor(datas: lineobject & carobject) { super(datas); - this.#point1 = datas.points[0]; - this.#point2 = datas.points[1]; + this.#startPoint = datas.startPoint; + this.#endPoint = datas.endPoint; } override onDraw(ctx: CanvasRenderingContext2D) { @@ -25,22 +28,22 @@ export class Line extends Carobj implements IPositionedMut { } get primaryPoints() { - return [this.#point1, this.#point2]; + return [this.#startPoint, this.#endPoint]; } set startX(value: number) { - this.#point1.x = value; + this.#startPoint.x = value; } set startY(value: number) { - this.#point1.y = value; + this.#startPoint.y = value; } set endX(value: number) { - this.#point2.x = value; + this.#endPoint.x = value; } set endY(value: number) { - this.#point2.y = value; + this.#endPoint.y = value; } }