Skip to content

Commit

Permalink
fix bug & update preview
Browse files Browse the repository at this point in the history
  • Loading branch information
luz-alphacode committed Apr 29, 2019
1 parent e0e1e7e commit 579518f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Both offset/offsetStroke take the form of **f(offset: number, options?: {})**, t
<br/>&nbsp;&nbsp;**insert**: whether the result should be insert into the canvas, default is **true**.

## Preview
There are some cases that the library may return weird result or failed silently, please let me noticed in the project issues. And in some cases the library will yeild an ok result than a perfect one.
There are some cases that the library may return weird result or failed silently, please let me noticed in the project issues. And in some cases the library will yeild an ok result than a perfect one. Currently the library should give good results for closed shapes, but may fail in some open curve cases, I'm still working on it.
![Preview](/public/preview.jpg)

## Development
Expand Down
6 changes: 1 addition & 5 deletions demo/paperjs-offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,6 @@
newPath.children.filter(function (c) {
if (c.segments.length > 1) {
return !IsSameDirection(c, path);
// let sample1 = c.segments[0].location.offset
// let sample2 = c.segments[Math.max(1, Math.floor(c.segments.length / 2))].location.offset
// let offset1 = path.getNearestLocation(c.getPointAt((sample1 + sample2) / 3)).offset
// let offset2 = path.getNearestLocation(c.getPointAt((sample1 + sample2) / 3 * 2)).offset
// return offset1 > offset2
}
else {
return true;
Expand Down Expand Up @@ -596,6 +591,7 @@
result = new paper.CompoundPath({ children: children, insert: false });
}
result.copyAttributes(nonSIPath, false);
result.remove();
return result;
}
function OffsetStroke(path, offset, join, cap, limit) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paperjs-offset",
"version": "1.0.4",
"version": "1.0.5",
"description": "An offset function for paperjs path.",
"main": "dist/index.umd.js",
"module": "dist/index.es5.js",
Expand Down
Binary file modified public/preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions src/Offset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ namespace Offsets {
(newPath.children as Array<paper.Path>).filter(c => {
if (c.segments.length > 1) {
return !IsSameDirection(c, path)
// let sample1 = c.segments[0].location.offset
// let sample2 = c.segments[Math.max(1, Math.floor(c.segments.length / 2))].location.offset
// let offset1 = path.getNearestLocation(c.getPointAt((sample1 + sample2) / 3)).offset
// let offset2 = path.getNearestLocation(c.getPointAt((sample1 + sample2) / 3 * 2)).offset
// return offset1 > offset2
} else {
return true
}
Expand Down Expand Up @@ -335,6 +330,7 @@ export function OffsetPath(path: PathType, offset: number, join: StrokeJoinType,
result = new paper.CompoundPath({ children, insert: false })
}
result.copyAttributes(nonSIPath, false)
result.remove()
return result
}

Expand Down

0 comments on commit 579518f

Please sign in to comment.