Fixes code save

This commit is contained in:
Steve Ruiz 2021-05-16 09:33:08 +01:00
parent 520553fb2f
commit e21748f7b7
9 changed files with 66 additions and 17 deletions

View file

@ -3,12 +3,23 @@ import Circle from "./circle"
import Ellipse from "./ellipse"
import Polyline from "./polyline"
import Dot from "./dot"
import Ray from "./ray"
import Line from "./line"
import Vector from "./vector"
import Utils from "./utils"
import { codeShapes } from "./index"
const scope = { Dot, Circle, Ellipse, Line, Polyline, Rectangle, Vector, Utils }
const scope = {
Dot,
Circle,
Ellipse,
Ray,
Line,
Polyline,
Rectangle,
Vector,
Utils,
}
/**
* Evaluate code, collecting generated shapes in the shape set. Return the

25
lib/code/ray.ts Normal file
View file

@ -0,0 +1,25 @@
import CodeShape from "./index"
import { v4 as uuid } from "uuid"
import { RayShape, ShapeType } from "types"
export default class Ray extends CodeShape<RayShape> {
constructor(props = {} as Partial<RayShape>) {
super({
id: uuid(),
type: ShapeType.Ray,
isGenerated: false,
name: "Ray",
parentId: "page0",
childIndex: 0,
point: [0, 0],
direction: [0, 1],
rotation: 0,
style: {
fill: "#777",
stroke: "#000",
strokeWidth: 1,
},
...props,
})
}
}

View file

@ -274,16 +274,12 @@ export default class Vector {
lrp(b: Vector, t: number) {
const n = new Vector(this)
this.vec(b)
.mul(t)
.add(n)
this.vec(b).mul(t).add(n)
}
static lrp(a: Vector, b: Vector, t: number) {
const n = new Vector(a)
n.vec(b)
.mul(t)
.add(a)
n.vec(b).mul(t).add(a)
return n
}
@ -390,6 +386,14 @@ export default class Vector {
return n.div(n.len())
}
normalize() {
return this.uni()
}
static normalize(v: Vector) {
return Vector.uni(v)
}
isLeft(center: Vector, b: Vector) {
return (
(center.x - this.x) * (b.y - this.y) - (b.x - this.x) * (center.y - b.y)