2022-06-08 07:50:05 -07:00
|
|
|
import { createTeeth } from './teeth.js'
|
|
|
|
|
|
|
|
export default function (part) {
|
|
|
|
let {
|
|
|
|
store,
|
|
|
|
sa,
|
|
|
|
Point,
|
|
|
|
points,
|
|
|
|
Path,
|
|
|
|
paths,
|
|
|
|
Snippet,
|
|
|
|
snippets,
|
|
|
|
options,
|
|
|
|
measurements,
|
|
|
|
complete,
|
|
|
|
paperless,
|
|
|
|
macro,
|
|
|
|
} = part.shorthand()
|
|
|
|
|
|
|
|
let upperTeeth01_02d = 131.305041182736 * options.size
|
|
|
|
let upperTeeth01_02a = 34.147056946748805 + 180
|
fix(hi): Make Hi faster (at generating teeth)
This pattern uses a method to generate teeth which depends on a lot
of Path.shiftAlong() invocations.
This causes the pattern to be a bit sluggish, with a render taking
around 160ms (which is too slow to feel instantaneous for the user) and
the unit tests timing out because some individual tests take longer than
2 seconds. When extending the timeout, running all tests clocks in just
over 14 seconds which is slow.
This PR replaces this method with an optimized one that is a lot faster.
(all tests now complete in 2.11 seconds).
To do this,it does some things differnet, and cuts some corners:
- It does not use the Path object, but rather the low-level Bezier
object directly
- It generates teeth for only half the mouth and will mirror them to the
other side
- It uses a symmetric cubic Bezier curve so we don't need to walk the
path in steps that are determined by distance, but can just walk it at
regular intervals of the t value. As it happens, that can be done in
one pass by using Bezier.getLUT()
The corners I cut:
- Because of the symmetric Bezier the path is ever so
slightly different, but the difference is minimal.provides ai
- Since we generate half of the mouth/teeth and then mirror, we need and
even number of teeth, so I've changed the upper teeth from 15 to 14
2022-06-15 19:48:51 +02:00
|
|
|
let upperTeeth02cp1d = 64.30113337316406 * options.size
|
2022-06-08 07:50:05 -07:00
|
|
|
let upperTeeth02cp1a = 55.1335930733262
|
fix(hi): Make Hi faster (at generating teeth)
This pattern uses a method to generate teeth which depends on a lot
of Path.shiftAlong() invocations.
This causes the pattern to be a bit sluggish, with a render taking
around 160ms (which is too slow to feel instantaneous for the user) and
the unit tests timing out because some individual tests take longer than
2 seconds. When extending the timeout, running all tests clocks in just
over 14 seconds which is slow.
This PR replaces this method with an optimized one that is a lot faster.
(all tests now complete in 2.11 seconds).
To do this,it does some things differnet, and cuts some corners:
- It does not use the Path object, but rather the low-level Bezier
object directly
- It generates teeth for only half the mouth and will mirror them to the
other side
- It uses a symmetric cubic Bezier curve so we don't need to walk the
path in steps that are determined by distance, but can just walk it at
regular intervals of the t value. As it happens, that can be done in
one pass by using Bezier.getLUT()
The corners I cut:
- Because of the symmetric Bezier the path is ever so
slightly different, but the difference is minimal.provides ai
- Since we generate half of the mouth/teeth and then mirror, we need and
even number of teeth, so I've changed the upper teeth from 15 to 14
2022-06-15 19:48:51 +02:00
|
|
|
let upperTeeth01cp2d = 48.331000000000017 * options.size
|
2022-06-08 07:50:05 -07:00
|
|
|
let upperTeeth01cp2a = 180
|
|
|
|
|
|
|
|
points.upperTeeth01 = new Point(0, 0)
|
|
|
|
points.upperTeeth02 = points.upperTeeth01.shift(upperTeeth01_02a, upperTeeth01_02d)
|
|
|
|
points.upperTeeth01cp2 = points.upperTeeth01.shift(upperTeeth01cp2a, upperTeeth01cp2d)
|
|
|
|
points.upperTeeth02cp1 = points.upperTeeth02.shift(upperTeeth02cp1a, upperTeeth02cp1d)
|
fix(hi): Make Hi faster (at generating teeth)
This pattern uses a method to generate teeth which depends on a lot
of Path.shiftAlong() invocations.
This causes the pattern to be a bit sluggish, with a render taking
around 160ms (which is too slow to feel instantaneous for the user) and
the unit tests timing out because some individual tests take longer than
2 seconds. When extending the timeout, running all tests clocks in just
over 14 seconds which is slow.
This PR replaces this method with an optimized one that is a lot faster.
(all tests now complete in 2.11 seconds).
To do this,it does some things differnet, and cuts some corners:
- It does not use the Path object, but rather the low-level Bezier
object directly
- It generates teeth for only half the mouth and will mirror them to the
other side
- It uses a symmetric cubic Bezier curve so we don't need to walk the
path in steps that are determined by distance, but can just walk it at
regular intervals of the t value. As it happens, that can be done in
one pass by using Bezier.getLUT()
The corners I cut:
- Because of the symmetric Bezier the path is ever so
slightly different, but the difference is minimal.provides ai
- Since we generate half of the mouth/teeth and then mirror, we need and
even number of teeth, so I've changed the upper teeth from 15 to 14
2022-06-15 19:48:51 +02:00
|
|
|
// Make seam symmetric to optimize generating teeth
|
|
|
|
points.upperTeeth02cp1 = points.upperTeeth02.shiftTowards(
|
|
|
|
points.upperTeeth02cp1,
|
|
|
|
points.upperTeeth01cp2.dist(points.upperTeeth01)
|
|
|
|
)
|
2022-06-08 07:50:05 -07:00
|
|
|
points.upperTeeth03 = points.upperTeeth02.flipX()
|
|
|
|
points.upperTeeth01cp1 = points.upperTeeth01cp2.flipX()
|
|
|
|
points.upperTeeth03cp2 = points.upperTeeth02cp1.flipX()
|
|
|
|
|
|
|
|
paths.seam = new Path()
|
|
|
|
.move(points.upperTeeth02)
|
|
|
|
.curve(points.upperTeeth02cp1, points.upperTeeth01cp2, points.upperTeeth01)
|
|
|
|
.curve(points.upperTeeth01cp1, points.upperTeeth03cp2, points.upperTeeth03)
|
|
|
|
|
|
|
|
store.set('upperTeethLength', paths.seam.length())
|
|
|
|
|
fix(hi): Make Hi faster (at generating teeth)
This pattern uses a method to generate teeth which depends on a lot
of Path.shiftAlong() invocations.
This causes the pattern to be a bit sluggish, with a render taking
around 160ms (which is too slow to feel instantaneous for the user) and
the unit tests timing out because some individual tests take longer than
2 seconds. When extending the timeout, running all tests clocks in just
over 14 seconds which is slow.
This PR replaces this method with an optimized one that is a lot faster.
(all tests now complete in 2.11 seconds).
To do this,it does some things differnet, and cuts some corners:
- It does not use the Path object, but rather the low-level Bezier
object directly
- It generates teeth for only half the mouth and will mirror them to the
other side
- It uses a symmetric cubic Bezier curve so we don't need to walk the
path in steps that are determined by distance, but can just walk it at
regular intervals of the t value. As it happens, that can be done in
one pass by using Bezier.getLUT()
The corners I cut:
- Because of the symmetric Bezier the path is ever so
slightly different, but the difference is minimal.provides ai
- Since we generate half of the mouth/teeth and then mirror, we need and
even number of teeth, so I've changed the upper teeth from 15 to 14
2022-06-15 19:48:51 +02:00
|
|
|
//paths.teeth = new Path().move(paths.seam.start())
|
2022-06-08 07:50:05 -07:00
|
|
|
|
fix(hi): Make Hi faster (at generating teeth)
This pattern uses a method to generate teeth which depends on a lot
of Path.shiftAlong() invocations.
This causes the pattern to be a bit sluggish, with a render taking
around 160ms (which is too slow to feel instantaneous for the user) and
the unit tests timing out because some individual tests take longer than
2 seconds. When extending the timeout, running all tests clocks in just
over 14 seconds which is slow.
This PR replaces this method with an optimized one that is a lot faster.
(all tests now complete in 2.11 seconds).
To do this,it does some things differnet, and cuts some corners:
- It does not use the Path object, but rather the low-level Bezier
object directly
- It generates teeth for only half the mouth and will mirror them to the
other side
- It uses a symmetric cubic Bezier curve so we don't need to walk the
path in steps that are determined by distance, but can just walk it at
regular intervals of the t value. As it happens, that can be done in
one pass by using Bezier.getLUT()
The corners I cut:
- Because of the symmetric Bezier the path is ever so
slightly different, but the difference is minimal.provides ai
- Since we generate half of the mouth/teeth and then mirror, we need and
even number of teeth, so I've changed the upper teeth from 15 to 14
2022-06-15 19:48:51 +02:00
|
|
|
paths.teeth = createTeeth(
|
|
|
|
[ // Array holding the points for half a mouth (bezier, not path)
|
|
|
|
points.upperTeeth02, // start
|
|
|
|
points.upperTeeth02cp1, // cp1
|
|
|
|
points.upperTeeth01cp2, // cp2
|
|
|
|
points.upperTeeth01, // end
|
|
|
|
],
|
|
|
|
14, // number of teeth
|
|
|
|
14, // size
|
|
|
|
part
|
|
|
|
)
|
|
|
|
//createTeeth(paths.seam, 18 * options.size, 9 * options.size, 15, options.aggressive, paths.teeth)
|
2022-06-08 07:50:05 -07:00
|
|
|
|
|
|
|
// Complete?
|
|
|
|
if (complete) {
|
|
|
|
snippets.upperTeeth = new Snippet('bnotch', points.upperTeeth01)
|
2022-06-08 20:16:21 -07:00
|
|
|
|
|
|
|
points.titleAnchor = points.upperTeeth02.shiftFractionTowards(points.upperTeeth03, 0.5).shiftFractionTowards(points.upperTeeth01, 0.5)
|
|
|
|
|
|
|
|
macro('title', {
|
|
|
|
at: points.titleAnchor,
|
2022-06-09 08:44:43 -07:00
|
|
|
nr: 8,
|
2022-06-08 20:16:21 -07:00
|
|
|
title: 'upperTeeth',
|
|
|
|
scale: options.size / 2,
|
|
|
|
})
|
|
|
|
|
|
|
|
if (paperless) {
|
|
|
|
macro('hd', {
|
|
|
|
from: points.upperTeeth01,
|
|
|
|
to: points.upperTeeth03,
|
|
|
|
y: points.upperTeeth02.y + sa + 10,
|
|
|
|
noStartMarker: true,
|
|
|
|
noEndMarker: true,
|
|
|
|
})
|
|
|
|
macro('hd', {
|
|
|
|
from: points.upperTeeth02,
|
|
|
|
to: points.upperTeeth01,
|
|
|
|
y: points.upperTeeth02.y + sa + 10,
|
|
|
|
noStartMarker: true,
|
|
|
|
noEndMarker: true,
|
|
|
|
})
|
|
|
|
macro('vd', {
|
|
|
|
from: points.upperTeeth02,
|
|
|
|
to: points.upperTeeth01,
|
|
|
|
x: points.upperTeeth02.x - sa - 10,
|
|
|
|
noStartMarker: true,
|
|
|
|
noEndMarker: true,
|
|
|
|
})
|
|
|
|
macro('vd', {
|
fix(hi): Make Hi faster (at generating teeth)
This pattern uses a method to generate teeth which depends on a lot
of Path.shiftAlong() invocations.
This causes the pattern to be a bit sluggish, with a render taking
around 160ms (which is too slow to feel instantaneous for the user) and
the unit tests timing out because some individual tests take longer than
2 seconds. When extending the timeout, running all tests clocks in just
over 14 seconds which is slow.
This PR replaces this method with an optimized one that is a lot faster.
(all tests now complete in 2.11 seconds).
To do this,it does some things differnet, and cuts some corners:
- It does not use the Path object, but rather the low-level Bezier
object directly
- It generates teeth for only half the mouth and will mirror them to the
other side
- It uses a symmetric cubic Bezier curve so we don't need to walk the
path in steps that are determined by distance, but can just walk it at
regular intervals of the t value. As it happens, that can be done in
one pass by using Bezier.getLUT()
The corners I cut:
- Because of the symmetric Bezier the path is ever so
slightly different, but the difference is minimal.provides ai
- Since we generate half of the mouth/teeth and then mirror, we need and
even number of teeth, so I've changed the upper teeth from 15 to 14
2022-06-15 19:48:51 +02:00
|
|
|
from: points.upperTeeth01,
|
2022-06-08 20:16:21 -07:00
|
|
|
to: paths.teeth.edge('top'),
|
|
|
|
x: points.upperTeeth02.x - sa - 10,
|
|
|
|
noStartMarker: true,
|
|
|
|
noEndMarker: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-08 07:50:05 -07:00
|
|
|
if (sa) {
|
|
|
|
let pSA = paths.seam.offset(sa)
|
|
|
|
paths.sa = new Path()
|
|
|
|
.move(paths.seam.start())
|
|
|
|
.line(pSA.start())
|
|
|
|
.join(pSA)
|
|
|
|
.line(paths.seam.end())
|
|
|
|
.attr('class', 'fabric sa')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return part
|
|
|
|
}
|