Ergogen reorg
This commit is contained in:
parent
cd1e10293c
commit
0ab5a246e5
14 changed files with 2289 additions and 309 deletions
71
src/point.js
Normal file
71
src/point.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
const m = require('makerjs')
|
||||
const u = require('./utils')
|
||||
|
||||
class Point {
|
||||
constructor(x=0, y=0, r=0, meta={}) {
|
||||
if (Array.isArray(x)) {
|
||||
this.x = x[0]
|
||||
this.y = x[1]
|
||||
this.r = 0
|
||||
this.meta = {}
|
||||
} else {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.r = r
|
||||
this.meta = meta
|
||||
}
|
||||
}
|
||||
|
||||
get p() {
|
||||
return [this.x, this.y]
|
||||
}
|
||||
|
||||
set p(val) {
|
||||
[this.x, this.y] = val
|
||||
}
|
||||
|
||||
add(a) {
|
||||
const res = this.clone()
|
||||
res.x += a[0]
|
||||
res.y += a[1]
|
||||
return res
|
||||
}
|
||||
|
||||
shift(s) {
|
||||
this.x += s[0]
|
||||
this.y += s[1]
|
||||
return this
|
||||
}
|
||||
|
||||
rotate(angle, origin=[0, 0]) {
|
||||
this.p = m.point.rotate(this.p, angle, origin)
|
||||
this.r += angle
|
||||
return this
|
||||
}
|
||||
|
||||
mirror(x) {
|
||||
this.x = 2 * x - this.x
|
||||
this.r = -this.r
|
||||
return this
|
||||
}
|
||||
|
||||
clone() {
|
||||
return new Point(
|
||||
this.x,
|
||||
this.y,
|
||||
this.r,
|
||||
u.deepcopy(this.meta)
|
||||
)
|
||||
}
|
||||
|
||||
position(model) {
|
||||
return m.model.moveRelative(m.model.rotate(model, this.r), this.p)
|
||||
}
|
||||
|
||||
rect(size=14) {
|
||||
let rect = u.rect(size, size, [-size/2, -size/2], this.meta.mirrored)
|
||||
return this.position(rect)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Point
|
Loading…
Add table
Add a link
Reference in a new issue