-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add point class (closes #76)
- Loading branch information
1 parent
ffa1343
commit 6b6bfde
Showing
6 changed files
with
549 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Vector } from "./Vector.js"; | ||
import { Circle } from "./Circle.js"; | ||
import { Line } from "./Line.js"; | ||
/** | ||
* Class representing a Point. | ||
*/ | ||
export class Point { | ||
/** | ||
* Create a Point. | ||
* @param {Vector} position | ||
* @param {string} [style = "circle"] | ||
*/ | ||
constructor(position, length = 0.25, style = "circle") { | ||
this.position = position; | ||
this.style = style; | ||
this.length = length; | ||
} | ||
|
||
/** | ||
* @returns {SVGElement} | ||
*/ | ||
toSVGElement() { | ||
let shape; | ||
switch (this.style) { | ||
case "circle": | ||
shape = new Circle(this.position.x, this.position.y, this.length); | ||
return shape.toSVGElement(); | ||
case "line": | ||
let length = new Vector(this.length, 0); | ||
let direction = 0; | ||
shape = new Line(this.position, Vector.add(this.position, length)); | ||
return shape.toSVGElement(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.