Skip to content

Commit

Permalink
feat(shape): add rotate manipulation property
Browse files Browse the repository at this point in the history
Closes #60.
  • Loading branch information
colinmeinke committed Jan 29, 2017
1 parent 93fe99f commit f9828d0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -415,6 +415,8 @@ The functions are defined as the following properties.
- `reverse` is a *boolean* that when:
- `true` reverses the order of points
- `false` has no effect
= `rotate` is a *number* that defines the degrees to rotate the
shape clockwise
- `scale` is either:
- a *number* that defines the scale factor, or
- an *array* that includes:
Expand Down
1 change: 1 addition & 0 deletions examples/fill-rule/client.js
Expand Up @@ -4,6 +4,7 @@ const from1 = {
type: 'path',
d: 'M20,20H80V80H20ZM30,30V70H70ZM40,40H60V60H40Z',
fillRule: 'evenodd',
rotate: 45
}

const from2 = {
Expand Down
6 changes: 5 additions & 1 deletion src/core/shape/create.js
Expand Up @@ -23,6 +23,7 @@
*
* @property {integer} [moveIndex] - the amount of points by which to offset a shape's index point.
* @property {number[]} [offset] - the amount to offset a shape's points horizontally and vertically.
* @property {number} [rotate] - the clockwise angle to rotate the shape.
* @property {boolean} [reverse] - reverses the shape's points.
* @property {(number|(number|string)[])} [scale] - scales a shape.
*/
Expand Down Expand Up @@ -134,7 +135,7 @@ import {
} from './props'

import { filter } from '../helpers'
import { moveIndex, offset, reverse, scale } from 'points'
import { moveIndex, offset, reverse, rotate, scale } from 'points'
import { toPoints } from 'svg-points'

/**
Expand Down Expand Up @@ -267,6 +268,9 @@ const manipulate = ({ manipulations, points }) => (

break

case 'rotate':
return rotate(nextPoints, args)

case 'scale':
const isArray = Array.isArray(args)
const scaleFactor = isArray ? args[ 0 ] : args
Expand Down
1 change: 1 addition & 0 deletions src/core/shape/props.js
Expand Up @@ -18,6 +18,7 @@ const manipulationProps = [
'moveIndex',
'offset',
'reverse',
'rotate',
'scale'
]

Expand Down
22 changes: 22 additions & 0 deletions tests/core/shape/create.js
Expand Up @@ -375,6 +375,28 @@ describe('manipulate', () => {
expect(manipulate({ manipulations, points })).toEqual(result)
})

it('should rotate points', () => {
const manipulations = { rotate: 90 }

const points = [
{ x: 0, y: 0, moveTo: true },
{ x: 100, y: 0 },
{ x: 100, y: 100 },
{ x: 0, y: 100 },
{ x: 0, y: 0 }
]

const result = [
{ x: 100, y: 0, moveTo: true },
{ x: 100, y: 100 },
{ x: 0, y: 100 },
{ x: 0, y: 0 },
{ x: 100, y: 0 }
]

expect(manipulate({ manipulations, points })).toEqual(result)
})

it('should scale points', () => {
const manipulations = { scale: 2 }

Expand Down

0 comments on commit f9828d0

Please sign in to comment.