42_ft_transcendence/frontend/static/js/api/game/Segment.js
2024-01-30 22:22:47 +01:00

42 lines
823 B
JavaScript

import { Point } from "./Point.js"
class Segment
{
/**
* @param {Point} start
* @param {Point} stop
*/
constructor(start, stop)
{
this.start = start === undefined ? new Point() : start;
this.stop = stop === undefined ? new Point() : stop;
}
/**
* @param {CanvasRenderingContext2D} ctx
*/
draw(ctx)
{
if(this.gl instanceof CanvasRenderingContext2D)
{
ctx.moveTo(this.start.x, this.start.y);
ctx.lineTo(this.stop.x, this.stop.y);
}
else if(this.gl instanceof WebGLRenderingContext)
{
}
else
alert('Unknown rendering context type');
}
from_json(data)
{
this.start = this.start.from_json(data.start);
this.stop = this.stop.from_json(data.stop);
return this;
}
}
export { Segment }