bin-packing-core
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -8,2 +8,3 @@ import { FindPosition } from './max-rect-bin-pack'; | ||
liveRate: number; | ||
allowRotate: boolean; | ||
} | ||
@@ -20,2 +21,3 @@ interface IPoint { | ||
private liveRate; | ||
private allowRotate; | ||
private totalSquares; | ||
@@ -22,0 +24,0 @@ private maxHeight; |
@@ -34,2 +34,3 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
this.findPosition = options.findPosition; | ||
this.allowRotate = options.allowRotate === true ? true : false; | ||
} | ||
@@ -79,3 +80,3 @@ Object.defineProperty(Genetic.prototype, "minHeight", { | ||
// 生活 | ||
var binPack = new max_rect_bin_pack_1.default(dot.x, dot.y, true); | ||
var binPack = new max_rect_bin_pack_1.default(dot.x, dot.y, this.allowRotate); | ||
var clonedRects = this.getRects(); | ||
@@ -82,0 +83,0 @@ var result = binPack.insertRects(clonedRects, this.findPosition); |
{ | ||
"name": "bin-packing-core", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "image packer based on genetic & max-rect algorithm", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -103,2 +103,3 @@ # 基于人工智能的雪碧图拼接算法 | ||
size: 50, // 每一代孩子个数 | ||
allowRotate: false,// 不支持旋转 | ||
}); | ||
@@ -108,3 +109,3 @@ | ||
const height = bestSize.y; | ||
const packer = new MaxRectBinPack(width, height, true); | ||
const packer = new MaxRectBinPack(width, height, false);//不支持旋转 | ||
const result = packer.insertRects(rects, findPosition); | ||
@@ -111,0 +112,0 @@ console.log(result.length === /* rects.length */); |
@@ -9,2 +9,3 @@ import MaxRectBinPack, { FindPosition } from './max-rect-bin-pack'; | ||
liveRate: number; | ||
allowRotate: boolean; | ||
} | ||
@@ -29,2 +30,3 @@ | ||
private liveRate: number; | ||
private allowRotate: boolean; | ||
@@ -55,2 +57,3 @@ private totalSquares: number = 0; | ||
this.findPosition = options.findPosition; | ||
this.allowRotate = options.allowRotate === true ? true : false; | ||
} | ||
@@ -84,3 +87,3 @@ public calc(): IPoint { | ||
// 生活 | ||
const binPack = new MaxRectBinPack(dot.x, dot.y, true); | ||
const binPack = new MaxRectBinPack(dot.x, dot.y, this.allowRotate); | ||
const clonedRects = this.getRects(); | ||
@@ -87,0 +90,0 @@ const result = binPack.insertRects(clonedRects, this.findPosition); |
@@ -1,1 +0,1 @@ | ||
var data = [{"x":0,"y":0,"width":202,"height":100},{"x":0,"y":100,"width":122,"height":60},{"x":122,"y":100,"width":102,"height":50},{"x":122,"y":150,"width":22,"height":10},{"x":202,"y":0,"width":182,"height":90},{"x":384,"y":0,"width":80,"height":162},{"x":224,"y":90,"width":142,"height":70},{"x":464,"y":0,"width":40,"height":82},{"x":464,"y":82,"width":30,"height":62},{"x":494,"y":82,"width":20,"height":42}] | ||
var data = [{"x":0,"y":0,"width":121,"height":385,"isRotated":true},{"x":121,"y":0,"width":121,"height":382,"isRotated":true},{"x":242,"y":0,"width":121,"height":379,"isRotated":true},{"x":363,"y":0,"width":121,"height":375,"isRotated":true},{"x":484,"y":0,"width":121,"height":356,"isRotated":true},{"x":605,"y":0,"width":128,"height":342,"isRotated":true},{"x":733,"y":0,"width":122,"height":339,"isRotated":true},{"x":855,"y":0,"width":121,"height":327,"isRotated":true},{"x":976,"y":0,"width":121,"height":224,"isRotated":true},{"x":976,"y":224,"width":121,"height":130,"isRotated":true},{"x":1097,"y":0,"width":428,"height":124,"isRotated":false},{"x":1525,"y":0,"width":121,"height":206,"isRotated":true},{"x":1097,"y":124,"width":422,"height":123,"isRotated":false},{"x":1097,"y":247,"width":387,"height":122,"isRotated":false},{"x":1484,"y":247,"width":190,"height":121,"isRotated":false}] |
@@ -6,16 +6,5 @@ var FindPosition = require('./../lib/index').FindPosition; | ||
var Rect = require('./../lib/index').Rect; | ||
const rects = []; | ||
for (var i = 0; i < 10; i++) { | ||
var r = new Rect(); | ||
r.width = (i + 1) * 10; | ||
r.height = (i + 1) * 11; | ||
r.info = { | ||
width: r.width, | ||
height: r.height, | ||
id: i, | ||
}; | ||
rects.push(r); | ||
} | ||
const findPosition = 0; // 参照第一条 | ||
@@ -22,0 +11,0 @@ |
@@ -9,8 +9,15 @@ //tslint:disable | ||
const rects: Rect[] = []; | ||
for (let i = 0; i < 10; i++) { | ||
const rect = new Rect(); | ||
rect.height = (i + 1) * 10; | ||
rect.width = (i + 1.1) * 20; | ||
const r = [{"x":0,"y":0,"width":387,"height":122,"isRotated":false,"info":{"name":"tileset-ornaments-001"}},{"x":0,"y":0,"width":356,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-002"}},{"x":0,"y":0,"width":379,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-003"}},{"x":0,"y":0,"width":375,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-004"}},{"x":0,"y":0,"width":342,"height":128,"isRotated":false,"info":{"name":"tileset-ornaments-005"}},{"x":0,"y":0,"width":130,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-006"}},{"x":0,"y":0,"width":339,"height":122,"isRotated":false,"info":{"name":"tileset-ornaments-007"}},{"x":0,"y":0,"width":327,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-008"}},{"x":0,"y":0,"width":385,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-009"}},{"x":0,"y":0,"width":382,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-010"}},{"x":0,"y":0,"width":422,"height":123,"isRotated":false,"info":{"name":"tileset-ornaments-011"}},{"x":0,"y":0,"width":428,"height":124,"isRotated":false,"info":{"name":"tileset-ornaments-012"}},{"x":0,"y":0,"width":190,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-013"}},{"x":0,"y":0,"width":224,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-014"}},{"x":0,"y":0,"width":206,"height":121,"isRotated":false,"info":{"name":"tileset-ornaments-015"}}] | ||
r.forEach($=>{ | ||
var rect = new Rect(); | ||
rect.width = $.width; | ||
rect.height = $.height; | ||
rect.info = $.info; | ||
rect.info.width = $.width; | ||
rect.info.height = $.height; | ||
rects.push(rect); | ||
} | ||
}) | ||
const bestNode = genetic(rects, { | ||
@@ -33,2 +40,3 @@ findPosition: FindPosition.AreaFit, | ||
let rectslength = rects.length; | ||
console.log(rectslength); | ||
const result = packer.insertRects(rects, FindPosition.AreaFit); | ||
@@ -35,0 +43,0 @@ console.log(result.length === rectslength); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
205958
1900
118