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

atlaspack

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atlaspack - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

5

example/example.js

@@ -10,2 +10,3 @@ // create a canvas

var atlas = createAtlas(canvas);
//atlas.tilepad = true;

@@ -16,2 +17,3 @@ function atlasPack(img) {

atlas = atlas.expand(img);
//atlas.tilepad = true;
}

@@ -25,3 +27,4 @@ }

'obsidian', 'plank', 'whitewool',
'crate', 'bedrock', 'bluewool', 'cobblestone',
'crate',
'bedrock', 'bluewool', 'cobblestone',
'brick', 'diamond', 'glowstone',

@@ -28,0 +31,0 @@ 'netherrack', 'redwool',

45

index.js

@@ -37,2 +37,3 @@ /*

this.filled = false;
this.tilepad = false;
this._cache = [];

@@ -54,2 +55,7 @@ this._uvcache = Object.create(null);

rect = this._toRect(rect);
if (this.img && this.tilepad) {
rect = this._tilepad(rect);
}
if (this.left !== null) {

@@ -81,2 +87,6 @@ return this._ontoCanvas(this.left.pack(rect) || this.right.pack(rect));

if (this.img && this.tilepad) {
rect = this._tilepad(rect);
}
var atlas;

@@ -135,2 +145,3 @@ if (this.rect.w < this.rect.h) {

}
var isPad = this.tilepad;
(function loop(atlas) {

@@ -141,7 +152,8 @@ if (atlas.left !== null) {

} else if (typeof atlas.rect.name !== 'undefined') {
var p = (isPad) ? atlas.rect.w / 4 : 0;
self._uvcache[atlas.rect.name] = [
[atlas.rect.x, atlas.rect.y],
[atlas.rect.x + atlas.rect.w, atlas.rect.y],
[atlas.rect.x + atlas.rect.w, atlas.rect.y + atlas.rect.h],
[atlas.rect.x, atlas.rect.y + atlas.rect.h],
[atlas.rect.x + p, atlas.rect.y + p],
[(atlas.rect.x + p) + (atlas.rect.w - (p * 2)), atlas.rect.y + p],
[(atlas.rect.x + p) + (atlas.rect.w - (p * 2)), (atlas.rect.y + p) + (atlas.rect.h - (p * 2))],
[(atlas.rect.x + p), (atlas.rect.y + p) + (atlas.rect.h - (p * 2))],
].map(function(uv) {

@@ -187,2 +199,27 @@ if (uv[0] !== 0) {

// Pads the image by tiling itself around itself
Atlas.prototype._tilepad = function(rect) {
var img = this.img;
if (!img) return rect;
var p = img.width / 2;
var canvas = document.createElement('canvas');
canvas.name = img.name || img.src;
canvas.id = img.id || '';
canvas.width = img.width + img.width;
canvas.height = img.height + img.height;
var ctx = canvas.getContext('2d');
var pattern = ctx.createPattern(img, 'repeat');
ctx.fillStyle = pattern;
ctx.translate(p, p);
ctx.fillRect(-p, -p, canvas.width + p, canvas.height + p);
ctx.translate(-p, -p);
this.img = canvas;
return new Rect(rect.x, rect.y, this.img.width, this.img.height);
};
// if has an image and canvas, draw to the canvas as we go

@@ -189,0 +226,0 @@ Atlas.prototype._ontoCanvas = function(node) {

{
"name": "atlaspack",
"description": "Pack rectangles (or images) into a rectangle (or canvas texture atlas).",
"version": "0.2.2",
"version": "0.2.3",
"homepage": "https://github.com/shama/atlaspack",

@@ -6,0 +6,0 @@ "author": {

@@ -152,2 +152,7 @@ # atlaspack

#### `atlas.tilepad`
Set this boolean property to `true` if you would like each packed image to pad
itself with a tiled pattern of itself. Useful for avoiding texture bleeding when
mipmapping.
### `atlaspack.Rect(x, y, w, h)`

@@ -170,2 +175,3 @@ Creates a rectangle instance.

## release history
* 0.2.3 - Add tilepad property to help with mipmapping.
* 0.2.2 - Ability to get and set JSON key.

@@ -172,0 +178,0 @@ * 0.2.1 - Add uv method for uv coordinates.

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