svg-intersections
Advanced tools
Comparing version 0.2.2 to 0.2.3
// expose module classes | ||
exports.intersect = require('./lib/intersect'); | ||
exports.IntersectionParams = require('./lib/IntersectionParams'); | ||
exports.shape = require('./lib/IntersectionParams').newShape; |
@@ -122,8 +122,6 @@ var Point2D = require('kld-affine').Point2D; | ||
IntersectionParams.newShape = function(type, props) { | ||
if(type === IPTYPE.RECT && (props.rx > 0 || props.ry > 0)) { | ||
type = IPTYPE.ROUNDRECT; | ||
} | ||
IntersectionParams.newShape = function(svgElementName, props) { | ||
svgElementName = svgElementName.toLowerCase(); | ||
if(type === IPTYPE.LINE) { | ||
if(svgElementName === "line") { | ||
return IntersectionParams.newLine( | ||
@@ -135,18 +133,18 @@ new Point2D(props.x1, props.y1), | ||
if(type === IPTYPE.RECT) { | ||
return IntersectionParams.newRect( | ||
props.x, props.y, | ||
props.width, props.height | ||
); | ||
if(svgElementName === "rect") { | ||
if(props.rx > 0 || props.ry > 0) { | ||
return IntersectionParams.newRoundRect( | ||
props.x, props.y, | ||
props.width, props.height, | ||
props.rx, props.ry | ||
); | ||
} else { | ||
return IntersectionParams.newRect( | ||
props.x, props.y, | ||
props.width, props.height | ||
); | ||
} | ||
} | ||
if(type === IPTYPE.ROUNDRECT) { | ||
return IntersectionParams.newRoundRect( | ||
props.x, props.y, | ||
props.width, props.height, | ||
props.rx, props.ry | ||
); | ||
} | ||
if(type === IPTYPE.CIRCLE) { | ||
if(svgElementName === "circle") { | ||
return IntersectionParams.newCircle( | ||
@@ -158,3 +156,3 @@ new Point2D(props.cx, props.cy), | ||
if(type === IPTYPE.ELLIPSE) { | ||
if(svgElementName === "ellipse") { | ||
return IntersectionParams.newEllipse( | ||
@@ -166,3 +164,3 @@ new Point2D(props.cx, props.cy), | ||
if(type === IPTYPE.POLYGON) { | ||
if(svgElementName === "polygon") { | ||
return IntersectionParams.newPolygon( | ||
@@ -173,3 +171,3 @@ parsePointsString(props.points) | ||
if(type === IPTYPE.POLYLINE) { | ||
if(svgElementName === "polyline") { | ||
return IntersectionParams.newPolyline( | ||
@@ -180,3 +178,3 @@ parsePointsString(props.points) | ||
if(type === IPTYPE.PATH) { | ||
if(svgElementName === "path") { | ||
return IntersectionParams.newPath( | ||
@@ -183,0 +181,0 @@ props.d |
{ | ||
"name": "svg-intersections", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "A library of intersection algorithms covering all SVG shape types", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -13,2 +13,21 @@ svg-intersections | ||
API | ||
--- | ||
This module exports two functions: | ||
The `intersect` function takes two shapes as an input an returns an result | ||
object providing a result status, and all intersection points of the two shapes. | ||
```intersect (shape1, shape2)``` | ||
The `shape` function wraps the necessary input parameters for each of | ||
the two shapes. It requires the SVG element name of the shape as a string | ||
and an object of the SVG element's attributes. | ||
```shape (svgElementName, svgAttributes)``` | ||
Usage example | ||
@@ -25,7 +44,7 @@ ------------- | ||
var intersect = svgIntersections.intersect; | ||
var IntersectionParams = svgIntersections.IntersectionParams; | ||
var shape = svgIntersections.shape; | ||
var intersections = intersect( | ||
IntersectionParams.newShape("Circle", { cx: 0, cy: 0, r: 50 }), | ||
IntersectionParams.newShape("Rect", { x: 0, y: 0, width: 60, height: 30 }) | ||
shape("circle", { cx: 0, cy: 0, r: 50 }), | ||
shape("rect", { x: 0, y: 0, width: 60, height: 30 }) | ||
); | ||
@@ -32,0 +51,0 @@ |
var bezier = require('../lib/functions/bezier'); | ||
var intersect = require('../lib/intersect'); | ||
var IntersectionParams = require('../lib/IntersectionParams'); | ||
var intersect = require('../index').intersect; | ||
var shape = require('../index').shape; | ||
var Point2D = require('kld-affine/lib/Point2D'); | ||
var IPTYPE = IntersectionParams.TYPE; | ||
exports.testLineLineIntersection = function(beforeExit, assert) { | ||
var line1 = IntersectionParams.newShape(IPTYPE.LINE, {x1: 10, y1:10, x2:110, y2:110}); | ||
var line2 = IntersectionParams.newShape(IPTYPE.LINE, {x1: 110, y1:10, x2:10, y2:110}); | ||
var line1 = shape("line", {x1: 10, y1:10, x2:110, y2:110}); | ||
var line2 = shape("line", {x1: 110, y1:10, x2:10, y2:110}); | ||
var result = intersect(line1, line2); | ||
@@ -20,4 +18,4 @@ | ||
exports.testIntersectRectLine = function(beforeExit, assert) { | ||
var line = IntersectionParams.newShape(IPTYPE.LINE, {x1: 10, y1:10, x2:110, y2:110}); | ||
var rect = IntersectionParams.newShape(IPTYPE.RECT, {x:20, y:10, width:300, height:200}); | ||
var line = shape("line", {x1: 10, y1:10, x2:110, y2:110}); | ||
var rect = shape("rect", {x:20, y:10, width:300, height:200}); | ||
var result = intersect(rect, line); | ||
@@ -30,4 +28,4 @@ | ||
exports.testIntersectRoundRectLine = function(beforeExit, assert) { | ||
var line = IntersectionParams.newShape(IPTYPE.LINE, {x1: 10, y1:10, x2:110, y2:110}); | ||
var rect = IntersectionParams.newShape(IPTYPE.RECT, {x:20, y:20, width:300, height:200, rx:10, ry:10}); | ||
var line = shape("line", {x1: 10, y1:10, x2:110, y2:110}); | ||
var rect = shape("rect", {x:20, y:20, width:300, height:200, rx:10, ry:10}); | ||
var result = intersect(rect, line); | ||
@@ -40,4 +38,4 @@ | ||
exports.testIntersectDiamondLine = function(beforeExit, assert) { | ||
var diamond = IntersectionParams.newShape(IPTYPE.PATH, {d: "M -4.5,16 L 16,-4.5 L 35.5,16 L 16,35.5z"}); | ||
var line = IntersectionParams.newShape(IPTYPE.LINE, {x1: 0, y1:0, x2:20, y2:20}); | ||
var diamond = shape("path", {d: "M -4.5,16 L 16,-4.5 L 35.5,16 L 16,35.5z"}); | ||
var line = shape("line", {x1: 0, y1:0, x2:20, y2:20}); | ||
var result = intersect(diamond, line); | ||
@@ -44,0 +42,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109356
58
2255