npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cg-point

v1.0.0-beta2

Published

An object representing a point in a two-dimensional coordinate system.

Downloads

51

Readme

A structure that contains a point in a two-dimensional ( x , y ) coordinate system.

Usage

const CGPoint = require('cg-point');

// Create point representing two coordinates in 2D space
let point = new CGPoint(5, 10);
console.log( point.x, point.y ); // 5, 10

//Default values
let defaultPoint = new CGPoint(); // null, null

Static Methods and Properties

CGPoint . zero

Returns a point constant with location (0,0). The zero point is equivalent to CGPoint(0,0).


let point = new CGPoint(0, 0);
point.equalTo(CGPoint.zero); //true

let other = new CGPoint(1, 1);
other.equalTo(CGPoint.zero); //false

CGPoint . null

Unlike CGPoint.zero, CGPoint.null has no assigned position. Both coordinates are null


let point = new CGPoint(null, null);
point.equalTo(CGPoint.null); //true

let defaultPoint = new CGPoint();
defaultPoint.equalTo(CGPoint.null); //true

let other = new CGPoint(1, 1);
other.equalTo(CGPoint.null); //false

CGPoint . infinite

Returns a point constant with location (Infinity, Infinity). An infinite point is one that has no defined bounds. .


let point = new CGPoint(Infinity, Infinity);
point.equalTo(CGPoint.infinite); //true

let other = new CGPoint(1, 1);
other.equalTo(CGPoint.infinite); //false

CGPoint . fromString( str )

Returns a CGPoint instance from the string. If string is malformed, it returns a CGPoint.zero


let point = new CGPoint.fromString("{1,2}");
console.log(point.x, point.y); //1,2

let other = new CGPoint.fromString("%##@$#@");
console.log(point.x, point.y); //0,0

Instance Methods and Properties

#isEmpty

Returns true if point is empty. An empty point is either a null point or a valid point with zero x or y.

let one = new CGPoint(0, 0);
console.log(one.isEmpty); // true

let two = new CGPoint(null, null);
console.log(two.isEmpty); // true

let three = new CGPoint(Infinity, Infinity);
console.log(three.isEmpty); // false

#isNull

Returns true if both point coordinates are null.

let one = new CGPoint(0, 0);
console.log(one.isNull); // false

let two = new CGPoint(null, null);
console.log(two.isNull); // true

let three = new CGPoint(Infinity, Infinity);
console.log(three.isNull); // false

#isInfinite

Returns true if point is infinite. An infinite point is one that has no defined bounds

let one = new CGPoint(0, 0);
console.log(one.isInfinite); // false

let two = new CGPoint(null, null);
console.log(two.isInfinite); // false

let three = new CGPoint(Infinity, Infinity);
console.log(three.isInfinite); // true

#integral

A point with the smallest integer values for its x and y coorindates. That is, given a point with fractional x or y values, integral rounds down the points x or y coordinates to the nearest whole integer. Returns a null point if rect is a null point.

let double = new CGPoint(1.5, -1.5);
console.log( double.integral.toString() ); // {1,-2}

#equalTo ( point: CGPoint )

Checks if a point has the same x, y coordinates as another (inclusive)


let point = new CGPoint(1, 1);
let other = new CGPoint(-2, -2);

point.equalTo(other); //false

let match = new CGPoint(1, 1);
point.equalTo(match); //true

#toString ( point )

Produces a string representation of the point


let point = new CGPoint(1, 1);
console.log(point.toString()) // {1,1}