Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
[feat]The API of object Line
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Apr 8, 2023
1 parent ec71105 commit 1b00c58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)**
Expand Down
23 changes: 13 additions & 10 deletions packages/objects/src/lib/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}

0 comments on commit 1b00c58

Please sign in to comment.