From 3f65251532842bf48bd4dc8941cf102864eb22b7 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sun, 27 Jan 2019 12:54:18 +0100 Subject: [PATCH] construction: Ported to v0.29 --- packages/examples/config/config.js | 10 -- packages/examples/config/index.js | 68 ++++++++ packages/examples/index.html | 2 +- packages/examples/src/index.js | 165 ++++++++++++------ packages/examples/src/path.divide.js | 37 ---- packages/examples/src/path.edge.js | 36 ---- packages/examples/src/path.end.js | 24 --- packages/examples/src/path.intersects.js | 42 ----- packages/examples/src/path.intersectsx.js | 35 ---- packages/examples/src/path.intersectsy.js | 34 ---- packages/examples/src/path.join.js | 32 ---- packages/examples/src/path.length.js | 38 ---- packages/examples/src/path.offset.js | 40 ----- packages/examples/src/path.ops.js | 62 ------- packages/examples/src/path.reverse.js | 27 --- packages/examples/src/path.shiftalong.js | 37 ---- .../examples/src/path.shiftfractionalong.js | 37 ---- packages/examples/src/path.split.js | 44 ----- packages/examples/src/path.start.js | 24 --- packages/examples/src/path.translate.js | 41 ----- packages/examples/src/path.trim.js | 50 ------ packages/examples/src/path_divide.js | 37 ++++ packages/examples/src/path_edge.js | 37 ++++ packages/examples/src/path_end.js | 25 +++ packages/examples/src/path_intersects.js | 43 +++++ packages/examples/src/path_intersectsx.js | 36 ++++ packages/examples/src/path_intersectsy.js | 35 ++++ packages/examples/src/path_join.js | 33 ++++ packages/examples/src/path_length.js | 39 +++++ packages/examples/src/path_offset.js | 42 +++++ packages/examples/src/path_ops.js | 63 +++++++ packages/examples/src/path_reverse.js | 29 +++ packages/examples/src/path_shiftalong.js | 38 ++++ .../examples/src/path_shiftfractionalong.js | 31 ++++ packages/examples/src/path_split.js | 44 +++++ packages/examples/src/path_start.js | 25 +++ packages/examples/src/path_translate.js | 44 +++++ packages/examples/src/path_trim.js | 50 ++++++ packages/examples/src/plugin.cutonfold.js | 30 ---- packages/examples/src/plugin.dimension.js | 56 ------ packages/examples/src/plugin.grainline.js | 20 --- packages/examples/src/plugin.logo.js | 25 --- packages/examples/src/plugin.scalebox.js | 16 -- packages/examples/src/plugin.title.js | 29 --- packages/examples/src/plugin_cutonfold.js | 23 +++ packages/examples/src/plugin_dimension.js | 49 ++++++ packages/examples/src/plugin_grainline.js | 13 ++ packages/examples/src/plugin_logo.js | 20 +++ packages/examples/src/plugin_scalebox.js | 11 ++ packages/examples/src/plugin_title.js | 24 +++ packages/examples/src/point.angle.js | 58 ------ packages/examples/src/point.attr.js | 22 --- packages/examples/src/point.clone.js | 23 --- packages/examples/src/point.copy.js | 22 --- packages/examples/src/point.dist.js | 23 --- packages/examples/src/point.dx.js | 24 --- packages/examples/src/point.dy.js | 24 --- packages/examples/src/point.flipx.js | 55 ------ packages/examples/src/point.flipy.js | 84 --------- packages/examples/src/point.rotate.js | 24 --- packages/examples/src/point.shift.js | 31 ---- .../src/point.shiftfractiontowards.js | 43 ----- packages/examples/src/point.shiftoutwards.js | 33 ---- packages/examples/src/point.shifttowards.js | 37 ---- packages/examples/src/point.sitson.js | 25 --- packages/examples/src/point.translate.js | 30 ---- packages/examples/src/point_angle.js | 51 ++++++ packages/examples/src/point_attr.js | 16 ++ packages/examples/src/point_clone.js | 17 ++ packages/examples/src/point_copy.js | 16 ++ packages/examples/src/point_dist.js | 16 ++ packages/examples/src/point_dx.js | 17 ++ packages/examples/src/point_dy.js | 17 ++ packages/examples/src/point_flipx.js | 56 ++++++ packages/examples/src/point_flipy.js | 81 +++++++++ packages/examples/src/point_rotate.js | 17 ++ packages/examples/src/point_shift.js | 21 +++ .../src/point_shiftfractiontowards.js | 44 +++++ packages/examples/src/point_shiftoutwards.js | 34 ++++ packages/examples/src/point_shifttowards.js | 38 ++++ packages/examples/src/point_sitson.js | 20 +++ packages/examples/src/point_translate.js | 25 +++ packages/examples/src/settings.sa.js | 28 --- packages/examples/src/settings_sa.js | 22 +++ .../src/utils.beamintersectscircle.js | 53 ------ .../examples/src/utils.beamintersectsx.js | 27 --- .../examples/src/utils.beamintersectsy.js | 27 --- packages/examples/src/utils.beamsintersect.js | 25 --- .../examples/src/utils.circlesintersect.js | 44 ----- .../examples/src/utils.curvesintersect.js | 40 ----- .../src/utils.lineintersectscircle.js | 52 ------ .../examples/src/utils.lineintersectscurve.js | 33 ---- packages/examples/src/utils.linesintersect.js | 25 --- packages/examples/src/utils.pointonbeam.js | 52 ------ packages/examples/src/utils.pointoncurve.js | 43 ----- packages/examples/src/utils.pointonline.js | 52 ------ .../src/utils_beamintersectscircle.js | 55 ++++++ .../examples/src/utils_beamintersectsx.js | 26 +++ .../examples/src/utils_beamintersectsy.js | 26 +++ packages/examples/src/utils_beamsintersect.js | 27 +++ .../examples/src/utils_circlesintersect.js | 46 +++++ .../examples/src/utils_curvesintersect.js | 42 +++++ .../src/utils_lineintersectscircle.js | 54 ++++++ .../examples/src/utils_lineintersectscurve.js | 35 ++++ packages/examples/src/utils_linesintersect.js | 27 +++ packages/examples/src/utils_pointonbeam.js | 54 ++++++ packages/examples/src/utils_pointoncurve.js | 45 +++++ packages/examples/src/utils_pointonline.js | 46 +++++ 108 files changed, 1962 insertions(+), 1940 deletions(-) delete mode 100644 packages/examples/config/config.js create mode 100644 packages/examples/config/index.js delete mode 100644 packages/examples/src/path.divide.js delete mode 100644 packages/examples/src/path.edge.js delete mode 100644 packages/examples/src/path.end.js delete mode 100644 packages/examples/src/path.intersects.js delete mode 100644 packages/examples/src/path.intersectsx.js delete mode 100644 packages/examples/src/path.intersectsy.js delete mode 100644 packages/examples/src/path.join.js delete mode 100644 packages/examples/src/path.length.js delete mode 100644 packages/examples/src/path.offset.js delete mode 100644 packages/examples/src/path.ops.js delete mode 100644 packages/examples/src/path.reverse.js delete mode 100644 packages/examples/src/path.shiftalong.js delete mode 100644 packages/examples/src/path.shiftfractionalong.js delete mode 100644 packages/examples/src/path.split.js delete mode 100644 packages/examples/src/path.start.js delete mode 100644 packages/examples/src/path.translate.js delete mode 100644 packages/examples/src/path.trim.js create mode 100644 packages/examples/src/path_divide.js create mode 100644 packages/examples/src/path_edge.js create mode 100644 packages/examples/src/path_end.js create mode 100644 packages/examples/src/path_intersects.js create mode 100644 packages/examples/src/path_intersectsx.js create mode 100644 packages/examples/src/path_intersectsy.js create mode 100644 packages/examples/src/path_join.js create mode 100644 packages/examples/src/path_length.js create mode 100644 packages/examples/src/path_offset.js create mode 100644 packages/examples/src/path_ops.js create mode 100644 packages/examples/src/path_reverse.js create mode 100644 packages/examples/src/path_shiftalong.js create mode 100644 packages/examples/src/path_shiftfractionalong.js create mode 100644 packages/examples/src/path_split.js create mode 100644 packages/examples/src/path_start.js create mode 100644 packages/examples/src/path_translate.js create mode 100644 packages/examples/src/path_trim.js delete mode 100644 packages/examples/src/plugin.cutonfold.js delete mode 100644 packages/examples/src/plugin.dimension.js delete mode 100644 packages/examples/src/plugin.grainline.js delete mode 100644 packages/examples/src/plugin.logo.js delete mode 100644 packages/examples/src/plugin.scalebox.js delete mode 100644 packages/examples/src/plugin.title.js create mode 100644 packages/examples/src/plugin_cutonfold.js create mode 100644 packages/examples/src/plugin_dimension.js create mode 100644 packages/examples/src/plugin_grainline.js create mode 100644 packages/examples/src/plugin_logo.js create mode 100644 packages/examples/src/plugin_scalebox.js create mode 100644 packages/examples/src/plugin_title.js delete mode 100644 packages/examples/src/point.angle.js delete mode 100644 packages/examples/src/point.attr.js delete mode 100644 packages/examples/src/point.clone.js delete mode 100644 packages/examples/src/point.copy.js delete mode 100644 packages/examples/src/point.dist.js delete mode 100644 packages/examples/src/point.dx.js delete mode 100644 packages/examples/src/point.dy.js delete mode 100644 packages/examples/src/point.flipx.js delete mode 100644 packages/examples/src/point.flipy.js delete mode 100644 packages/examples/src/point.rotate.js delete mode 100644 packages/examples/src/point.shift.js delete mode 100644 packages/examples/src/point.shiftfractiontowards.js delete mode 100644 packages/examples/src/point.shiftoutwards.js delete mode 100644 packages/examples/src/point.shifttowards.js delete mode 100644 packages/examples/src/point.sitson.js delete mode 100644 packages/examples/src/point.translate.js create mode 100644 packages/examples/src/point_angle.js create mode 100644 packages/examples/src/point_attr.js create mode 100644 packages/examples/src/point_clone.js create mode 100644 packages/examples/src/point_copy.js create mode 100644 packages/examples/src/point_dist.js create mode 100644 packages/examples/src/point_dx.js create mode 100644 packages/examples/src/point_dy.js create mode 100644 packages/examples/src/point_flipx.js create mode 100644 packages/examples/src/point_flipy.js create mode 100644 packages/examples/src/point_rotate.js create mode 100644 packages/examples/src/point_shift.js create mode 100644 packages/examples/src/point_shiftfractiontowards.js create mode 100644 packages/examples/src/point_shiftoutwards.js create mode 100644 packages/examples/src/point_shifttowards.js create mode 100644 packages/examples/src/point_sitson.js create mode 100644 packages/examples/src/point_translate.js delete mode 100644 packages/examples/src/settings.sa.js create mode 100644 packages/examples/src/settings_sa.js delete mode 100644 packages/examples/src/utils.beamintersectscircle.js delete mode 100644 packages/examples/src/utils.beamintersectsx.js delete mode 100644 packages/examples/src/utils.beamintersectsy.js delete mode 100644 packages/examples/src/utils.beamsintersect.js delete mode 100644 packages/examples/src/utils.circlesintersect.js delete mode 100644 packages/examples/src/utils.curvesintersect.js delete mode 100644 packages/examples/src/utils.lineintersectscircle.js delete mode 100644 packages/examples/src/utils.lineintersectscurve.js delete mode 100644 packages/examples/src/utils.linesintersect.js delete mode 100644 packages/examples/src/utils.pointonbeam.js delete mode 100644 packages/examples/src/utils.pointoncurve.js delete mode 100644 packages/examples/src/utils.pointonline.js create mode 100644 packages/examples/src/utils_beamintersectscircle.js create mode 100644 packages/examples/src/utils_beamintersectsx.js create mode 100644 packages/examples/src/utils_beamintersectsy.js create mode 100644 packages/examples/src/utils_beamsintersect.js create mode 100644 packages/examples/src/utils_circlesintersect.js create mode 100644 packages/examples/src/utils_curvesintersect.js create mode 100644 packages/examples/src/utils_lineintersectscircle.js create mode 100644 packages/examples/src/utils_lineintersectscurve.js create mode 100644 packages/examples/src/utils_linesintersect.js create mode 100644 packages/examples/src/utils_pointonbeam.js create mode 100644 packages/examples/src/utils_pointoncurve.js create mode 100644 packages/examples/src/utils_pointonline.js diff --git a/packages/examples/config/config.js b/packages/examples/config/config.js deleted file mode 100644 index b301ee4f29f..00000000000 --- a/packages/examples/config/config.js +++ /dev/null @@ -1,10 +0,0 @@ -import { version } from "../package.json"; - -export default { - name: "examples", - version, - dependencies: { - path_attr: "path_clone" - }, - parts: ["path_attr", "path_clone"] -}; diff --git a/packages/examples/config/index.js b/packages/examples/config/index.js new file mode 100644 index 00000000000..e01b864ea38 --- /dev/null +++ b/packages/examples/config/index.js @@ -0,0 +1,68 @@ +import { version } from "../package.json"; + +export default { + name: "examples", + version, + // This is not needed, but is here to sidestep an issue in freesewing + // that needs to be fixed but hasn't yet + dependencies: { + path_attr: "path_clone" + }, + parts: [ + "point_attr", + "path_attr", + "path_clone", + "path_divide", + "path_edge", + "path_end", + "path_intersects", + "path_intersectsx", + "path_intersectsy", + "path_join", + "path_length", + "path_offset", + "path_ops", + "path_reverse", + "path_shiftalong", + "path_shiftfractionalong", + "path_split", + "path_start", + "path_translate", + "path_trim", + "plugin_cutonfold", + "plugin_dimension", + "plugin_grainline", + "plugin_logo", + "plugin_scalebox", + "plugin_title", + "point_angle", + "point_attr", + "point_clone", + "point_copy", + "point_dist", + "point_dx", + "point_dy", + "point_flipx", + "point_flipy", + "point_shift", + "point_shiftfractiontowards", + "point_shifttowards", + "point_shiftoutwards", + "point_sitson", + "point_rotate", + "point_translate", + "settings_sa", + "utils_linesintersect", + "utils_beamsintersect", + "utils_beamintersectsx", + "utils_beamintersectsy", + "utils_lineintersectscurve", + "utils_curvesintersect", + "utils_pointonbeam", + "utils_pointonline", + "utils_pointoncurve", + "utils_circlesintersect", + "utils_beamintersectscircle", + "utils_lineintersectscircle" + ] +}; diff --git a/packages/examples/index.html b/packages/examples/index.html index d83d31ed472..31b272cff8d 100644 --- a/packages/examples/index.html +++ b/packages/examples/index.html @@ -19,7 +19,7 @@ var pattern = new freesewing.patterns.examples(); pattern.use(freesewing.plugins.debug) .use(freesewing.plugins.theme) - .use(freesewing.plugins.designer) + //.use(freesewing.plugins.designer) .use(freesewing.plugins.validate) ; diff --git a/packages/examples/src/index.js b/packages/examples/src/index.js index c5c45af73cb..c63cab57c7d 100644 --- a/packages/examples/src/index.js +++ b/packages/examples/src/index.js @@ -1,68 +1,67 @@ import freesewing from "freesewing"; import plugins from "@freesewing/plugin-bundle"; -import config from "../config/config"; +import config from "../config/"; import { version } from "../package.json"; -import pointAttr from "./point.attr"; -import pointDist from "./point.dist"; -import pointDx from "./point.dx"; -import pointDy from "./point.dy"; -import pointAngle from "./point.angle"; -import pointRotate from "./point.rotate"; -import pointCopy from "./point.copy"; -import pointFlipX from "./point.flipx"; -import pointFlipY from "./point.flipy"; -import pointShift from "./point.shift"; -import pointShiftTowards from "./point.shifttowards"; -import pointShiftFractionTowards from "./point.shiftfractiontowards"; -import pointShiftOutwards from "./point.shiftoutwards"; -import pointTranslate from "./point.translate"; -import pointSitsOn from "./point.sitson"; -import pointClone from "./point.clone"; - import draftPath_attr from "./path_attr"; import draftPath_clone from "./path_clone"; +import draftPath_divide from "./path_divide"; +import draftPath_edge from "./path_edge"; +import draftPath_end from "./path_end"; +import draftPath_intersects from "./path_intersects"; +import draftPath_intersectsx from "./path_intersectsx"; +import draftPath_intersectsy from "./path_intersectsy"; +import draftPath_join from "./path_join"; +import draftPath_length from "./path_length"; +import draftPath_offset from "./path_offset"; +import draftPath_ops from "./path_ops"; +import draftPath_reverse from "./path_reverse"; +import draftPath_shiftalong from "./path_shiftalong"; +import draftPath_shiftfractionalong from "./path_shiftfractionalong"; +import draftPath_split from "./path_split"; +import draftPath_start from "./path_start"; +import draftPath_translate from "./path_translate"; +import draftPath_trim from "./path_trim"; -import pathOps from "./path.ops"; -import pathOffset from "./path.offset"; -import pathLength from "./path.length"; -import pathStart from "./path.start"; -import pathEnd from "./path.end"; -import pathJoin from "./path.join"; -import pathReverse from "./path.reverse"; -import pathShiftAlong from "./path.shiftalong"; -import pathShiftFractionAlong from "./path.shiftfractionalong"; -import pathEdge from "./path.edge"; -import pathTrim from "./path.trim"; -import pathIntersectsX from "./path.intersectsx"; -import pathIntersectsY from "./path.intersectsy"; -import pathIntersects from "./path.intersects"; -import pathDivide from "./path.divide"; -import pathSplit from "./path.split"; -import pathTranslate from "./path.translate"; +import draftPlugin_cutonfold from "./plugin_cutonfold"; +import draftPlugin_dimension from "./plugin_dimension"; +import draftPlugin_grainline from "./plugin_grainline"; +import draftPlugin_logo from "./plugin_logo"; +import draftPlugin_scalebox from "./plugin_scalebox"; +import draftPlugin_title from "./plugin_title"; -import utilsLinesIntersect from "./utils.linesintersect"; -import utilsBeamsIntersect from "./utils.beamsintersect"; -import utilsBeamIntersectsX from "./utils.beamintersectsx"; -import utilsBeamIntersectsY from "./utils.beamintersectsy"; -import utilsLineIntersectsCurve from "./utils.lineintersectscurve"; -import utilsCurvesIntersect from "./utils.curvesintersect"; -import utilsPointOnBeam from "./utils.pointonbeam"; -import utilsPointOnLine from "./utils.pointonline"; -import utilsPointOnCurve from "./utils.pointoncurve"; -import utilsCirclesIntersect from "./utils.circlesintersect"; -import utilsBeamIntersectsCircle from "./utils.beamintersectscircle"; -import utilsLineIntersectsCircle from "./utils.lineintersectscircle"; +import draftPoint_angle from "./point_angle"; +import draftPoint_attr from "./point_attr"; +import draftPoint_clone from "./point_clone"; +import draftPoint_copy from "./point_copy"; +import draftPoint_dist from "./point_dist"; +import draftPoint_dx from "./point_dx"; +import draftPoint_dy from "./point_dy"; +import draftPoint_flipx from "./point_flipx"; +import draftPoint_flipy from "./point_flipy"; +import draftPoint_shift from "./point_shift"; +import draftPoint_shiftfractiontowards from "./point_shiftfractiontowards"; +import draftPoint_shifttowards from "./point_shifttowards"; +import draftPoint_shiftoutwards from "./point_shiftoutwards"; +import draftPoint_sitson from "./point_sitson"; +import draftPoint_rotate from "./point_rotate"; +import draftPoint_translate from "./point_translate"; -import pluginGrainline from "./plugin.grainline"; -import pluginCutonfold from "./plugin.cutonfold"; -import pluginDimension from "./plugin.dimension"; -import pluginLogo from "./plugin.logo"; -import pluginTitle from "./plugin.title"; -import pluginScalebox from "./plugin.scalebox"; +import draftUtils_linesintersect from "./utils_linesintersect"; +import draftUtils_beamsintersect from "./utils_beamsintersect"; +import draftUtils_beamintersectsx from "./utils_beamintersectsx"; +import draftUtils_beamintersectsy from "./utils_beamintersectsy"; +import draftUtils_lineintersectscurve from "./utils_lineintersectscurve"; +import draftUtils_curvesintersect from "./utils_curvesintersect"; +import draftUtils_pointonbeam from "./utils_pointonbeam"; +import draftUtils_pointonline from "./utils_pointonline"; +import draftUtils_pointoncurve from "./utils_pointoncurve"; +import draftUtils_circlesintersect from "./utils_circlesintersect"; +import draftUtils_beamintersectscircle from "./utils_beamintersectscircle"; +import draftUtils_lineintersectscircle from "./utils_lineintersectscircle"; -import settingsSa from "./settings.sa"; +import draftSettings_sa from "./settings_sa"; // Constructor const Examples = function(settings) { @@ -77,8 +76,66 @@ Examples.prototype = Object.create(freesewing.Pattern.prototype); Examples.prototype.constructor = Examples; // Attach per-part draft methods to prototype +Examples.prototype.draftPoint_attr = draftPoint_attr; + Examples.prototype.draftPath_attr = draftPath_attr; Examples.prototype.draftPath_clone = draftPath_clone; +Examples.prototype.draftPath_divide = draftPath_divide; +Examples.prototype.draftPath_edge = draftPath_edge; +Examples.prototype.draftPath_end = draftPath_end; +Examples.prototype.draftPath_intersects = draftPath_intersects; +Examples.prototype.draftPath_intersectsx = draftPath_intersectsy; +Examples.prototype.draftPath_intersectsy = draftPath_intersectsy; +Examples.prototype.draftPath_join = draftPath_join; +Examples.prototype.draftPath_length = draftPath_length; +Examples.prototype.draftPath_offset = draftPath_offset; +Examples.prototype.draftPath_ops = draftPath_ops; +Examples.prototype.draftPath_reverse = draftPath_reverse; +Examples.prototype.draftPath_shiftalong = draftPath_shiftalong; +Examples.prototype.draftPath_shiftfractionalong = draftPath_shiftfractionalong; +Examples.prototype.draftPath_split = draftPath_split; +Examples.prototype.draftPath_start = draftPath_start; +Examples.prototype.draftPath_translate = draftPath_translate; +Examples.prototype.draftPath_trim = draftPath_trim; + +Examples.prototype.draftPlugin_cutonfold = draftPlugin_cutonfold; +Examples.prototype.draftPlugin_dimension = draftPlugin_dimension; +Examples.prototype.draftPlugin_grainline = draftPlugin_grainline; +Examples.prototype.draftPlugin_logo = draftPlugin_logo; +Examples.prototype.draftPlugin_scalebox = draftPlugin_scalebox; +Examples.prototype.draftPlugin_title = draftPlugin_title; + +Examples.prototype.draftPoint_angle = draftPoint_angle; +Examples.prototype.draftPoint_attr = draftPoint_attr; +Examples.prototype.draftPoint_clone = draftPoint_clone; +Examples.prototype.draftPoint_copy = draftPoint_copy; +Examples.prototype.draftPoint_dist = draftPoint_dist; +Examples.prototype.draftPoint_dx = draftPoint_dx; +Examples.prototype.draftPoint_dy = draftPoint_dy; +Examples.prototype.draftPoint_flipx = draftPoint_flipx; +Examples.prototype.draftPoint_flipy = draftPoint_flipy; +Examples.prototype.draftPoint_shift = draftPoint_shift; +Examples.prototype.draftPoint_shiftfractiontowards = draftPoint_shiftfractiontowards; +Examples.prototype.draftPoint_shifttowards = draftPoint_shifttowards; +Examples.prototype.draftPoint_shiftoutwards = draftPoint_shiftoutwards; +Examples.prototype.draftPoint_sitson = draftPoint_sitson; +Examples.prototype.draftPoint_rotate = draftPoint_rotate; +Examples.prototype.draftPoint_translate = draftPoint_translate; + +Examples.prototype.draftSettings_sa = draftSettings_sa; + +Examples.prototype.draftUtils_linesintersect = draftUtils_linesintersect; +Examples.prototype.draftUtils_beamsintersect = draftUtils_beamsintersect; +Examples.prototype.draftUtils_beamintersectsx = draftUtils_beamintersectsx; +Examples.prototype.draftUtils_beamintersectsy = draftUtils_beamintersectsy; +Examples.prototype.draftUtils_lineintersectscurve = draftUtils_lineintersectscurve; +Examples.prototype.draftUtils_curvesintersect = draftUtils_curvesintersect; +Examples.prototype.draftUtils_pointonbeam = draftUtils_pointonbeam; +Examples.prototype.draftUtils_pointonline = draftUtils_pointonline; +Examples.prototype.draftUtils_pointoncurve = draftUtils_pointoncurve; +Examples.prototype.draftUtils_circlesintersect = draftUtils_circlesintersect; +Examples.prototype.draftUtils_beamintersectscircle = draftUtils_beamintersectscircle; +Examples.prototype.draftUtils_lineintersectscircle = draftUtils_lineintersectscircle; // Add custom snippet //pattern.on("preRender", function(next) { diff --git a/packages/examples/src/path.divide.js b/packages/examples/src/path.divide.js deleted file mode 100644 index 3add794af59..00000000000 --- a/packages/examples/src/path.divide.js +++ /dev/null @@ -1,37 +0,0 @@ -import freesewing from "freesewing"; - -var pathDivide = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(55, 40); - points.B = new Point(10, 70); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 60); - points.CCp1 = new Point(50, -30); - points.D = new Point(50, 80); - points.DCp1 = new Point(140, 50); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .curve(points.DCp1, points.DCp1, points.D) - .close(); - - let i = 1; - for (let p of paths.example.divide()) { - paths[i] = p.attr( - "style", - `stroke-width: 4; stroke-opacity: 0.5; stroke: hsl(${i * - 70}, 100%, 50%)` - ); - i++; - } - - return part; - } -}; - -export default pathDivide; diff --git a/packages/examples/src/path.edge.js b/packages/examples/src/path.edge.js deleted file mode 100644 index 8ff9000e115..00000000000 --- a/packages/examples/src/path.edge.js +++ /dev/null @@ -1,36 +0,0 @@ -import freesewing from "freesewing"; - -var pathEdge = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - points.D = new Point(-60, 90); - points.E = new Point(90, 190); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .curve(points.E, points.D, points.A) - .close(); - - snippets.a = new Snippet("x", paths.example.edge("topLeft")); - snippets.b = new Snippet("x", paths.example.edge("topRight")); - snippets.c = new Snippet("x", paths.example.edge("bottomLeft")); - snippets.d = new Snippet("x", paths.example.edge("bottomRight")); - snippets.e = new Snippet("x", paths.example.edge("top")); - snippets.f = new Snippet("x", paths.example.edge("left")); - snippets.g = new Snippet("x", paths.example.edge("bottom")); - snippets.h = new Snippet("x", paths.example.edge("right")); - - return part; - } -}; - -export default pathEdge; diff --git a/packages/examples/src/path.end.js b/packages/examples/src/path.end.js deleted file mode 100644 index 74807fbbdba..00000000000 --- a/packages/examples/src/path.end.js +++ /dev/null @@ -1,24 +0,0 @@ -import freesewing from "freesewing"; - -var pathEnd = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C); - - snippets.x = new Snippet("x", paths.example.end()); - return part; - } -}; - -export default pathEnd; diff --git a/packages/examples/src/path.intersects.js b/packages/examples/src/path.intersects.js deleted file mode 100644 index 1ef40a583f1..00000000000 --- a/packages/examples/src/path.intersects.js +++ /dev/null @@ -1,42 +0,0 @@ -import freesewing from "freesewing"; - -var pathIntersects = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - points.D = new Point(50, 130); - points.DCp1 = new Point(150, 30); - - points._A = new Point(55, 40); - points._B = new Point(0, 55); - points._BCp2 = new Point(40, -20); - points._C = new Point(90, 40); - points._CCp1 = new Point(50, -30); - points._D = new Point(40, 120); - points._DCp1 = new Point(180, 40); - - paths.example1 = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .curve(points.DCp1, points.DCp1, points.D); - paths.example2 = new Path() - .move(points._A) - .line(points._B) - .curve(points._BCp2, points._CCp1, points._C) - .curve(points._DCp1, points._DCp1, points._D); - - for (let p of paths.example1.intersects(paths.example2)) - snippets[part.getId()] = new Snippet("x", p); - - return part; - } -}; - -export default pathIntersects; diff --git a/packages/examples/src/path.intersectsx.js b/packages/examples/src/path.intersectsx.js deleted file mode 100644 index cc85bc64d93..00000000000 --- a/packages/examples/src/path.intersectsx.js +++ /dev/null @@ -1,35 +0,0 @@ -import freesewing from "freesewing"; - -var pathIntersectsX = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(95, 50); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - points.D = new Point(50, 130); - points.DCp1 = new Point(150, 30); - - points.top = new Point(60, -10); - points.bot = new Point(60, 140); - paths.line = new Path() - .move(points.top) - .line(points.bot) - .attr("class", "lining dashed"); - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .curve(points.DCp1, points.DCp1, points.D); - - for (let p of paths.example.intersectsX(60)) - snippets[part.getId()] = new Snippet("x", p); - - return part; - } -}; - -export default pathIntersectsX; diff --git a/packages/examples/src/path.intersectsy.js b/packages/examples/src/path.intersectsy.js deleted file mode 100644 index cb27ce5fc08..00000000000 --- a/packages/examples/src/path.intersectsy.js +++ /dev/null @@ -1,34 +0,0 @@ -import freesewing from "freesewing"; - -var pathIntersectsY = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(55, 40); - points.B = new Point(10, 70); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 60); - points.CCp1 = new Point(50, -30); - points.D = new Point(50, 80); - points.DCp1 = new Point(140, 50); - - points.top = new Point(10, 58); - points.bot = new Point(130, 58); - paths.line = new Path() - .move(points.top) - .line(points.bot) - .attr("class", "lining dashed"); - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .curve(points.DCp1, points.DCp1, points.D); - for (let p of paths.example.intersectsY(58)) - snippets[part.getId()] = new Snippet("x", p); - - return part; - } -}; - -export default pathIntersectsY; diff --git a/packages/examples/src/path.join.js b/packages/examples/src/path.join.js deleted file mode 100644 index a825a13aef1..00000000000 --- a/packages/examples/src/path.join.js +++ /dev/null @@ -1,32 +0,0 @@ -import freesewing from "freesewing"; - -var pathJoin = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.path1 = new Path() - .move(points.A) - .line(points.B) - .attr("class", "various"); - - paths.path2 = new Path() - .move(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .attr("class", "canvas"); - - paths.joint = paths.path1 - .join(paths.path2) - .attr("class", "note lashed stroke-xl"); - - return part; - } -}; - -export default pathJoin; diff --git a/packages/examples/src/path.length.js b/packages/examples/src/path.length.js deleted file mode 100644 index d332677ba60..00000000000 --- a/packages/examples/src/path.length.js +++ /dev/null @@ -1,38 +0,0 @@ -import freesewing from "freesewing"; - -var pathLength = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C); - - macro("pd", { - path: paths.example, - d: -20 - }); - - macro("pd", { - path: new Path().move(points.B).line(points.A), - d: 10 - }); - - macro("pd", { - path: new Path().move(points.B).curve(points.BCp2, points.CCp1, points.C), - d: -10 - }); - - return part; - } -}; - -export default pathLength; diff --git a/packages/examples/src/path.offset.js b/packages/examples/src/path.offset.js deleted file mode 100644 index c8c12c6c675..00000000000 --- a/packages/examples/src/path.offset.js +++ /dev/null @@ -1,40 +0,0 @@ -import freesewing from "freesewing"; -import { box } from "./shared"; - -var pathOffset = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .line(points.A) - .close(); - - paths.offset = paths.example.offset(-10).attr("class", "interfacing"); - - paths.lineOffset = new Path() - .move(points.A) - .line(points.B) - .offset(-5) - .attr("class", "various"); - - paths.curveOffset = new Path() - .move(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .offset(-5) - .attr("class", "canvas"); - - return part; - } -}; - -export default pathOffset; diff --git a/packages/examples/src/path.ops.js b/packages/examples/src/path.ops.js deleted file mode 100644 index faeb4004462..00000000000 --- a/packages/examples/src/path.ops.js +++ /dev/null @@ -1,62 +0,0 @@ -import freesewing from "freesewing"; - -var pathOps = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(10, 10) - .attr("data-text", "Move to point A") - .attr("data-text-class", "center text-xs"); - points.B = new Point(70, 30); - points.BCp2 = new Point(40, 10); - points.C = new Point(90, -50); - points.CCp1 = new Point(125, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .close(); - - paths.handle1 = new Path() - .move(points.B) - .line(points.BCp2) - .attr("class", "note dashed"); - paths.handle2 = new Path() - .move(points.C) - .line(points.CCp1) - .attr("class", "note dashed"); - - snippets.A = new Snippet("notch", points.A); - snippets.B = new Snippet("notch", points.B); - snippets.C = new Snippet("notch", points.C); - snippets.Bcp2 = new Snippet("x", points.BCp2); - snippets.Ccp1 = new Snippet("x", points.CCp1); - - paths.textLine = new Path() - .move(points.A) - .line(points.B) - .attr("data-text", "Line to point B") - .attr("data-text-class", "center text-xs"); - - paths.textCurve = new Path() - .move(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .attr( - "data-text", - "Curve to point C, using BCp2 and CCp1 as control points" - ) - .attr("data-text-class", "center text-xs"); - - paths.textClose = new Path() - .move(points.A) - .line(points.C) - .attr("data-text", "Close path") - .attr("data-text-class", "center text-xs"); - - return part; - } -}; - -export default pathOps; diff --git a/packages/examples/src/path.reverse.js b/packages/examples/src/path.reverse.js deleted file mode 100644 index 8a2521d1fdf..00000000000 --- a/packages/examples/src/path.reverse.js +++ /dev/null @@ -1,27 +0,0 @@ -import freesewing from "freesewing"; -import { box } from "./shared"; - -var pathReverse = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .attr("data-text", "I am the original path"); - - paths.reverse = paths.example - .reverse() - .attr("data-text", "I am the reversed path"); - - return part; - } -}; - -export default pathReverse; diff --git a/packages/examples/src/path.shiftalong.js b/packages/examples/src/path.shiftalong.js deleted file mode 100644 index d0101ca1b06..00000000000 --- a/packages/examples/src/path.shiftalong.js +++ /dev/null @@ -1,37 +0,0 @@ -import freesewing from "freesewing"; - -var pathShiftAlong = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C); - - points.X1 = paths.example - .shiftAlong(20) - .attr("data-text", "Shifted 2cm\nalong this path") - .attr("data-text-class", "center") - .attr("data-text-lineheight", 6); - points.X2 = paths.example - .shiftAlong(90) - .attr("data-text", "Shifted 9cm\nalong this path") - .attr("data-text-class", "center") - .attr("data-text-lineheight", 6); - - snippets.Xl = new Snippet("x", points.X1); - snippets.X2 = new Snippet("x", points.X2); - - return part; - } -}; - -export default pathShiftAlong; diff --git a/packages/examples/src/path.shiftfractionalong.js b/packages/examples/src/path.shiftfractionalong.js deleted file mode 100644 index 05f9a79c579..00000000000 --- a/packages/examples/src/path.shiftfractionalong.js +++ /dev/null @@ -1,37 +0,0 @@ -import freesewing from "freesewing"; - -var pathShiftFractionAlong = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C); - - points.X1 = paths.example - .shiftFractionAlong(0.2) - .attr("data-text", "Shifted 20%\nalong this path") - .attr("data-text-class", "center") - .attr("data-text-lineheight", 6); - points.X2 = paths.example - .shiftFractionAlong(0.9) - .attr("data-text", "Shifted 90%\nalong this path") - .attr("data-text-class", "center") - .attr("data-text-lineheight", 6); - - snippets.Xl = new Snippet("x", points.X1); - snippets.X2 = new Snippet("x", points.X2); - - return part; - } -}; - -export default pathShiftFractionAlong; diff --git a/packages/examples/src/path.split.js b/packages/examples/src/path.split.js deleted file mode 100644 index 66985e1d90c..00000000000 --- a/packages/examples/src/path.split.js +++ /dev/null @@ -1,44 +0,0 @@ -import freesewing from "freesewing"; - -var pathSplit = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - points.D = new Point(50, 130); - points.DCp1 = new Point(150, 30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .curve(points.DCp1, points.DCp1, points.D); - - paths.example2 = new Path() - .move(points.D) - .curve(points.DCp1, points.DCp1, points.C) - .curve(points.CCp1, points.BCp2, points.B) - .line(points.A); - - points.split = paths.example.shiftAlong(20); - snippets.x = new Snippet("x", points.split); - - let halves = paths.example2.split(points.split); - for (let i in halves) { - paths[i] = halves[i].attr( - "style", - `stroke-width: 3; stroke-opacity: 0.5; stroke: hsl(${i * - 70}, 100%, 50%)` - ); - } - - return part; - } -}; - -export default pathSplit; diff --git a/packages/examples/src/path.start.js b/packages/examples/src/path.start.js deleted file mode 100644 index ad615165c2f..00000000000 --- a/packages/examples/src/path.start.js +++ /dev/null @@ -1,24 +0,0 @@ -import freesewing from "freesewing"; - -var pathStart = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C); - - snippets.x = new Snippet("x", paths.example.start()); - return part; - } -}; - -export default pathStart; diff --git a/packages/examples/src/path.translate.js b/packages/examples/src/path.translate.js deleted file mode 100644 index 1750831a48e..00000000000 --- a/packages/examples/src/path.translate.js +++ /dev/null @@ -1,41 +0,0 @@ -var pathTranslate = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.A = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .attr("data-text", "Path A") - .attr("data-text-class", "center"); - - paths.B = paths.A.translate(60, 30).attr( - "data-text", - "with a translate(60,30) transform applied" - ); - - points.step1 = points.B.shift(0, 60); - points.step2 = points.step1.shift(-90, 30); - macro("ld", { - from: points.B, - to: points.step1, - noStartMarker: true - }); - macro("ld", { - from: points.step1, - to: points.step2, - noStartMarker: true - }); - - return part; - } -}; - -export default pathTranslate; diff --git a/packages/examples/src/path.trim.js b/packages/examples/src/path.trim.js deleted file mode 100644 index 3172015eaea..00000000000 --- a/packages/examples/src/path.trim.js +++ /dev/null @@ -1,50 +0,0 @@ -var pathTrim = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.center = new Point(0, 0); - points.base = new Point(0, 10); - points.tip = new Point(0, 50); - points.tipCpRight = new Point(30, 50); - points.tipCpLeft = new Point(-30, 50); - paths.example = new Path().move(points.base); - for (let i = 0; i < 4; i++) { - points["base" + i] = points.base.rotate(60 * i, points.center); - points["tip" + i] = points.tip.rotate(60 * i, points.center); - points["tipCpRight" + i] = points.tipCpRight.rotate( - 60 * i, - points.center - ); - points["tipCpLeft" + i] = points.tipCpLeft.rotate(60 * i, points.center); - if (i < 2) { - paths.example - .line(points["base" + i]) - .curve(points["base" + i], points["tipCpLeft" + i], points["tip" + i]) - .curve( - points["tipCpRight" + i], - points["base" + i], - points["base" + i] - ); - } else { - paths.example - .line(points["base" + i]) - .line(points["tip" + i]) - .line(points["tipCpRight" + i]) - .line(points["base" + i]); - } - } - - paths.offset = paths.example - .offset(10) - .attr("class", "lining dotted stroke-sm"); - - paths.trimmed = paths.offset - .trim() - .attr("class", "various stroke-xl") - .attr("style", "stroke-opacity: 0.5;"); - return part; - } -}; - -export default pathTrim; diff --git a/packages/examples/src/path_divide.js b/packages/examples/src/path_divide.js new file mode 100644 index 00000000000..ce01dca1921 --- /dev/null +++ b/packages/examples/src/path_divide.js @@ -0,0 +1,37 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(55, 40); + points.B = new Point(10, 70); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 60); + points.CCp1 = new Point(50, -30); + points.D = new Point(50, 80); + points.DCp1 = new Point(140, 50); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .curve(points.DCp1, points.DCp1, points.D) + .close(); + + let i = 1; + for (let p of paths.example.divide()) { + paths[i] = p.attr( + "style", + `stroke-width: 4; stroke-opacity: 0.5; stroke: hsl(${i * 70}, 100%, 50%)` + ); + i++; + } + + return part; +}; diff --git a/packages/examples/src/path_edge.js b/packages/examples/src/path_edge.js new file mode 100644 index 00000000000..1990d7352ce --- /dev/null +++ b/packages/examples/src/path_edge.js @@ -0,0 +1,37 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + points.D = new Point(-60, 90); + points.E = new Point(90, 190); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .curve(points.E, points.D, points.A) + .close(); + + snippets.a = new Snippet("x", paths.example.edge("topLeft")); + snippets.b = new Snippet("x", paths.example.edge("topRight")); + snippets.c = new Snippet("x", paths.example.edge("bottomLeft")); + snippets.d = new Snippet("x", paths.example.edge("bottomRight")); + snippets.e = new Snippet("x", paths.example.edge("top")); + snippets.f = new Snippet("x", paths.example.edge("left")); + snippets.g = new Snippet("x", paths.example.edge("bottom")); + snippets.h = new Snippet("x", paths.example.edge("right")); + + return part; +}; diff --git a/packages/examples/src/path_end.js b/packages/examples/src/path_end.js new file mode 100644 index 00000000000..96f62a08e3c --- /dev/null +++ b/packages/examples/src/path_end.js @@ -0,0 +1,25 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C); + + snippets.x = new Snippet("x", paths.example.end()); + return part; +}; diff --git a/packages/examples/src/path_intersects.js b/packages/examples/src/path_intersects.js new file mode 100644 index 00000000000..cf3801fef09 --- /dev/null +++ b/packages/examples/src/path_intersects.js @@ -0,0 +1,43 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + points.D = new Point(50, 130); + points.DCp1 = new Point(150, 30); + + points._A = new Point(55, 40); + points._B = new Point(0, 55); + points._BCp2 = new Point(40, -20); + points._C = new Point(90, 40); + points._CCp1 = new Point(50, -30); + points._D = new Point(40, 120); + points._DCp1 = new Point(180, 40); + + paths.example1 = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .curve(points.DCp1, points.DCp1, points.D); + paths.example2 = new Path() + .move(points._A) + .line(points._B) + .curve(points._BCp2, points._CCp1, points._C) + .curve(points._DCp1, points._DCp1, points._D); + + for (let p of paths.example1.intersects(paths.example2)) + snippets[part.getId()] = new Snippet("x", p); + + return part; +}; diff --git a/packages/examples/src/path_intersectsx.js b/packages/examples/src/path_intersectsx.js new file mode 100644 index 00000000000..4dda0df5599 --- /dev/null +++ b/packages/examples/src/path_intersectsx.js @@ -0,0 +1,36 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(95, 50); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + points.D = new Point(50, 130); + points.DCp1 = new Point(150, 30); + + points.top = new Point(60, -10); + points.bot = new Point(60, 140); + paths.line = new Path() + .move(points.top) + .line(points.bot) + .attr("class", "lining dashed"); + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .curve(points.DCp1, points.DCp1, points.D); + + for (let p of paths.example.intersectsX(60)) + snippets[part.getId()] = new Snippet("x", p); + + return part; +}; diff --git a/packages/examples/src/path_intersectsy.js b/packages/examples/src/path_intersectsy.js new file mode 100644 index 00000000000..dae7411efe6 --- /dev/null +++ b/packages/examples/src/path_intersectsy.js @@ -0,0 +1,35 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(55, 40); + points.B = new Point(10, 70); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 60); + points.CCp1 = new Point(50, -30); + points.D = new Point(50, 80); + points.DCp1 = new Point(140, 50); + + points.top = new Point(10, 58); + points.bot = new Point(130, 58); + paths.line = new Path() + .move(points.top) + .line(points.bot) + .attr("class", "lining dashed"); + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .curve(points.DCp1, points.DCp1, points.D); + for (let p of paths.example.intersectsY(58)) + snippets[part.getId()] = new Snippet("x", p); + + return part; +}; diff --git a/packages/examples/src/path_join.js b/packages/examples/src/path_join.js new file mode 100644 index 00000000000..ef1e6680621 --- /dev/null +++ b/packages/examples/src/path_join.js @@ -0,0 +1,33 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.path1 = new Path() + .move(points.A) + .line(points.B) + .attr("class", "various"); + + paths.path2 = new Path() + .move(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .attr("class", "canvas"); + + paths.joint = paths.path1 + .join(paths.path2) + .attr("class", "note lashed stroke-xl"); + + return part; +}; diff --git a/packages/examples/src/path_length.js b/packages/examples/src/path_length.js new file mode 100644 index 00000000000..00c87966ee8 --- /dev/null +++ b/packages/examples/src/path_length.js @@ -0,0 +1,39 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C); + + macro("pd", { + path: paths.example, + d: -20 + }); + + macro("pd", { + path: new Path().move(points.B).line(points.A), + d: 10 + }); + + macro("pd", { + path: new Path().move(points.B).curve(points.BCp2, points.CCp1, points.C), + d: -10 + }); + + return part; +}; diff --git a/packages/examples/src/path_offset.js b/packages/examples/src/path_offset.js new file mode 100644 index 00000000000..1e8febff6f6 --- /dev/null +++ b/packages/examples/src/path_offset.js @@ -0,0 +1,42 @@ +import { box } from "./shared"; + +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .line(points.A) + .close(); + + paths.offset = paths.example.offset(-10).attr("class", "interfacing"); + + paths.lineOffset = new Path() + .move(points.A) + .line(points.B) + .offset(-5) + .attr("class", "various"); + + paths.curveOffset = new Path() + .move(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .offset(-5) + .attr("class", "canvas"); + + return part; +}; diff --git a/packages/examples/src/path_ops.js b/packages/examples/src/path_ops.js new file mode 100644 index 00000000000..945b0785a95 --- /dev/null +++ b/packages/examples/src/path_ops.js @@ -0,0 +1,63 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(10, 10) + .attr("data-text", "Move to point A") + .attr("data-text-class", "center text-xs"); + points.B = new Point(70, 30); + points.BCp2 = new Point(40, 10); + points.C = new Point(90, -50); + points.CCp1 = new Point(125, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .close(); + + paths.handle1 = new Path() + .move(points.B) + .line(points.BCp2) + .attr("class", "note dashed"); + paths.handle2 = new Path() + .move(points.C) + .line(points.CCp1) + .attr("class", "note dashed"); + + snippets.A = new Snippet("notch", points.A); + snippets.B = new Snippet("notch", points.B); + snippets.C = new Snippet("notch", points.C); + snippets.Bcp2 = new Snippet("x", points.BCp2); + snippets.Ccp1 = new Snippet("x", points.CCp1); + + paths.textLine = new Path() + .move(points.A) + .line(points.B) + .attr("data-text", "Line to point B") + .attr("data-text-class", "center text-xs"); + + paths.textCurve = new Path() + .move(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .attr( + "data-text", + "Curve to point C, using BCp2 and CCp1 as control points" + ) + .attr("data-text-class", "center text-xs"); + + paths.textClose = new Path() + .move(points.A) + .line(points.C) + .attr("data-text", "Close path") + .attr("data-text-class", "center text-xs"); + + return part; +}; diff --git a/packages/examples/src/path_reverse.js b/packages/examples/src/path_reverse.js new file mode 100644 index 00000000000..3551407cf16 --- /dev/null +++ b/packages/examples/src/path_reverse.js @@ -0,0 +1,29 @@ +import { box } from "./shared"; + +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .attr("data-text", "I am the original path"); + + paths.reverse = paths.example + .reverse() + .attr("data-text", "I am the reversed path"); + + return part; +}; diff --git a/packages/examples/src/path_shiftalong.js b/packages/examples/src/path_shiftalong.js new file mode 100644 index 00000000000..24468db9c88 --- /dev/null +++ b/packages/examples/src/path_shiftalong.js @@ -0,0 +1,38 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C); + + points.X1 = paths.example + .shiftAlong(20) + .attr("data-text", "Shifted 2cm\nalong this path") + .attr("data-text-class", "center") + .attr("data-text-lineheight", 6); + points.X2 = paths.example + .shiftAlong(90) + .attr("data-text", "Shifted 9cm\nalong this path") + .attr("data-text-class", "center") + .attr("data-text-lineheight", 6); + + snippets.Xl = new Snippet("x", points.X1); + snippets.X2 = new Snippet("x", points.X2); + + return part; +}; diff --git a/packages/examples/src/path_shiftfractionalong.js b/packages/examples/src/path_shiftfractionalong.js new file mode 100644 index 00000000000..8e2f1041349 --- /dev/null +++ b/packages/examples/src/path_shiftfractionalong.js @@ -0,0 +1,31 @@ +export default part => { + // prettier-ignore + let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C); + + points.X1 = paths.example + .shiftFractionAlong(0.2) + .attr("data-text", "Shifted 20%\nalong this path") + .attr("data-text-class", "center") + .attr("data-text-lineheight", 6); + points.X2 = paths.example + .shiftFractionAlong(0.9) + .attr("data-text", "Shifted 90%\nalong this path") + .attr("data-text-class", "center") + .attr("data-text-lineheight", 6); + + snippets.Xl = new Snippet("x", points.X1); + snippets.X2 = new Snippet("x", points.X2); + + return part; +}; diff --git a/packages/examples/src/path_split.js b/packages/examples/src/path_split.js new file mode 100644 index 00000000000..02499781747 --- /dev/null +++ b/packages/examples/src/path_split.js @@ -0,0 +1,44 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + points.D = new Point(50, 130); + points.DCp1 = new Point(150, 30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .curve(points.DCp1, points.DCp1, points.D); + + paths.example2 = new Path() + .move(points.D) + .curve(points.DCp1, points.DCp1, points.C) + .curve(points.CCp1, points.BCp2, points.B) + .line(points.A); + + points.split = paths.example.shiftAlong(20); + snippets.x = new Snippet("x", points.split); + + let halves = paths.example2.split(points.split); + for (let i in halves) { + paths[i] = halves[i].attr( + "style", + `stroke-width: 3; stroke-opacity: 0.5; stroke: hsl(${i * 70}, 100%, 50%)` + ); + } + + return part; +}; diff --git a/packages/examples/src/path_start.js b/packages/examples/src/path_start.js new file mode 100644 index 00000000000..bee3845c6bb --- /dev/null +++ b/packages/examples/src/path_start.js @@ -0,0 +1,25 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C); + + snippets.x = new Snippet("x", paths.example.start()); + return part; +}; diff --git a/packages/examples/src/path_translate.js b/packages/examples/src/path_translate.js new file mode 100644 index 00000000000..4f7b27cbdc7 --- /dev/null +++ b/packages/examples/src/path_translate.js @@ -0,0 +1,44 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.A = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .attr("data-text", "Path A") + .attr("data-text-class", "center"); + + paths.B = paths.A.translate(60, 30).attr( + "data-text", + "with a translate(60,30) transform applied" + ); + + points.step1 = points.B.shift(0, 60); + points.step2 = points.step1.shift(-90, 30); + macro("ld", { + from: points.B, + to: points.step1, + noStartMarker: true + }); + macro("ld", { + from: points.step1, + to: points.step2, + noStartMarker: true + }); + + return part; +}; diff --git a/packages/examples/src/path_trim.js b/packages/examples/src/path_trim.js new file mode 100644 index 00000000000..2dc97371a3e --- /dev/null +++ b/packages/examples/src/path_trim.js @@ -0,0 +1,50 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.center = new Point(0, 0); + points.base = new Point(0, 10); + points.tip = new Point(0, 50); + points.tipCpRight = new Point(30, 50); + points.tipCpLeft = new Point(-30, 50); + paths.example = new Path().move(points.base); + for (let i = 0; i < 4; i++) { + points["base" + i] = points.base.rotate(60 * i, points.center); + points["tip" + i] = points.tip.rotate(60 * i, points.center); + points["tipCpRight" + i] = points.tipCpRight.rotate(60 * i, points.center); + points["tipCpLeft" + i] = points.tipCpLeft.rotate(60 * i, points.center); + if (i < 2) { + paths.example + .line(points["base" + i]) + .curve(points["base" + i], points["tipCpLeft" + i], points["tip" + i]) + .curve( + points["tipCpRight" + i], + points["base" + i], + points["base" + i] + ); + } else { + paths.example + .line(points["base" + i]) + .line(points["tip" + i]) + .line(points["tipCpRight" + i]) + .line(points["base" + i]); + } + } + + paths.offset = paths.example + .offset(10) + .attr("class", "lining dotted stroke-sm"); + + paths.trimmed = paths.offset + .trim() + .attr("class", "various stroke-xl") + .attr("style", "stroke-opacity: 0.5;"); + return part; +}; diff --git a/packages/examples/src/plugin.cutonfold.js b/packages/examples/src/plugin.cutonfold.js deleted file mode 100644 index de8a79d2480..00000000000 --- a/packages/examples/src/plugin.cutonfold.js +++ /dev/null @@ -1,30 +0,0 @@ -import freesewing from "freesewing"; - -var pluginCutonfold = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, macro} = part.shorthand(); - - points.topLeft = new Point(0, 0); - points.topRight = new Point(150, 0); - points.bottomRight = new Point(150, 50); - points.bottomLeft = new Point(0, 50); - - paths.box = new Path() - .move(points.topLeft) - .line(points.topRight) - .line(points.bottomRight) - .line(points.bottomLeft) - .close(); - - macro("cutonfold", { - from: points.topRight, - to: points.topLeft, - grainline: true - }); - - return part; - } -}; - -export default pluginCutonfold; diff --git a/packages/examples/src/plugin.dimension.js b/packages/examples/src/plugin.dimension.js deleted file mode 100644 index 37b50ea8aca..00000000000 --- a/packages/examples/src/plugin.dimension.js +++ /dev/null @@ -1,56 +0,0 @@ -import freesewing from "freesewing"; - -var pluginDimension = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, macro} = part.shorthand(); - - points.A = new Point(0, 0); - points.B = new Point(0, 100); - points.C = new Point(50, 100); - points.D = new Point(100, 50); - points.DCp1 = new Point(100, 0); - - paths.box = new Path() - .move(points.A) - .line(points.B) - .line(points.C) - .line(points.D) - .curve(points.DCp1, points.A, points.A) - .close(); - - macro("vd", { - from: points.A, - to: points.B, - x: points.A.x - 15 - }); - - macro("hd", { - from: points.B, - to: points.C, - y: points.B.y + 15 - }); - - macro("ld", { - from: points.C, - to: points.D, - d: -15 - }); - - macro("ld", { - from: points.C, - to: points.D, - d: -30, - text: "Custom text" - }); - - macro("pd", { - path: new Path().move(points.A).curve(points.A, points.DCp1, points.D), - d: -15 - }); - - return part; - } -}; - -export default pluginDimension; diff --git a/packages/examples/src/plugin.grainline.js b/packages/examples/src/plugin.grainline.js deleted file mode 100644 index 18b4bbda1e2..00000000000 --- a/packages/examples/src/plugin.grainline.js +++ /dev/null @@ -1,20 +0,0 @@ -import freesewing from "freesewing"; - -var pluginGrainline = { - draft: function(part) { - // prettier-ignore - let {Point, points, macro} = part.shorthand(); - - points.grainlineFrom = new Point(10, 10); - points.grainlineTo = new Point(100, 10); - - macro("grainline", { - from: points.grainlineFrom, - to: points.grainlineTo - }); - - return part; - } -}; - -export default pluginGrainline; diff --git a/packages/examples/src/plugin.logo.js b/packages/examples/src/plugin.logo.js deleted file mode 100644 index e26ed97fe1e..00000000000 --- a/packages/examples/src/plugin.logo.js +++ /dev/null @@ -1,25 +0,0 @@ -var pluginLogo = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, snippets, Snippet} = part.shorthand(); - - points.topLeft = new Point(0, 0); - points.topRight = new Point(120, 0); - points.bottomRight = new Point(120, 70); - points.bottomLeft = new Point(0, 70); - points.logoAnchor = new Point(60, 47); - - paths.box = new Path() - .move(points.topLeft) - .line(points.topRight) - .line(points.bottomRight) - .line(points.bottomLeft) - .close(); - - snippets.logo = new Snippet("logo", points.logoAnchor); - - return part; - } -}; - -export default pluginLogo; diff --git a/packages/examples/src/plugin.scalebox.js b/packages/examples/src/plugin.scalebox.js deleted file mode 100644 index 6a708aaca20..00000000000 --- a/packages/examples/src/plugin.scalebox.js +++ /dev/null @@ -1,16 +0,0 @@ -var pluginScalebox = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, macro} = part.shorthand(); - - points.anchor = new Point(0, 0); - - macro("scalebox", { - at: points.anchor - }); - - return part; - } -}; - -export default pluginScalebox; diff --git a/packages/examples/src/plugin.title.js b/packages/examples/src/plugin.title.js deleted file mode 100644 index 26da415c585..00000000000 --- a/packages/examples/src/plugin.title.js +++ /dev/null @@ -1,29 +0,0 @@ -var pluginTitle = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, macro} = part.shorthand(); - - points.topLeft = new Point(0, 0); - points.topRight = new Point(120, 0); - points.bottomRight = new Point(120, 70); - points.bottomLeft = new Point(0, 70); - points.titleAnchor = new Point(60, 35); - - paths.box = new Path() - .move(points.topLeft) - .line(points.topRight) - .line(points.bottomRight) - .line(points.bottomLeft) - .close(); - - macro("title", { - at: points.titleAnchor, - nr: 4, - title: "sleeve" - }); - - return part; - } -}; - -export default pluginTitle; diff --git a/packages/examples/src/plugin_cutonfold.js b/packages/examples/src/plugin_cutonfold.js new file mode 100644 index 00000000000..984cf158fe3 --- /dev/null +++ b/packages/examples/src/plugin_cutonfold.js @@ -0,0 +1,23 @@ +export default part => { + let { Point, points, Path, paths, macro } = part.shorthand(); + + points.topLeft = new Point(0, 0); + points.topRight = new Point(150, 0); + points.bottomRight = new Point(150, 50); + points.bottomLeft = new Point(0, 50); + + paths.box = new Path() + .move(points.topLeft) + .line(points.topRight) + .line(points.bottomRight) + .line(points.bottomLeft) + .close(); + + macro("cutonfold", { + from: points.topRight, + to: points.topLeft, + grainline: true + }); + + return part; +}; diff --git a/packages/examples/src/plugin_dimension.js b/packages/examples/src/plugin_dimension.js new file mode 100644 index 00000000000..48c6dd5c67c --- /dev/null +++ b/packages/examples/src/plugin_dimension.js @@ -0,0 +1,49 @@ +export default part => { + let { Point, points, Path, paths, macro } = part.shorthand(); + + points.A = new Point(0, 0); + points.B = new Point(0, 100); + points.C = new Point(50, 100); + points.D = new Point(100, 50); + points.DCp1 = new Point(100, 0); + + paths.box = new Path() + .move(points.A) + .line(points.B) + .line(points.C) + .line(points.D) + .curve(points.DCp1, points.A, points.A) + .close(); + + macro("vd", { + from: points.A, + to: points.B, + x: points.A.x - 15 + }); + + macro("hd", { + from: points.B, + to: points.C, + y: points.B.y + 15 + }); + + macro("ld", { + from: points.C, + to: points.D, + d: -15 + }); + + macro("ld", { + from: points.C, + to: points.D, + d: -30, + text: "Custom text" + }); + + macro("pd", { + path: new Path().move(points.A).curve(points.A, points.DCp1, points.D), + d: -15 + }); + + return part; +}; diff --git a/packages/examples/src/plugin_grainline.js b/packages/examples/src/plugin_grainline.js new file mode 100644 index 00000000000..56e18f6be9e --- /dev/null +++ b/packages/examples/src/plugin_grainline.js @@ -0,0 +1,13 @@ +export default part => { + let { Point, points, macro } = part.shorthand(); + + points.grainlineFrom = new Point(10, 10); + points.grainlineTo = new Point(100, 10); + + macro("grainline", { + from: points.grainlineFrom, + to: points.grainlineTo + }); + + return part; +}; diff --git a/packages/examples/src/plugin_logo.js b/packages/examples/src/plugin_logo.js new file mode 100644 index 00000000000..97010a70718 --- /dev/null +++ b/packages/examples/src/plugin_logo.js @@ -0,0 +1,20 @@ +export default part => { + let { Point, points, Path, paths, snippets, Snippet } = part.shorthand(); + + points.topLeft = new Point(0, 0); + points.topRight = new Point(120, 0); + points.bottomRight = new Point(120, 70); + points.bottomLeft = new Point(0, 70); + points.logoAnchor = new Point(60, 47); + + paths.box = new Path() + .move(points.topLeft) + .line(points.topRight) + .line(points.bottomRight) + .line(points.bottomLeft) + .close(); + + snippets.logo = new Snippet("logo", points.logoAnchor); + + return part; +}; diff --git a/packages/examples/src/plugin_scalebox.js b/packages/examples/src/plugin_scalebox.js new file mode 100644 index 00000000000..66fbf422d71 --- /dev/null +++ b/packages/examples/src/plugin_scalebox.js @@ -0,0 +1,11 @@ +export default part => { + let { Point, points, Path, paths, macro } = part.shorthand(); + + points.anchor = new Point(0, 0); + + macro("scalebox", { + at: points.anchor + }); + + return part; +}; diff --git a/packages/examples/src/plugin_title.js b/packages/examples/src/plugin_title.js new file mode 100644 index 00000000000..90f6b28befb --- /dev/null +++ b/packages/examples/src/plugin_title.js @@ -0,0 +1,24 @@ +export default part => { + let { Point, points, Path, paths, macro } = part.shorthand(); + + points.topLeft = new Point(0, 0); + points.topRight = new Point(120, 0); + points.bottomRight = new Point(120, 70); + points.bottomLeft = new Point(0, 70); + points.titleAnchor = new Point(60, 35); + + paths.box = new Path() + .move(points.topLeft) + .line(points.topRight) + .line(points.bottomRight) + .line(points.bottomLeft) + .close(); + + macro("title", { + at: points.titleAnchor, + nr: 4, + title: "sleeve" + }); + + return part; +}; diff --git a/packages/examples/src/point.angle.js b/packages/examples/src/point.angle.js deleted file mode 100644 index 0dafd33c165..00000000000 --- a/packages/examples/src/point.angle.js +++ /dev/null @@ -1,58 +0,0 @@ -import freesewing from "freesewing"; - -var pointAngle = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets} = part.shorthand(); - - points.sun = new Point(40, 40); - points.moon1 = new Point(70, 40) - .attr("data-text", "0") - .attr("data-text-class", "text-xl"); - points.moon2 = new Point(40, 10) - .attr("data-text", 90) - .attr("data-text-class", "text-xl"); - points.moon3 = new Point(10, 40) - .attr("data-text", 180) - .attr("data-text-class", "text-xl"); - points.moon4 = new Point(40, 70) - .attr("data-text", 270) - .attr("data-text-class", "text-xl"); - points.moon5 = points.moon1.rotate(-45, points.sun); - points.moon5 - .attr("data-text", points.sun.angle(points.moon5)) - .attr("data-text-class", "text-xl"); - - paths.moon1 = new Path() - .move(points.sun) - .line(points.moon1) - .attr("class", "dashed note"); - paths.moon2 = new Path() - .move(points.sun) - .line(points.moon2) - .attr("class", "dashed note"); - paths.moon3 = new Path() - .move(points.sun) - .line(points.moon3) - .attr("class", "dashed note"); - paths.moon4 = new Path() - .move(points.sun) - .line(points.moon4) - .attr("class", "dashed note"); - paths.moon5 = new Path() - .move(points.sun) - .line(points.moon5) - .attr("class", "dashed note"); - - snippets.notch = new Snippet("notch", points.sun); - snippets.notch1 = new Snippet("x", points.moon1); - snippets.notch2 = new Snippet("x", points.moon2); - snippets.notch3 = new Snippet("x", points.moon3); - snippets.notch4 = new Snippet("x", points.moon4); - snippets.notch5 = new Snippet("x", points.moon5); - - return part; - } -}; - -export default pointAngle; diff --git a/packages/examples/src/point.attr.js b/packages/examples/src/point.attr.js deleted file mode 100644 index 2b69beb82e5..00000000000 --- a/packages/examples/src/point.attr.js +++ /dev/null @@ -1,22 +0,0 @@ -import freesewing from "freesewing"; -import { box } from "./shared"; - -var pointAttr = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets} = part.shorthand(); - - box(part); - - points.anchor = new Point(50, 25) - .attr("data-text", "Hello world!\nThis is\na line break.") - .attr("data-text-class", "text-xl center") - .attr("data-text-lineheight", 10); - - snippets.notch = new Snippet("x", points.anchor); - - return part; - } -}; - -export default pointAttr; diff --git a/packages/examples/src/point.clone.js b/packages/examples/src/point.clone.js deleted file mode 100644 index 41dfcbec0db..00000000000 --- a/packages/examples/src/point.clone.js +++ /dev/null @@ -1,23 +0,0 @@ -import freesewing from "freesewing"; -import { box } from "./shared"; - -var pointClone = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets} = part.shorthand(); - - box(part); - - points.A = new Point(25, 25) - .attr("data-text", "Point A") - .attr("data-text-class", "text-xl") - .attr("data-text-fill-opacity", "0.5"); - points.B = points.A.clone().attr("data-text", "Point B"); - - snippets.x = new Snippet("x", points.A); - - return part; - } -}; - -export default pointClone; diff --git a/packages/examples/src/point.copy.js b/packages/examples/src/point.copy.js deleted file mode 100644 index a96be675da4..00000000000 --- a/packages/examples/src/point.copy.js +++ /dev/null @@ -1,22 +0,0 @@ -import freesewing from "freesewing"; -import { box } from "./shared"; - -var pointCopy = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets} = part.shorthand(); - - box(part); - - points.A = new Point(50, 25) - .attr("data-text", "Point A") - .attr("data-text-class", "text-xl"); - points.B = points.A.copy().attr("data-text", "Point B"); - - snippets.x = new Snippet("x", points.A); - - return part; - } -}; - -export default pointCopy; diff --git a/packages/examples/src/point.dist.js b/packages/examples/src/point.dist.js deleted file mode 100644 index 737c9c4a5dd..00000000000 --- a/packages/examples/src/point.dist.js +++ /dev/null @@ -1,23 +0,0 @@ -import freesewing from "freesewing"; - -var pointDist = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets, macro} = part.shorthand(); - - points.from = new Point(10, 10); - points.to = new Point(90, 40); - - macro("ld", { - from: points.from, - to: points.to - }); - - snippets.notch1 = new Snippet("x", points.from); - snippets.notch2 = new Snippet("x", points.to); - - return part; - } -}; - -export default pointDist; diff --git a/packages/examples/src/point.dx.js b/packages/examples/src/point.dx.js deleted file mode 100644 index 8fa42e2084e..00000000000 --- a/packages/examples/src/point.dx.js +++ /dev/null @@ -1,24 +0,0 @@ -import freesewing from "freesewing"; - -var pointDx = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets, macro} = part.shorthand(); - - points.from = new Point(10, 10); - points.to = new Point(90, 40); - - macro("hd", { - from: points.from, - to: points.to, - y: 25 - }); - - snippets.notch1 = new Snippet("x", points.from); - snippets.notch2 = new Snippet("x", points.to); - - return part; - } -}; - -export default pointDx; diff --git a/packages/examples/src/point.dy.js b/packages/examples/src/point.dy.js deleted file mode 100644 index 00ab0fbf39a..00000000000 --- a/packages/examples/src/point.dy.js +++ /dev/null @@ -1,24 +0,0 @@ -import freesewing from "freesewing"; - -var pointDy = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets, macro} = part.shorthand(); - - points.from = new Point(10, 10); - points.to = new Point(90, 40); - - macro("vd", { - from: points.to, - to: points.from, - x: 50 - }); - - snippets.notch1 = new Snippet("x", points.from); - snippets.notch2 = new Snippet("x", points.to); - - return part; - } -}; - -export default pointDy; diff --git a/packages/examples/src/point.flipx.js b/packages/examples/src/point.flipx.js deleted file mode 100644 index 41cd3b1ed89..00000000000 --- a/packages/examples/src/point.flipx.js +++ /dev/null @@ -1,55 +0,0 @@ -import freesewing from "freesewing"; - -var pointFlipX = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.top = new Point(50, 10); - points.out1 = new Point(70, 30); - points.in1 = new Point(55, 35); - points.out2 = new Point(75, 50); - points.in2 = new Point(60, 55); - points.out3 = new Point(80, 70); - points.in3 = new Point(55, 70); - points.trunkOut = new Point(55, 80); - points.trunkIn = new Point(50, 80); - - points._out1 = points.out1.flipX(points.top); - points._in1 = points.in1.flipX(points.top); - points._out2 = points.out2.flipX(points.top); - points._in2 = points.in2.flipX(points.top); - points._out3 = points.out3.flipX(points.top); - points._in3 = points.in3.flipX(points.top); - points._trunkOut = points.trunkOut.flipX(points.top); - - points.bottom = new Point(50, 80); - - paths.tree = new Path() - .move(points.top) - .line(points.out1) - .line(points.in1) - .line(points.out2) - .line(points.in2) - .line(points.out3) - .line(points.in3) - .line(points.trunkOut) - .line(points._trunkOut) - .line(points._in3) - .line(points._out3) - .line(points._in2) - .line(points._out2) - .line(points._in1) - .line(points._out1) - .close(); - - paths.mirror = new Path() - .move(points.top) - .line(points.bottom) - .attr("class", "note dashed"); - - return part; - } -}; - -export default pointFlipX; diff --git a/packages/examples/src/point.flipy.js b/packages/examples/src/point.flipy.js deleted file mode 100644 index 91224f62309..00000000000 --- a/packages/examples/src/point.flipy.js +++ /dev/null @@ -1,84 +0,0 @@ -import freesewing from "freesewing"; - -var pointFlipX = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.start = new Point(0, 50); - points.churchTowerWallLeft = new Point(10, 50); - points.churchTowerRoofLeft = new Point(10, 30); - points.churchTowerTop = new Point(15, 10); - points.churchTowerRoofRight = new Point(20, 30); - points.churchRoofRight = new Point(50, 30); - points.churchWallRight = new Point(50, 50); - points.houseWallLeft = new Point(65, 50); - points.houseRoofLeft = new Point(65, 35); - points.houseRoofTop = new Point(75, 25); - points.houseRoofRight = new Point(85, 35); - points.houseWallRight = new Point(85, 50); - points.end = new Point(95, 50); - - points.mirror = new Point(0, 60); - points.mirrorLineEnd = new Point(95, 60); - - points._start = points.start.flipY(points.mirror); - points._churchTowerWallLeft = points.churchTowerWallLeft.flipY( - points.mirror - ); - points._churchTowerRoofLeft = points.churchTowerRoofLeft.flipY( - points.mirror - ); - points._churchTowerTop = points.churchTowerTop.flipY(points.mirror); - points._churchTowerRoofRight = points.churchTowerRoofRight.flipY( - points.mirror - ); - points._churchRoofRight = points.churchRoofRight.flipY(points.mirror); - points._churchWallRight = points.churchWallRight.flipY(points.mirror); - points._houseWallLeft = points.houseWallLeft.flipY(points.mirror); - points._houseRoofLeft = points.houseRoofLeft.flipY(points.mirror); - points._houseRoofTop = points.houseRoofTop.flipY(points.mirror); - points._houseRoofRight = points.houseRoofRight.flipY(points.mirror); - points._houseWallRight = points.houseWallRight.flipY(points.mirror); - points._end = points.end.flipY(points.mirror); - - paths.skylineTop = new Path() - .move(points.start) - .line(points.churchTowerWallLeft) - .line(points.churchTowerRoofLeft) - .line(points.churchTowerTop) - .line(points.churchTowerRoofRight) - .line(points.churchRoofRight) - .line(points.churchWallRight) - .line(points.houseWallLeft) - .line(points.houseRoofLeft) - .line(points.houseRoofTop) - .line(points.houseRoofRight) - .line(points.houseWallRight) - .line(points.end); - - paths.skylineBottom = new Path() - .move(points._start) - .line(points._churchTowerWallLeft) - .line(points._churchTowerRoofLeft) - .line(points._churchTowerTop) - .line(points._churchTowerRoofRight) - .line(points._churchRoofRight) - .line(points._churchWallRight) - .line(points._houseWallLeft) - .line(points._houseRoofLeft) - .line(points._houseRoofTop) - .line(points._houseRoofRight) - .line(points._houseWallRight) - .line(points._end); - - paths.mirrorLine = new Path() - .move(points.mirror) - .line(points.mirrorLineEnd) - .attr("class", "note dashed"); - - return part; - } -}; - -export default pointFlipX; diff --git a/packages/examples/src/point.rotate.js b/packages/examples/src/point.rotate.js deleted file mode 100644 index d2da68a3ba4..00000000000 --- a/packages/examples/src/point.rotate.js +++ /dev/null @@ -1,24 +0,0 @@ -import freesewing from "freesewing"; - -var pointRotate = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets} = part.shorthand(); - - points.sun = new Point(40, 40); - snippets.sun = new Snippet("notch", points.sun); - points.moon = new Point(70, 40); - let angle = 0; - let step = 360 / 36; - for (let i = 1; i < 37; i++) { - let angle = step * i; - points[`moon${i}`] = points.moon.rotate(angle, points.sun); - paths[`moon${i}`] = new Path().move(points.sun).line(points[`moon${i}`]); - snippets[`moon${i}`] = new Snippet("x", points[`moon${i}`]); - } - - return part; - } -}; - -export default pointRotate; diff --git a/packages/examples/src/point.shift.js b/packages/examples/src/point.shift.js deleted file mode 100644 index 38193fabe4a..00000000000 --- a/packages/examples/src/point.shift.js +++ /dev/null @@ -1,31 +0,0 @@ -import freesewing from "freesewing"; - -var pointShift = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(90, 40) - .attr("data-text", "Point A") - .attr("data-text-class", "right"); - points.B = points.A.shift(155, 70) - .attr( - "data-text", - "Point B is point A shifted 7cm\nat a 155 degree angle" - ) - .attr("data-text-lineheight", 6); - - snippets.A = new Snippet("x", points.A); - snippets.B = new Snippet("x", points.B); - - macro("ld", { - from: points.B, - to: points.A, - d: -10 - }); - - return part; - } -}; - -export default pointShift; diff --git a/packages/examples/src/point.shiftfractiontowards.js b/packages/examples/src/point.shiftfractiontowards.js deleted file mode 100644 index e38c26f3e55..00000000000 --- a/packages/examples/src/point.shiftfractiontowards.js +++ /dev/null @@ -1,43 +0,0 @@ -import freesewing from "freesewing"; - -var pointShiftFractionTowards = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(90, 70).attr("data-text", "Point A"); - points.B = new Point(10, 10).attr("data-text", "Point B"); - points.C = points.A.shiftFractionTowards(points.B, 0.5) - .attr( - "data-text", - "Point C is point A shifted 50%\nin the direction of point B" - ) - .attr("data-text-class", "center") - .attr("data-text-lineheight", 6); - - snippets.A = new Snippet("x", points.A); - snippets.B = new Snippet("x", points.B); - snippets.C = new Snippet("x", points.C); - - paths.direction = new Path() - .move(points.A) - .line(points.B) - .attr("class", "note dashed"); - - macro("ld", { - from: points.C, - to: points.A, - d: -10 - }); - - macro("ld", { - from: points.B, - to: points.A, - d: 20 - }); - - return part; - } -}; - -export default pointShiftFractionTowards; diff --git a/packages/examples/src/point.shiftoutwards.js b/packages/examples/src/point.shiftoutwards.js deleted file mode 100644 index eb94d15cc89..00000000000 --- a/packages/examples/src/point.shiftoutwards.js +++ /dev/null @@ -1,33 +0,0 @@ -import freesewing from "freesewing"; - -var pointShiftOutwards = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(90, 70).attr("data-text", "Point A"); - points.B = new Point(10, 10).attr("data-text", "Point B"); - points.C = points.A.shiftOutwards(points.B, 30) - .attr("data-text", "Point C is point A shifted 3cm\nbeyond point B") - .attr("data-text-lineheight", 6); - - snippets.A = new Snippet("x", points.A); - snippets.B = new Snippet("x", points.B); - snippets.C = new Snippet("x", points.C); - - paths.direction = new Path() - .move(points.A) - .line(points.C) - .attr("class", "note dashed"); - - macro("ld", { - from: points.C, - to: points.B, - d: -10 - }); - - return part; - } -}; - -export default pointShiftOutwards; diff --git a/packages/examples/src/point.shifttowards.js b/packages/examples/src/point.shifttowards.js deleted file mode 100644 index 23d032dc7fb..00000000000 --- a/packages/examples/src/point.shifttowards.js +++ /dev/null @@ -1,37 +0,0 @@ -import freesewing from "freesewing"; - -var pointShiftTowards = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(90, 70).attr("data-text", "Point A"); - points.B = new Point(10, 10).attr("data-text", "Point B"); - points.C = points.A.shiftTowards(points.B, 35) - .attr( - "data-text", - "Point C is point A shifted 3.5cm\nin the direction of point B" - ) - .attr("data-text-class", "center") - .attr("data-text-lineheight", 6); - - snippets.A = new Snippet("x", points.A); - snippets.B = new Snippet("x", points.B); - snippets.C = new Snippet("x", points.C); - - paths.direction = new Path() - .move(points.A) - .line(points.B) - .attr("class", "note dashed"); - - macro("ld", { - from: points.C, - to: points.A, - d: -10 - }); - - return part; - } -}; - -export default pointShiftTowards; diff --git a/packages/examples/src/point.sitson.js b/packages/examples/src/point.sitson.js deleted file mode 100644 index 4a16ca62d5f..00000000000 --- a/packages/examples/src/point.sitson.js +++ /dev/null @@ -1,25 +0,0 @@ -import freesewing from "freesewing"; -import { box } from "./shared"; - -var pointDx = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets, macro} = part.shorthand(); - - box(part); - - let s; - for (let i = 0; i < 10; i++) { - points[`a${i}`] = new Point(i * 10, 40); - points[`b${i}`] = new Point(i * 10, i * 8); - if (points[`a${i}`].sitsOn(points[`b${i}`])) s = "notch"; - else s = "x"; - snippets[`b${i}`] = new Snippet(s, points[`b${i}`]); - snippets[`a${i}`] = new Snippet(s, points[`a${i}`]); - } - - return part; - } -}; - -export default pointDx; diff --git a/packages/examples/src/point.translate.js b/packages/examples/src/point.translate.js deleted file mode 100644 index 89845751df1..00000000000 --- a/packages/examples/src/point.translate.js +++ /dev/null @@ -1,30 +0,0 @@ -var pointTranslate = { - draft: function(part) { - // prettier-ignore - let {Point, points, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(10, 10).attr("data-text", "Point A"); - points.B = points.A.translate(120, 60) - .attr( - "data-text", - "Point B is point A with a\ntranslate(120, 60)\ntransform applied" - ) - .attr("data-text-class", "right") - .attr("data-text-dy", -6) - .attr("data-text-lineheight", 6); - - snippets.A = new Snippet("x", points.A); - snippets.B = new Snippet("x", points.B); - - macro("ld", { - from: points.A, - to: points.B, - text: "translate(120,60)", - noStartMarker: true - }); - - return part; - } -}; - -export default pointTranslate; diff --git a/packages/examples/src/point_angle.js b/packages/examples/src/point_angle.js new file mode 100644 index 00000000000..40852ecbe39 --- /dev/null +++ b/packages/examples/src/point_angle.js @@ -0,0 +1,51 @@ +export default part => { + let { Point, points, Path, paths, Snippet, snippets } = part.shorthand(); + + points.sun = new Point(40, 40); + points.moon1 = new Point(70, 40) + .attr("data-text", "0") + .attr("data-text-class", "text-xl"); + points.moon2 = new Point(40, 10) + .attr("data-text", 90) + .attr("data-text-class", "text-xl"); + points.moon3 = new Point(10, 40) + .attr("data-text", 180) + .attr("data-text-class", "text-xl"); + points.moon4 = new Point(40, 70) + .attr("data-text", 270) + .attr("data-text-class", "text-xl"); + points.moon5 = points.moon1.rotate(-45, points.sun); + points.moon5 + .attr("data-text", points.sun.angle(points.moon5)) + .attr("data-text-class", "text-xl"); + + paths.moon1 = new Path() + .move(points.sun) + .line(points.moon1) + .attr("class", "dashed note"); + paths.moon2 = new Path() + .move(points.sun) + .line(points.moon2) + .attr("class", "dashed note"); + paths.moon3 = new Path() + .move(points.sun) + .line(points.moon3) + .attr("class", "dashed note"); + paths.moon4 = new Path() + .move(points.sun) + .line(points.moon4) + .attr("class", "dashed note"); + paths.moon5 = new Path() + .move(points.sun) + .line(points.moon5) + .attr("class", "dashed note"); + + snippets.notch = new Snippet("notch", points.sun); + snippets.notch1 = new Snippet("x", points.moon1); + snippets.notch2 = new Snippet("x", points.moon2); + snippets.notch3 = new Snippet("x", points.moon3); + snippets.notch4 = new Snippet("x", points.moon4); + snippets.notch5 = new Snippet("x", points.moon5); + + return part; +}; diff --git a/packages/examples/src/point_attr.js b/packages/examples/src/point_attr.js new file mode 100644 index 00000000000..83efbc61ce8 --- /dev/null +++ b/packages/examples/src/point_attr.js @@ -0,0 +1,16 @@ +import { box } from "./shared"; + +export default part => { + let { Point, points, Snippet, snippets } = part.shorthand(); + + box(part); + + points.anchor = new Point(50, 25) + .attr("data-text", "Hello world!\nThis is\na line break.") + .attr("data-text-class", "text-xl center") + .attr("data-text-lineheight", 10); + + snippets.notch = new Snippet("x", points.anchor); + + return part; +}; diff --git a/packages/examples/src/point_clone.js b/packages/examples/src/point_clone.js new file mode 100644 index 00000000000..bf2a6acbb84 --- /dev/null +++ b/packages/examples/src/point_clone.js @@ -0,0 +1,17 @@ +import { box } from "./shared"; + +export default part => { + let { Point, points, Snippet, snippets } = part.shorthand(); + + box(part); + + points.A = new Point(25, 25) + .attr("data-text", "Point A") + .attr("data-text-class", "text-xl") + .attr("data-text-fill-opacity", "0.5"); + points.B = points.A.clone().attr("data-text", "Point B"); + + snippets.x = new Snippet("x", points.A); + + return part; +}; diff --git a/packages/examples/src/point_copy.js b/packages/examples/src/point_copy.js new file mode 100644 index 00000000000..1d9f2a51c3d --- /dev/null +++ b/packages/examples/src/point_copy.js @@ -0,0 +1,16 @@ +import { box } from "./shared"; + +export default part => { + let { Point, points, Snippet, snippets } = part.shorthand(); + + box(part); + + points.A = new Point(50, 25) + .attr("data-text", "Point A") + .attr("data-text-class", "text-xl"); + points.B = points.A.copy().attr("data-text", "Point B"); + + snippets.x = new Snippet("x", points.A); + + return part; +}; diff --git a/packages/examples/src/point_dist.js b/packages/examples/src/point_dist.js new file mode 100644 index 00000000000..cd56299c1e9 --- /dev/null +++ b/packages/examples/src/point_dist.js @@ -0,0 +1,16 @@ +export default part => { + let { Point, points, Snippet, snippets, macro } = part.shorthand(); + + points.from = new Point(10, 10); + points.to = new Point(90, 40); + + macro("ld", { + from: points.from, + to: points.to + }); + + snippets.notch1 = new Snippet("x", points.from); + snippets.notch2 = new Snippet("x", points.to); + + return part; +}; diff --git a/packages/examples/src/point_dx.js b/packages/examples/src/point_dx.js new file mode 100644 index 00000000000..79de92a5c68 --- /dev/null +++ b/packages/examples/src/point_dx.js @@ -0,0 +1,17 @@ +export default part => { + let { Point, points, Snippet, snippets, macro } = part.shorthand(); + + points.from = new Point(10, 10); + points.to = new Point(90, 40); + + macro("hd", { + from: points.from, + to: points.to, + y: 25 + }); + + snippets.notch1 = new Snippet("x", points.from); + snippets.notch2 = new Snippet("x", points.to); + + return part; +}; diff --git a/packages/examples/src/point_dy.js b/packages/examples/src/point_dy.js new file mode 100644 index 00000000000..2ae1292aa38 --- /dev/null +++ b/packages/examples/src/point_dy.js @@ -0,0 +1,17 @@ +export default part => { + let { Point, points, Snippet, snippets, macro } = part.shorthand(); + + points.from = new Point(10, 10); + points.to = new Point(90, 40); + + macro("vd", { + from: points.to, + to: points.from, + x: 50 + }); + + snippets.notch1 = new Snippet("x", points.from); + snippets.notch2 = new Snippet("x", points.to); + + return part; +}; diff --git a/packages/examples/src/point_flipx.js b/packages/examples/src/point_flipx.js new file mode 100644 index 00000000000..1f5521ba7f9 --- /dev/null +++ b/packages/examples/src/point_flipx.js @@ -0,0 +1,56 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.top = new Point(50, 10); + points.out1 = new Point(70, 30); + points.in1 = new Point(55, 35); + points.out2 = new Point(75, 50); + points.in2 = new Point(60, 55); + points.out3 = new Point(80, 70); + points.in3 = new Point(55, 70); + points.trunkOut = new Point(55, 80); + points.trunkIn = new Point(50, 80); + + points._out1 = points.out1.flipX(points.top); + points._in1 = points.in1.flipX(points.top); + points._out2 = points.out2.flipX(points.top); + points._in2 = points.in2.flipX(points.top); + points._out3 = points.out3.flipX(points.top); + points._in3 = points.in3.flipX(points.top); + points._trunkOut = points.trunkOut.flipX(points.top); + + points.bottom = new Point(50, 80); + + paths.tree = new Path() + .move(points.top) + .line(points.out1) + .line(points.in1) + .line(points.out2) + .line(points.in2) + .line(points.out3) + .line(points.in3) + .line(points.trunkOut) + .line(points._trunkOut) + .line(points._in3) + .line(points._out3) + .line(points._in2) + .line(points._out2) + .line(points._in1) + .line(points._out1) + .close(); + + paths.mirror = new Path() + .move(points.top) + .line(points.bottom) + .attr("class", "note dashed"); + + return part; +}; diff --git a/packages/examples/src/point_flipy.js b/packages/examples/src/point_flipy.js new file mode 100644 index 00000000000..69b33a3d3a9 --- /dev/null +++ b/packages/examples/src/point_flipy.js @@ -0,0 +1,81 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.start = new Point(0, 50); + points.churchTowerWallLeft = new Point(10, 50); + points.churchTowerRoofLeft = new Point(10, 30); + points.churchTowerTop = new Point(15, 10); + points.churchTowerRoofRight = new Point(20, 30); + points.churchRoofRight = new Point(50, 30); + points.churchWallRight = new Point(50, 50); + points.houseWallLeft = new Point(65, 50); + points.houseRoofLeft = new Point(65, 35); + points.houseRoofTop = new Point(75, 25); + points.houseRoofRight = new Point(85, 35); + points.houseWallRight = new Point(85, 50); + points.end = new Point(95, 50); + + points.mirror = new Point(0, 60); + points.mirrorLineEnd = new Point(95, 60); + + points._start = points.start.flipY(points.mirror); + points._churchTowerWallLeft = points.churchTowerWallLeft.flipY(points.mirror); + points._churchTowerRoofLeft = points.churchTowerRoofLeft.flipY(points.mirror); + points._churchTowerTop = points.churchTowerTop.flipY(points.mirror); + points._churchTowerRoofRight = points.churchTowerRoofRight.flipY( + points.mirror + ); + points._churchRoofRight = points.churchRoofRight.flipY(points.mirror); + points._churchWallRight = points.churchWallRight.flipY(points.mirror); + points._houseWallLeft = points.houseWallLeft.flipY(points.mirror); + points._houseRoofLeft = points.houseRoofLeft.flipY(points.mirror); + points._houseRoofTop = points.houseRoofTop.flipY(points.mirror); + points._houseRoofRight = points.houseRoofRight.flipY(points.mirror); + points._houseWallRight = points.houseWallRight.flipY(points.mirror); + points._end = points.end.flipY(points.mirror); + + paths.skylineTop = new Path() + .move(points.start) + .line(points.churchTowerWallLeft) + .line(points.churchTowerRoofLeft) + .line(points.churchTowerTop) + .line(points.churchTowerRoofRight) + .line(points.churchRoofRight) + .line(points.churchWallRight) + .line(points.houseWallLeft) + .line(points.houseRoofLeft) + .line(points.houseRoofTop) + .line(points.houseRoofRight) + .line(points.houseWallRight) + .line(points.end); + + paths.skylineBottom = new Path() + .move(points._start) + .line(points._churchTowerWallLeft) + .line(points._churchTowerRoofLeft) + .line(points._churchTowerTop) + .line(points._churchTowerRoofRight) + .line(points._churchRoofRight) + .line(points._churchWallRight) + .line(points._houseWallLeft) + .line(points._houseRoofLeft) + .line(points._houseRoofTop) + .line(points._houseRoofRight) + .line(points._houseWallRight) + .line(points._end); + + paths.mirrorLine = new Path() + .move(points.mirror) + .line(points.mirrorLineEnd) + .attr("class", "note dashed"); + + return part; +}; diff --git a/packages/examples/src/point_rotate.js b/packages/examples/src/point_rotate.js new file mode 100644 index 00000000000..0eb917209ad --- /dev/null +++ b/packages/examples/src/point_rotate.js @@ -0,0 +1,17 @@ +export default part => { + let { Point, points, Path, paths, Snippet, snippets } = part.shorthand(); + + points.sun = new Point(40, 40); + snippets.sun = new Snippet("notch", points.sun); + points.moon = new Point(70, 40); + let angle = 0; + let step = 360 / 36; + for (let i = 1; i < 37; i++) { + let angle = step * i; + points[`moon${i}`] = points.moon.rotate(angle, points.sun); + paths[`moon${i}`] = new Path().move(points.sun).line(points[`moon${i}`]); + snippets[`moon${i}`] = new Snippet("x", points[`moon${i}`]); + } + + return part; +}; diff --git a/packages/examples/src/point_shift.js b/packages/examples/src/point_shift.js new file mode 100644 index 00000000000..b70a53eabf5 --- /dev/null +++ b/packages/examples/src/point_shift.js @@ -0,0 +1,21 @@ +export default part => { + let { Point, points, Snippet, snippets, macro } = part.shorthand(); + + points.A = new Point(90, 40) + .attr("data-text", "Point A") + .attr("data-text-class", "right"); + points.B = points.A.shift(155, 70) + .attr("data-text", "Point B is point A shifted 7cm\nat a 155 degree angle") + .attr("data-text-lineheight", 6); + + snippets.A = new Snippet("x", points.A); + snippets.B = new Snippet("x", points.B); + + macro("ld", { + from: points.B, + to: points.A, + d: -10 + }); + + return part; +}; diff --git a/packages/examples/src/point_shiftfractiontowards.js b/packages/examples/src/point_shiftfractiontowards.js new file mode 100644 index 00000000000..489a1647486 --- /dev/null +++ b/packages/examples/src/point_shiftfractiontowards.js @@ -0,0 +1,44 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(90, 70).attr("data-text", "Point A"); + points.B = new Point(10, 10).attr("data-text", "Point B"); + points.C = points.A.shiftFractionTowards(points.B, 0.5) + .attr( + "data-text", + "Point C is point A shifted 50%\nin the direction of point B" + ) + .attr("data-text-class", "center") + .attr("data-text-lineheight", 6); + + snippets.A = new Snippet("x", points.A); + snippets.B = new Snippet("x", points.B); + snippets.C = new Snippet("x", points.C); + + paths.direction = new Path() + .move(points.A) + .line(points.B) + .attr("class", "note dashed"); + + macro("ld", { + from: points.C, + to: points.A, + d: -10 + }); + + macro("ld", { + from: points.B, + to: points.A, + d: 20 + }); + + return part; +}; diff --git a/packages/examples/src/point_shiftoutwards.js b/packages/examples/src/point_shiftoutwards.js new file mode 100644 index 00000000000..a53bb8d21d9 --- /dev/null +++ b/packages/examples/src/point_shiftoutwards.js @@ -0,0 +1,34 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(90, 70).attr("data-text", "Point A"); + points.B = new Point(10, 10).attr("data-text", "Point B"); + points.C = points.A.shiftOutwards(points.B, 30) + .attr("data-text", "Point C is point A shifted 3cm\nbeyond point B") + .attr("data-text-lineheight", 6); + + snippets.A = new Snippet("x", points.A); + snippets.B = new Snippet("x", points.B); + snippets.C = new Snippet("x", points.C); + + paths.direction = new Path() + .move(points.A) + .line(points.C) + .attr("class", "note dashed"); + + macro("ld", { + from: points.C, + to: points.B, + d: -10 + }); + + return part; +}; diff --git a/packages/examples/src/point_shifttowards.js b/packages/examples/src/point_shifttowards.js new file mode 100644 index 00000000000..2b0f780ce50 --- /dev/null +++ b/packages/examples/src/point_shifttowards.js @@ -0,0 +1,38 @@ +export default part => { + let { + Point, + points, + Path, + paths, + Snippet, + snippets, + macro + } = part.shorthand(); + + points.A = new Point(90, 70).attr("data-text", "Point A"); + points.B = new Point(10, 10).attr("data-text", "Point B"); + points.C = points.A.shiftTowards(points.B, 35) + .attr( + "data-text", + "Point C is point A shifted 3.5cm\nin the direction of point B" + ) + .attr("data-text-class", "center") + .attr("data-text-lineheight", 6); + + snippets.A = new Snippet("x", points.A); + snippets.B = new Snippet("x", points.B); + snippets.C = new Snippet("x", points.C); + + paths.direction = new Path() + .move(points.A) + .line(points.B) + .attr("class", "note dashed"); + + macro("ld", { + from: points.C, + to: points.A, + d: -10 + }); + + return part; +}; diff --git a/packages/examples/src/point_sitson.js b/packages/examples/src/point_sitson.js new file mode 100644 index 00000000000..04346a1e30f --- /dev/null +++ b/packages/examples/src/point_sitson.js @@ -0,0 +1,20 @@ +import { box } from "./shared"; + +export default part => { + // prettier-ignore + let {Point, points, Snippet, snippets, macro} = part.shorthand(); + + box(part); + + let s; + for (let i = 0; i < 10; i++) { + points[`a${i}`] = new Point(i * 10, 40); + points[`b${i}`] = new Point(i * 10, i * 8); + if (points[`a${i}`].sitsOn(points[`b${i}`])) s = "notch"; + else s = "x"; + snippets[`b${i}`] = new Snippet(s, points[`b${i}`]); + snippets[`a${i}`] = new Snippet(s, points[`a${i}`]); + } + + return part; +}; diff --git a/packages/examples/src/point_translate.js b/packages/examples/src/point_translate.js new file mode 100644 index 00000000000..97ad94f9348 --- /dev/null +++ b/packages/examples/src/point_translate.js @@ -0,0 +1,25 @@ +export default part => { + let { Point, points, Snippet, snippets, macro } = part.shorthand(); + + points.A = new Point(10, 10).attr("data-text", "Point A"); + points.B = points.A.translate(120, 60) + .attr( + "data-text", + "Point B is point A with a\ntranslate(120, 60)\ntransform applied" + ) + .attr("data-text-class", "right") + .attr("data-text-dy", -6) + .attr("data-text-lineheight", 6); + + snippets.A = new Snippet("x", points.A); + snippets.B = new Snippet("x", points.B); + + macro("ld", { + from: points.A, + to: points.B, + text: "translate(120,60)", + noStartMarker: true + }); + + return part; +}; diff --git a/packages/examples/src/settings.sa.js b/packages/examples/src/settings.sa.js deleted file mode 100644 index e2e5195f884..00000000000 --- a/packages/examples/src/settings.sa.js +++ /dev/null @@ -1,28 +0,0 @@ -import freesewing from "freesewing"; - -var pathOffset = { - draft: function(part) { - // prettier-ignore - let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); - - points.A = new Point(45, 60); - points.B = new Point(10, 30); - points.BCp2 = new Point(40, 20); - points.C = new Point(90, 30); - points.CCp1 = new Point(50, -30); - - paths.example = new Path() - .move(points.A) - .line(points.B) - .curve(points.BCp2, points.CCp1, points.C) - .line(points.A) - .close() - .attr("class", "fabric"); - - paths.offset = paths.example.offset(-10).attr("class", "fabric sa"); - - return part; - } -}; - -export default pathOffset; diff --git a/packages/examples/src/settings_sa.js b/packages/examples/src/settings_sa.js new file mode 100644 index 00000000000..dff37100c68 --- /dev/null +++ b/packages/examples/src/settings_sa.js @@ -0,0 +1,22 @@ +export default part => { + // prettier-ignore + let {Point, points, Path, paths, Snippet, snippets, macro} = part.shorthand(); + + points.A = new Point(45, 60); + points.B = new Point(10, 30); + points.BCp2 = new Point(40, 20); + points.C = new Point(90, 30); + points.CCp1 = new Point(50, -30); + + paths.example = new Path() + .move(points.A) + .line(points.B) + .curve(points.BCp2, points.CCp1, points.C) + .line(points.A) + .close() + .attr("class", "fabric"); + + paths.offset = paths.example.offset(-10).attr("class", "fabric sa"); + + return part; +}; diff --git a/packages/examples/src/utils.beamintersectscircle.js b/packages/examples/src/utils.beamintersectscircle.js deleted file mode 100644 index c214411800d..00000000000 --- a/packages/examples/src/utils.beamintersectscircle.js +++ /dev/null @@ -1,53 +0,0 @@ -import freesewing from "freesewing"; - -var utilsBeamIntersectsCircle = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(45, 45) - .attr("data-circle", 35) - .attr("data-circle-class", "fabric"); - points.B = new Point(5, 50); - points.C = new Point(25, 30); - points.D = new Point(5, 65); - points.E = new Point(65, 5); - points.F = new Point(15, 75); - points.G = new Point(75, 15); - - paths.line1 = new Path().move(points.B).line(points.C); - paths.line2 = new Path().move(points.D).line(points.E); - paths.line3 = new Path().move(points.F).line(points.G); - - let intersections1 = utils.beamIntersectsCircle( - points.A, - points.A.attributes.get("data-circle"), - points.B, - points.C - ); - let intersections2 = utils.beamIntersectsCircle( - points.A, - points.A.attributes.get("data-circle"), - points.D, - points.E, - "y" - ); - let intersections3 = utils.beamIntersectsCircle( - points.A, - points.A.attributes.get("data-circle"), - points.F, - points.G - ); - - snippets.first1 = new Snippet("bnotch", intersections1[0]); - snippets.second1 = new Snippet("x", intersections1[1]); - snippets.first2 = new Snippet("bnotch", intersections2[0]); - snippets.second2 = new Snippet("x", intersections2[1]); - snippets.first3 = new Snippet("bnotch", intersections3[0]); - snippets.second3 = new Snippet("x", intersections3[1]); - - return part; - } -}; - -export default utilsBeamIntersectsCircle; diff --git a/packages/examples/src/utils.beamintersectsx.js b/packages/examples/src/utils.beamintersectsx.js deleted file mode 100644 index 7e63b56c65d..00000000000 --- a/packages/examples/src/utils.beamintersectsx.js +++ /dev/null @@ -1,27 +0,0 @@ -import freesewing from "freesewing"; - -var utilsBeamIntersectsX = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(10, 10); - points.B = new Point(50, 40); - - paths.AB = new Path().move(points.A).line(points.B); - - snippets.X = new Snippet( - "x", - utils.beamIntersectsX(points.A, points.B, 40) - ); - - paths.help = new Path() - .move(new Point(40, 0)) - .line(new Point(40, 50)) - .attr("class", "note dashed"); - - return part; - } -}; - -export default utilsBeamIntersectsX; diff --git a/packages/examples/src/utils.beamintersectsy.js b/packages/examples/src/utils.beamintersectsy.js deleted file mode 100644 index 9583ae8199e..00000000000 --- a/packages/examples/src/utils.beamintersectsy.js +++ /dev/null @@ -1,27 +0,0 @@ -import freesewing from "freesewing"; - -var utilsBeamIntersectsY = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(10, 10); - points.B = new Point(50, 40); - - paths.AB = new Path().move(points.A).line(points.B); - - snippets.X = new Snippet( - "x", - utils.beamIntersectsY(points.A, points.B, 30) - ); - - paths.help = new Path() - .move(new Point(0, 30)) - .line(new Point(50, 30)) - .attr("class", "note dashed"); - - return part; - } -}; - -export default utilsBeamIntersectsY; diff --git a/packages/examples/src/utils.beamsintersect.js b/packages/examples/src/utils.beamsintersect.js deleted file mode 100644 index 71fe85243ad..00000000000 --- a/packages/examples/src/utils.beamsintersect.js +++ /dev/null @@ -1,25 +0,0 @@ -import freesewing from "freesewing"; - -var utilsBeamsIntersect = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(10, 10); - points.B = new Point(50, 40); - points.C = new Point(45, 20); - points.D = new Point(60, 15); - - paths.AB = new Path().move(points.A).line(points.B); - paths.CD = new Path().move(points.C).line(points.D); - - snippets.X = new Snippet( - "x", - utils.beamsIntersect(points.A, points.B, points.C, points.D) - ); - - return part; - } -}; - -export default utilsBeamsIntersect; diff --git a/packages/examples/src/utils.circlesintersect.js b/packages/examples/src/utils.circlesintersect.js deleted file mode 100644 index 765dbc4d12d..00000000000 --- a/packages/examples/src/utils.circlesintersect.js +++ /dev/null @@ -1,44 +0,0 @@ -import freesewing from "freesewing"; - -var utilsCirclesIntersect = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(10, 10) - .attr("data-circle", 15) - .attr("data-circle-class", "fabric"); - points.B = new Point(30, 30) - .attr("data-circle", 35) - .attr("data-circle-class", "fabric"); - points.C = new Point(90, 10) - .attr("data-circle", 15) - .attr("data-circle-class", "various"); - points.D = new Point(110, 30) - .attr("data-circle", 35) - .attr("data-circle-class", "various"); - - let intersections1 = utils.circlesIntersect( - points.A, - points.A.attributes.get("data-circle"), - points.B, - points.B.attributes.get("data-circle") - ); - let intersections2 = utils.circlesIntersect( - points.C, - points.C.attributes.get("data-circle"), - points.D, - points.D.attributes.get("data-circle"), - "y" - ); - - snippets.first1 = new Snippet("bnotch", intersections1[0]); - snippets.second1 = new Snippet("x", intersections1[1]); - snippets.first2 = new Snippet("bnotch", intersections2[0]); - snippets.second2 = new Snippet("x", intersections2[1]); - - return part; - } -}; - -export default utilsCirclesIntersect; diff --git a/packages/examples/src/utils.curvesintersect.js b/packages/examples/src/utils.curvesintersect.js deleted file mode 100644 index f4f43984202..00000000000 --- a/packages/examples/src/utils.curvesintersect.js +++ /dev/null @@ -1,40 +0,0 @@ -import freesewing from "freesewing"; - -var utilsCurvesIntersect = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(10, 10); - points.Acp = new Point(310, 40); - points.B = new Point(110, 70); - points.Bcp = new Point(-210, 40); - - points.C = new Point(20, -5); - points.Ccp = new Point(60, 300); - points.D = new Point(100, 85); - points.Dcp = new Point(70, -220); - paths.curveA = new Path() - .move(points.A) - .curve(points.Acp, points.Bcp, points.B); - paths.curveB = new Path() - .move(points.C) - .curve(points.Ccp, points.Dcp, points.D); - - for (let p of utils.curvesIntersect( - points.A, - points.Acp, - points.Bcp, - points.B, - points.C, - points.Ccp, - points.Dcp, - points.D - )) - snippets[part.getId()] = new Snippet("x", p); - - return part; - } -}; - -export default utilsCurvesIntersect; diff --git a/packages/examples/src/utils.lineintersectscircle.js b/packages/examples/src/utils.lineintersectscircle.js deleted file mode 100644 index b885c04b5fc..00000000000 --- a/packages/examples/src/utils.lineintersectscircle.js +++ /dev/null @@ -1,52 +0,0 @@ -import freesewing from "freesewing"; - -var utilsLineIntersectsCircle = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(45, 45) - .attr("data-circle", 35) - .attr("data-circle-class", "fabric"); - points.B = new Point(5, 50); - points.C = new Point(25, 30); - - points.D = new Point(5, 65); - points.E = new Point(65, 5); - points.F = new Point(15, 75); - points.G = new Point(75, 15); - - paths.line1 = new Path().move(points.B).line(points.C); - paths.line2 = new Path().move(points.D).line(points.E); - paths.line3 = new Path().move(points.F).line(points.G); - - let intersections1 = utils.lineIntersectsCircle( - points.A, - points.A.attributes.get("data-circle"), - points.B, - points.C - ); - let intersections2 = utils.lineIntersectsCircle( - points.A, - points.A.attributes.get("data-circle"), - points.D, - points.E, - "y" - ); - let intersections3 = utils.lineIntersectsCircle( - points.A, - points.A.attributes.get("data-circle"), - points.F, - points.G - ); - snippets.first1 = new Snippet("bnotch", intersections1[0]); - snippets.first2 = new Snippet("bnotch", intersections2[0]); - snippets.second2 = new Snippet("x", intersections2[1]); - snippets.first3 = new Snippet("bnotch", intersections3[0]); - snippets.second3 = new Snippet("x", intersections3[1]); - - return part; - } -}; - -export default utilsLineIntersectsCircle; diff --git a/packages/examples/src/utils.lineintersectscurve.js b/packages/examples/src/utils.lineintersectscurve.js deleted file mode 100644 index dde63490bfb..00000000000 --- a/packages/examples/src/utils.lineintersectscurve.js +++ /dev/null @@ -1,33 +0,0 @@ -import freesewing from "freesewing"; - -var utilsLineIntersectsCurve = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(10, 10); - points.Acp = new Point(310, 40); - points.B = new Point(110, 70); - points.Bcp = new Point(-210, 40); - points.E = new Point(20, -5); - points.D = new Point(100, 85); - paths.curve = new Path() - .move(points.A) - .curve(points.Acp, points.Bcp, points.B); - paths.line = new Path().move(points.E).line(points.D); - - for (let p of freesewing.utils.lineIntersectsCurve( - points.D, - points.E, - points.A, - points.Acp, - points.Bcp, - points.B - )) - snippets[part.getId()] = new Snippet("x", p); - - return part; - } -}; - -export default utilsLineIntersectsCurve; diff --git a/packages/examples/src/utils.linesintersect.js b/packages/examples/src/utils.linesintersect.js deleted file mode 100644 index dcf7f21aa10..00000000000 --- a/packages/examples/src/utils.linesintersect.js +++ /dev/null @@ -1,25 +0,0 @@ -import freesewing from "freesewing"; - -var utilsLinesIntersect = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.A = new Point(10, 10); - points.B = new Point(50, 40); - points.C = new Point(15, 30); - points.D = new Point(60, 15); - - paths.AB = new Path().move(points.A).line(points.B); - paths.CD = new Path().move(points.C).line(points.D); - - snippets.X = new Snippet( - "x", - utils.linesIntersect(points.A, points.B, points.C, points.D) - ); - - return part; - } -}; - -export default utilsLinesIntersect; diff --git a/packages/examples/src/utils.pointonbeam.js b/packages/examples/src/utils.pointonbeam.js deleted file mode 100644 index 3ebca476baf..00000000000 --- a/packages/examples/src/utils.pointonbeam.js +++ /dev/null @@ -1,52 +0,0 @@ -import freesewing from "freesewing"; - -var utilsPointOnBeam = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - 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); - - let scatter = []; - for (let i = 1; i < 36; i++) { - for (let j = 1; j < 27; j++) { - scatter.push(new Point(i * 5, j * 5)); - } - } - let snippet; - for (let point of scatter) { - if (utils.pointOnBeam(points.from1, points.to1, point)) snippet = "notch"; - else snippet = "x"; - snippets[part.getId()] = new Snippet(snippet, point); - if (utils.pointOnBeam(points.from2, points.to2, point, 0.01)) - snippet = "notch"; - else snippet = "x"; - snippets[part.getId()] = new Snippet(snippet, point); - } - paths.line1 = new Path() - .move(points.from1) - .line(points.to1) - .attr("class", "fabric stroke-lg"); - paths.lne1 = new Path() - .move(points.to1) - .line(points.b1) - .attr("class", "fabric dashed"); - paths.line2 = new Path() - .move(points.from2) - .line(points.to2) - .attr("class", "fabric stroke-lg"); - paths.lne2 = new Path() - .move(points.to2) - .line(points.b2) - .attr("class", "fabric dashed"); - - return part; - } -}; - -export default utilsPointOnBeam; diff --git a/packages/examples/src/utils.pointoncurve.js b/packages/examples/src/utils.pointoncurve.js deleted file mode 100644 index d392135f5b7..00000000000 --- a/packages/examples/src/utils.pointoncurve.js +++ /dev/null @@ -1,43 +0,0 @@ -import freesewing from "freesewing"; - -var utilsPointOnCurve = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - points.start = new Point(10, 10); - points.cp1 = new Point(90, 10); - points.cp2 = new Point(10, 60); - points.end = new Point(90, 60); - - let scatter = []; - for (let i = 1; i < 19; i++) { - for (let j = 1; j < 14; j++) { - scatter.push(new Point(i * 5, j * 5)); - } - } - let snippet; - for (let point of scatter) { - if ( - utils.pointOnCurve( - points.start, - points.cp1, - points.cp2, - points.end, - point - ) - ) - snippet = "notch"; - else snippet = "x"; - snippets[part.getId()] = new Snippet(snippet, point); - } - paths.curve = new Path() - .move(points.start) - .curve(points.cp1, points.cp2, points.end) - .attr("class", "fabric stroke-lg"); - - return part; - } -}; - -export default utilsPointOnCurve; diff --git a/packages/examples/src/utils.pointonline.js b/packages/examples/src/utils.pointonline.js deleted file mode 100644 index b6bc482d399..00000000000 --- a/packages/examples/src/utils.pointonline.js +++ /dev/null @@ -1,52 +0,0 @@ -import freesewing from "freesewing"; - -var utilsPointOnLine = { - draft: function(part) { - // prettier-ignore - let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); - - 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); - - let scatter = []; - for (let i = 1; i < 36; i++) { - for (let j = 1; j < 27; j++) { - scatter.push(new Point(i * 5, j * 5)); - } - } - let snippet; - for (let point of scatter) { - if (utils.pointOnLine(points.from1, points.to1, point)) snippet = "notch"; - else snippet = "x"; - snippets[part.getId()] = new Snippet(snippet, point); - if (utils.pointOnLine(points.from2, points.to2, point, 0.01)) - snippet = "notch"; - else snippet = "x"; - snippets[part.getId()] = new Snippet(snippet, point); - } - paths.line1 = new Path() - .move(points.from1) - .line(points.to1) - .attr("class", "fabric stroke-lg"); - paths.lne1 = new Path() - .move(points.to1) - .line(points.b1) - .attr("class", "fabric dashed"); - paths.line2 = new Path() - .move(points.from2) - .line(points.to2) - .attr("class", "fabric stroke-lg"); - paths.lne2 = new Path() - .move(points.to2) - .line(points.b2) - .attr("class", "fabric dashed"); - - return part; - } -}; - -export default utilsPointOnLine; diff --git a/packages/examples/src/utils_beamintersectscircle.js b/packages/examples/src/utils_beamintersectscircle.js new file mode 100644 index 00000000000..9ce118bd856 --- /dev/null +++ b/packages/examples/src/utils_beamintersectscircle.js @@ -0,0 +1,55 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(45, 45) + .attr("data-circle", 35) + .attr("data-circle-class", "fabric"); + points.B = new Point(5, 50); + points.C = new Point(25, 30); + points.D = new Point(5, 65); + points.E = new Point(65, 5); + points.F = new Point(15, 75); + points.G = new Point(75, 15); + + paths.line1 = new Path().move(points.B).line(points.C); + paths.line2 = new Path().move(points.D).line(points.E); + paths.line3 = new Path().move(points.F).line(points.G); + + let intersections1 = utils.beamIntersectsCircle( + points.A, + points.A.attributes.get("data-circle"), + points.B, + points.C + ); + let intersections2 = utils.beamIntersectsCircle( + points.A, + points.A.attributes.get("data-circle"), + points.D, + points.E, + "y" + ); + let intersections3 = utils.beamIntersectsCircle( + points.A, + points.A.attributes.get("data-circle"), + points.F, + points.G + ); + + snippets.first1 = new Snippet("bnotch", intersections1[0]); + snippets.second1 = new Snippet("x", intersections1[1]); + snippets.first2 = new Snippet("bnotch", intersections2[0]); + snippets.second2 = new Snippet("x", intersections2[1]); + snippets.first3 = new Snippet("bnotch", intersections3[0]); + snippets.second3 = new Snippet("x", intersections3[1]); + + return part; +}; diff --git a/packages/examples/src/utils_beamintersectsx.js b/packages/examples/src/utils_beamintersectsx.js new file mode 100644 index 00000000000..72be267a0ba --- /dev/null +++ b/packages/examples/src/utils_beamintersectsx.js @@ -0,0 +1,26 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(10, 10); + points.B = new Point(50, 40); + + paths.AB = new Path().move(points.A).line(points.B); + + snippets.X = new Snippet("x", utils.beamIntersectsX(points.A, points.B, 40)); + + paths.help = new Path() + .move(new Point(40, 0)) + .line(new Point(40, 50)) + .attr("class", "note dashed"); + + return part; +}; diff --git a/packages/examples/src/utils_beamintersectsy.js b/packages/examples/src/utils_beamintersectsy.js new file mode 100644 index 00000000000..c14db4c6cc5 --- /dev/null +++ b/packages/examples/src/utils_beamintersectsy.js @@ -0,0 +1,26 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(10, 10); + points.B = new Point(50, 40); + + paths.AB = new Path().move(points.A).line(points.B); + + snippets.X = new Snippet("x", utils.beamIntersectsY(points.A, points.B, 30)); + + paths.help = new Path() + .move(new Point(0, 30)) + .line(new Point(50, 30)) + .attr("class", "note dashed"); + + return part; +}; diff --git a/packages/examples/src/utils_beamsintersect.js b/packages/examples/src/utils_beamsintersect.js new file mode 100644 index 00000000000..26b30493f66 --- /dev/null +++ b/packages/examples/src/utils_beamsintersect.js @@ -0,0 +1,27 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(10, 10); + points.B = new Point(50, 40); + points.C = new Point(45, 20); + points.D = new Point(60, 15); + + paths.AB = new Path().move(points.A).line(points.B); + paths.CD = new Path().move(points.C).line(points.D); + + snippets.X = new Snippet( + "x", + utils.beamsIntersect(points.A, points.B, points.C, points.D) + ); + + return part; +}; diff --git a/packages/examples/src/utils_circlesintersect.js b/packages/examples/src/utils_circlesintersect.js new file mode 100644 index 00000000000..a5d05e2373e --- /dev/null +++ b/packages/examples/src/utils_circlesintersect.js @@ -0,0 +1,46 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(10, 10) + .attr("data-circle", 15) + .attr("data-circle-class", "fabric"); + points.B = new Point(30, 30) + .attr("data-circle", 35) + .attr("data-circle-class", "fabric"); + points.C = new Point(90, 10) + .attr("data-circle", 15) + .attr("data-circle-class", "various"); + points.D = new Point(110, 30) + .attr("data-circle", 35) + .attr("data-circle-class", "various"); + + let intersections1 = utils.circlesIntersect( + points.A, + points.A.attributes.get("data-circle"), + points.B, + points.B.attributes.get("data-circle") + ); + let intersections2 = utils.circlesIntersect( + points.C, + points.C.attributes.get("data-circle"), + points.D, + points.D.attributes.get("data-circle"), + "y" + ); + + snippets.first1 = new Snippet("bnotch", intersections1[0]); + snippets.second1 = new Snippet("x", intersections1[1]); + snippets.first2 = new Snippet("bnotch", intersections2[0]); + snippets.second2 = new Snippet("x", intersections2[1]); + + return part; +}; diff --git a/packages/examples/src/utils_curvesintersect.js b/packages/examples/src/utils_curvesintersect.js new file mode 100644 index 00000000000..29f588a947c --- /dev/null +++ b/packages/examples/src/utils_curvesintersect.js @@ -0,0 +1,42 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(10, 10); + points.Acp = new Point(310, 40); + points.B = new Point(110, 70); + points.Bcp = new Point(-210, 40); + + points.C = new Point(20, -5); + points.Ccp = new Point(60, 300); + points.D = new Point(100, 85); + points.Dcp = new Point(70, -220); + paths.curveA = new Path() + .move(points.A) + .curve(points.Acp, points.Bcp, points.B); + paths.curveB = new Path() + .move(points.C) + .curve(points.Ccp, points.Dcp, points.D); + + for (let p of utils.curvesIntersect( + points.A, + points.Acp, + points.Bcp, + points.B, + points.C, + points.Ccp, + points.Dcp, + points.D + )) + snippets[part.getId()] = new Snippet("x", p); + + return part; +}; diff --git a/packages/examples/src/utils_lineintersectscircle.js b/packages/examples/src/utils_lineintersectscircle.js new file mode 100644 index 00000000000..c6006d0a829 --- /dev/null +++ b/packages/examples/src/utils_lineintersectscircle.js @@ -0,0 +1,54 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(45, 45) + .attr("data-circle", 35) + .attr("data-circle-class", "fabric"); + points.B = new Point(5, 50); + points.C = new Point(25, 30); + + points.D = new Point(5, 65); + points.E = new Point(65, 5); + points.F = new Point(15, 75); + points.G = new Point(75, 15); + + paths.line1 = new Path().move(points.B).line(points.C); + paths.line2 = new Path().move(points.D).line(points.E); + paths.line3 = new Path().move(points.F).line(points.G); + + let intersections1 = utils.lineIntersectsCircle( + points.A, + points.A.attributes.get("data-circle"), + points.B, + points.C + ); + let intersections2 = utils.lineIntersectsCircle( + points.A, + points.A.attributes.get("data-circle"), + points.D, + points.E, + "y" + ); + let intersections3 = utils.lineIntersectsCircle( + points.A, + points.A.attributes.get("data-circle"), + points.F, + points.G + ); + snippets.first1 = new Snippet("bnotch", intersections1[0]); + snippets.first2 = new Snippet("bnotch", intersections2[0]); + snippets.second2 = new Snippet("x", intersections2[1]); + snippets.first3 = new Snippet("bnotch", intersections3[0]); + snippets.second3 = new Snippet("x", intersections3[1]); + + return part; +}; diff --git a/packages/examples/src/utils_lineintersectscurve.js b/packages/examples/src/utils_lineintersectscurve.js new file mode 100644 index 00000000000..0d3759625e3 --- /dev/null +++ b/packages/examples/src/utils_lineintersectscurve.js @@ -0,0 +1,35 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(10, 10); + points.Acp = new Point(310, 40); + points.B = new Point(110, 70); + points.Bcp = new Point(-210, 40); + points.E = new Point(20, -5); + points.D = new Point(100, 85); + paths.curve = new Path() + .move(points.A) + .curve(points.Acp, points.Bcp, points.B); + paths.line = new Path().move(points.E).line(points.D); + + for (let p of freesewing.utils.lineIntersectsCurve( + points.D, + points.E, + points.A, + points.Acp, + points.Bcp, + points.B + )) + snippets[part.getId()] = new Snippet("x", p); + + return part; +}; diff --git a/packages/examples/src/utils_linesintersect.js b/packages/examples/src/utils_linesintersect.js new file mode 100644 index 00000000000..091bfdca158 --- /dev/null +++ b/packages/examples/src/utils_linesintersect.js @@ -0,0 +1,27 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.A = new Point(10, 10); + points.B = new Point(50, 40); + points.C = new Point(15, 30); + points.D = new Point(60, 15); + + paths.AB = new Path().move(points.A).line(points.B); + paths.CD = new Path().move(points.C).line(points.D); + + snippets.X = new Snippet( + "x", + utils.linesIntersect(points.A, points.B, points.C, points.D) + ); + + return part; +}; diff --git a/packages/examples/src/utils_pointonbeam.js b/packages/examples/src/utils_pointonbeam.js new file mode 100644 index 00000000000..dc5f7957eca --- /dev/null +++ b/packages/examples/src/utils_pointonbeam.js @@ -0,0 +1,54 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + 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); + + let scatter = []; + for (let i = 1; i < 36; i++) { + for (let j = 1; j < 27; j++) { + scatter.push(new Point(i * 5, j * 5)); + } + } + let snippet; + for (let point of scatter) { + if (utils.pointOnBeam(points.from1, points.to1, point)) snippet = "notch"; + else snippet = "x"; + snippets[part.getId()] = new Snippet(snippet, point); + if (utils.pointOnBeam(points.from2, points.to2, point, 0.01)) + snippet = "notch"; + else snippet = "x"; + snippets[part.getId()] = new Snippet(snippet, point); + } + paths.line1 = new Path() + .move(points.from1) + .line(points.to1) + .attr("class", "fabric stroke-lg"); + paths.lne1 = new Path() + .move(points.to1) + .line(points.b1) + .attr("class", "fabric dashed"); + paths.line2 = new Path() + .move(points.from2) + .line(points.to2) + .attr("class", "fabric stroke-lg"); + paths.lne2 = new Path() + .move(points.to2) + .line(points.b2) + .attr("class", "fabric dashed"); + + return part; +}; diff --git a/packages/examples/src/utils_pointoncurve.js b/packages/examples/src/utils_pointoncurve.js new file mode 100644 index 00000000000..8d23eaf05f9 --- /dev/null +++ b/packages/examples/src/utils_pointoncurve.js @@ -0,0 +1,45 @@ +export default part => { + let { + debug, + Point, + points, + Path, + paths, + Snippet, + snippets, + utils + } = part.shorthand(); + + points.start = new Point(10, 10); + points.cp1 = new Point(90, 10); + points.cp2 = new Point(10, 60); + points.end = new Point(90, 60); + + let scatter = []; + for (let i = 1; i < 19; i++) { + for (let j = 1; j < 14; j++) { + scatter.push(new Point(i * 5, j * 5)); + } + } + let snippet; + for (let point of scatter) { + if ( + utils.pointOnCurve( + points.start, + points.cp1, + points.cp2, + points.end, + point + ) + ) + snippet = "notch"; + else snippet = "x"; + snippets[part.getId()] = new Snippet(snippet, point); + } + paths.curve = new Path() + .move(points.start) + .curve(points.cp1, points.cp2, points.end) + .attr("class", "fabric stroke-lg"); + + return part; +}; diff --git a/packages/examples/src/utils_pointonline.js b/packages/examples/src/utils_pointonline.js new file mode 100644 index 00000000000..c2dbee92f4a --- /dev/null +++ b/packages/examples/src/utils_pointonline.js @@ -0,0 +1,46 @@ +export default part => { + // prettier-ignore + let {debug, Point, points, Path, paths, Snippet, snippets, utils} = part.shorthand(); + + 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); + + let scatter = []; + for (let i = 1; i < 36; i++) { + for (let j = 1; j < 27; j++) { + scatter.push(new Point(i * 5, j * 5)); + } + } + let snippet; + for (let point of scatter) { + if (utils.pointOnLine(points.from1, points.to1, point)) snippet = "notch"; + else snippet = "x"; + snippets[part.getId()] = new Snippet(snippet, point); + if (utils.pointOnLine(points.from2, points.to2, point, 0.01)) + snippet = "notch"; + else snippet = "x"; + snippets[part.getId()] = new Snippet(snippet, point); + } + paths.line1 = new Path() + .move(points.from1) + .line(points.to1) + .attr("class", "fabric stroke-lg"); + paths.lne1 = new Path() + .move(points.to1) + .line(points.b1) + .attr("class", "fabric dashed"); + paths.line2 = new Path() + .move(points.from2) + .line(points.to2) + .attr("class", "fabric stroke-lg"); + paths.lne2 = new Path() + .move(points.to2) + .line(points.b2) + .attr("class", "fabric dashed"); + + return part; +};