Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pure-canvas

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pure-canvas - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

20

lib/Circle.js

@@ -11,9 +11,11 @@ "use strict";

function Circle(_a) {
var radius = _a.radius, _b = _a.lineWidth, lineWidth = _b === void 0 ? 1 : _b, _c = _a.strokeStyle, strokeStyle = _c === void 0 ? 'rgba(0, 0, 0, 1)' : _c, _d = _a.fillStyle, fillStyle = _d === void 0 ? 'rgba(255, 255, 255, 1)' : _d;
var minX = -radius - lineWidth / 2;
var minY = -radius - lineWidth / 2;
var maxX = radius + lineWidth / 2;
var maxY = radius + lineWidth / 2;
var _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c, radius = _a.radius, _d = _a.lineWidth, lineWidth = _d === void 0 ? 1 : _d, _e = _a.strokeStyle, strokeStyle = _e === void 0 ? 'rgba(0, 0, 0, 1)' : _e, _f = _a.fillStyle, fillStyle = _f === void 0 ? 'rgba(255, 255, 255, 1)' : _f;
var minX = x - radius - lineWidth / 2;
var minY = y - radius - lineWidth / 2;
var maxX = x + radius + lineWidth / 2;
var maxY = y + radius + lineWidth / 2;
var bounds = { minX: minX, minY: minY, maxX: maxX, maxY: maxY };
_super.call(this, bounds);
this.x = x;
this.y = y;
this.radius = radius;

@@ -25,3 +27,3 @@ this.lineWidth = lineWidth;

Circle.prototype.draw = function (context) {
var _a = this, radius = _a.radius, strokeStyle = _a.strokeStyle, lineWidth = _a.lineWidth, fillStyle = _a.fillStyle;
var _a = this, x = _a.x, y = _a.y, radius = _a.radius, strokeStyle = _a.strokeStyle, lineWidth = _a.lineWidth, fillStyle = _a.fillStyle;
var oldStrokeStyle = context.strokeStyle;

@@ -31,3 +33,3 @@ var oldFillStyle = context.fillStyle;

context.beginPath();
context.arc(0, 0, radius, 0, 2 * Math.PI, false);
context.arc(x, y, radius, 0, 2 * Math.PI, false);
context.strokeStyle = strokeStyle;

@@ -47,4 +49,4 @@ context.fillStyle = fillStyle;

var x = _a.x, y = _a.y;
var _b = this, radius = _b.radius, lineWidth = _b.lineWidth;
if (Math.pow(x, 2) + Math.pow(y, 2) <= Math.pow((radius + lineWidth / 2), 2)) {
var _b = this, ox = _b.x, oy = _b.y, radius = _b.radius, lineWidth = _b.lineWidth;
if (Math.pow((x - ox), 2) + Math.pow((y - oy), 2) <= Math.pow((radius + lineWidth / 2), 2)) {
return this;

@@ -51,0 +53,0 @@ }

{
"name": "pure-canvas",
"version": "0.4.0",
"version": "0.4.1",
"description": "TODO",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,2 +5,4 @@ import Node, {Bounds, Point} from './Node';

export interface CircleParameters {
x?: number;
y?: number;
radius: number;

@@ -13,2 +15,4 @@ lineWidth?: number;

class Circle extends NodeFixedBounds {
private x: number;
private y: number;
private radius: number;

@@ -19,10 +23,12 @@ private lineWidth: number;

constructor({radius, lineWidth = 1, strokeStyle = 'rgba(0, 0, 0, 1)', fillStyle = 'rgba(255, 255, 255, 1)'}: CircleParameters) {
const minX = -radius - lineWidth / 2;
const minY = -radius - lineWidth / 2;
const maxX = radius + lineWidth / 2;
const maxY = radius + lineWidth / 2;
constructor({x = 0, y = 0, radius, lineWidth = 1, strokeStyle = 'rgba(0, 0, 0, 1)', fillStyle = 'rgba(255, 255, 255, 1)'}: CircleParameters) {
const minX = x - radius - lineWidth / 2;
const minY = y - radius - lineWidth / 2;
const maxX = x + radius + lineWidth / 2;
const maxY = y + radius + lineWidth / 2;
const bounds: Bounds = {minX, minY, maxX, maxY};
super(bounds);
this.x = x;
this.y = y;
this.radius = radius;

@@ -35,3 +41,3 @@ this.lineWidth = lineWidth;

draw(context: CanvasRenderingContext2D): void {
const {radius, strokeStyle, lineWidth, fillStyle} = this;
const {x, y, radius, strokeStyle, lineWidth, fillStyle} = this;
const oldStrokeStyle = context.strokeStyle;

@@ -41,3 +47,3 @@ const oldFillStyle = context.fillStyle;

context.beginPath();
context.arc(0, 0, radius, 0, 2 * Math.PI, false);
context.arc(x, y, radius, 0, 2 * Math.PI, false);
context.strokeStyle = strokeStyle;

@@ -57,4 +63,4 @@ context.fillStyle = fillStyle;

intersection({x, y}: Point): Node {
const {radius, lineWidth} = this;
if (x ** 2 + y ** 2 <= (radius + lineWidth / 2) ** 2) {
const {x: ox, y: oy, radius, lineWidth} = this;
if ((x - ox) ** 2 + (y - oy) ** 2 <= (radius + lineWidth / 2) ** 2) {
return this;

@@ -61,0 +67,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc