Skip to content

Commit

Permalink
changelog/docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Apr 16, 2015
1 parent aed6826 commit 49069ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
9 changes: 5 additions & 4 deletions HISTORY.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
1.1.0 / WIP
------------------

- Unified transformations logic.
- Added `.matrix` and `.rodate()` methods.
- Unified transformations math.
- Added `.matrix` and `.rotate()`.
- Added `.unarc()` - convert arcs to curves.
- Evaluate curried transforms lazily.
- Coverage improvement.
- Minor optimisation & code refactoring.
- 100% tests coverage.
- Minor optimisations & code refactoring.


1.0.7 / 2014-12-05
Expand Down
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Example
```js
var svgpath = require('svgpath');

var transformedPath = svgpath(__your_path__)
.scale(0.5)
.translate(100,200)
.abs()
.round(1) // Here the real rounding happens
.rel()
.round(1) // Fix js floating point error/garbage after rel()
.toString()
var transformed = svgpath(__your_path__)
.scale(0.5)
.translate(100,200)
.abs()
.round(1) // Here the real rounding happens
.rel()
.round(1) // Fix js floating point error after rel()
.toString();
```


Expand All @@ -44,9 +44,10 @@ API
All methods are chainable (return self).


### SvgPath(path) -> self
### new SvgPath(path) -> self

Constructor. Create SvgPath instance with chainable methods.
Constructor. Creates new `SvgPath` class instance with chainable methods.
`new` can be omited.


### .abs() -> self
Expand Down Expand Up @@ -93,14 +94,19 @@ Converts smooth curves (`T`, `t`, `S`, `s`) with missed control point to
generic curves.


### .unarc() -> self

Replaces all arcs with bezier curves.


### .toString() -> string

Returns final path string.


### .round(precision) -> self

Round all coordinated to given decimal precision. By default round to integer.
Round all coordinates to given decimal precision. By default round to integer.
Useful to reduce resulting string size.

(!) NOTE:
Expand All @@ -111,16 +117,18 @@ Useful to reduce resulting string size.
`0.000000000000023`. So, you have to call .round(x) again. See example above.


### .iterate(function [, keepLazyStack]) -> self
### .iterate(function(segment, index, x, y) [, keepLazyStack]) -> self

Apply iterator to all path segments. Each iterator receives `segment`, `index`,
`x`, `y` params. Where (x, y) - absolute coordinates of segment start point.
Apply iterator to all path segments.

Also, you iterator can return array of new segments, that should replace
current one. On empty array current segment will be deleted.
- Each iterator receives `segment`, `index`, `x` and `y` params.
Where (x, y) - absolute coordinates of segment start point.
- Iterator can modify current segment directly (return nothing in this case).
- Iterator can return array of new segments to replace current one (`[]` means
that current segment should be delated).

If seconnd param `keepLazyStack` set to `true`, then iterator will not evaluate
stacked transforms prior to run.
If second param `keepLazyStack` set to `true`, then iterator will not evaluate
stacked transforms prior to run. That can be useful to optimize calculations.


Authors
Expand Down
5 changes: 3 additions & 2 deletions lib/svgpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function SvgPath(path) {

SvgPath.prototype.__matrix = function (m) {
var self = this,
ma, sx, sy, angle, a, arc2line;
ma, sx, sy, angle, arc2line;

// Quick leave for empty matrix
if (!m.queue.length) { return; }
Expand Down Expand Up @@ -75,7 +75,7 @@ SvgPath.prototype.__matrix = function (m) {
case 'A':
// ARC is: ['A', rx, ry, x-axis-rotation, large-arc-flag, sweep-flag, x, y]

// Drop segment if arc is empty
// Drop segment if arc is empty (end point === start point)
if ((s[0] === 'A' && s[6] === x && s[7] === y) ||
(s[0] === 'a' && s[6] === 0 && s[7] === 0)) {
return [];
Expand All @@ -87,6 +87,7 @@ SvgPath.prototype.__matrix = function (m) {
// Fill cache if empty
if (!ma) {
ma = m.toArray();

sx = Math.sqrt(Math.pow(ma[0], 2) + Math.pow(ma[2], 2));
arc2line = true;

Expand Down

0 comments on commit 49069ea

Please sign in to comment.