1
0
Fork 0
freesewing/packages/examples/src/utils_pointonline.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-01-27 12:54:18 +01:00
export default part => {
2019-08-03 15:03:33 +02:00
let { Point, points, Path, paths, Snippet, snippets, utils } = part.shorthand()
2019-01-27 12:54:18 +01:00
2019-08-03 15:03:33 +02:00
points.from1 = new Point(10, 10)
points.to1 = new Point(90, 60)
points.from2 = new Point(10, 30)
points.to2 = new Point(90, 80)
points.b1 = new Point(170, 110)
points.b2 = new Point(170, 130)
2019-01-27 12:54:18 +01:00
2019-08-03 15:03:33 +02:00
let scatter = []
2019-01-27 12:54:18 +01:00
for (let i = 1; i < 36; i++) {
for (let j = 1; j < 27; j++) {
2019-08-03 15:03:33 +02:00
scatter.push(new Point(i * 10, j * 10))
2019-01-27 12:54:18 +01:00
}
}
2019-08-03 15:03:33 +02:00
let snippet
2019-01-27 12:54:18 +01:00
for (let point of scatter) {
2019-08-03 15:03:33 +02:00
if (utils.pointOnLine(points.from1, points.to1, point)) snippet = 'notch'
else snippet = 'bnotch'
snippets[part.getId()] = new Snippet(snippet, point)
2019-01-30 14:21:59 +01:00
if (utils.pointOnLine(points.from2, points.to2, point, 0.01)) {
2019-08-03 15:03:33 +02:00
snippet = 'notch'
} else snippet = 'bnotch'
snippets[part.getId()] = new Snippet(snippet, point)
2019-01-27 12:54:18 +01:00
}
paths.line1 = new Path()
.move(points.from1)
.line(points.to1)
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric stroke-lg')
2019-01-27 12:54:18 +01:00
paths.lne1 = new Path()
.move(points.to1)
.line(points.b1)
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric dashed')
2019-01-27 12:54:18 +01:00
paths.line2 = new Path()
.move(points.from2)
.line(points.to2)
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric stroke-lg')
2019-01-27 12:54:18 +01:00
paths.lne2 = new Path()
.move(points.to2)
.line(points.b2)
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric dashed')
2019-01-27 12:54:18 +01:00
2019-08-03 15:03:33 +02:00
return part
}