Skip to content

Commit

Permalink
rename Composites function xx and yy params, closes #1095
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Mar 18, 2023
1 parent 272049a commit 6bda7e8
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions src/factory/Composites.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ var deprecated = Common.deprecated;
* Create a new composite containing bodies created in the callback in a grid arrangement.
* This function uses the body's bounds to prevent overlaps.
* @method stack
* @param {number} xx
* @param {number} yy
* @param {number} x Starting position in X.
* @param {number} y Starting position in Y.
* @param {number} columns
* @param {number} rows
* @param {number} columnGap
* @param {number} rowGap
* @param {function} callback
* @return {composite} A new composite containing objects created in the callback
*/
Composites.stack = function(xx, yy, columns, rows, columnGap, rowGap, callback) {
Composites.stack = function(x, y, columns, rows, columnGap, rowGap, callback) {
var stack = Composite.create({ label: 'Stack' }),
x = xx,
y = yy,
currentX = x,
currentY = y,
lastBody,
i = 0;

for (var row = 0; row < rows; row++) {
var maxHeight = 0;

for (var column = 0; column < columns; column++) {
var body = callback(x, y, column, row, lastBody, i);
var body = callback(currentX, currentY, column, row, lastBody, i);

if (body) {
var bodyHeight = body.bounds.max.y - body.bounds.min.y,
Expand All @@ -55,19 +55,19 @@ var deprecated = Common.deprecated;

Body.translate(body, { x: bodyWidth * 0.5, y: bodyHeight * 0.5 });

x = body.bounds.max.x + columnGap;
currentX = body.bounds.max.x + columnGap;

Composite.addBody(stack, body);

lastBody = body;
i += 1;
} else {
x += columnGap;
currentX += columnGap;
}
}

y += maxHeight + rowGap;
x = xx;
currentY += maxHeight + rowGap;
currentX = x;
}

return stack;
Expand Down Expand Up @@ -165,17 +165,17 @@ var deprecated = Common.deprecated;
* Create a new composite containing bodies created in the callback in a pyramid arrangement.
* This function uses the body's bounds to prevent overlaps.
* @method pyramid
* @param {number} xx
* @param {number} yy
* @param {number} x Starting position in X.
* @param {number} y Starting position in Y.
* @param {number} columns
* @param {number} rows
* @param {number} columnGap
* @param {number} rowGap
* @param {function} callback
* @return {composite} A new composite containing objects created in the callback
*/
Composites.pyramid = function(xx, yy, columns, rows, columnGap, rowGap, callback) {
return Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y, column, row, lastBody, i) {
Composites.pyramid = function(x, y, columns, rows, columnGap, rowGap, callback) {
return Composites.stack(x, y, columns, rows, columnGap, rowGap, function(stackX, stackY, column, row, lastBody, i) {
var actualRows = Math.min(rows, Math.ceil(columns / 2)),
lastBodyWidth = lastBody ? lastBody.bounds.max.x - lastBody.bounds.min.x : 0;

Expand All @@ -198,29 +198,29 @@ var deprecated = Common.deprecated;

var xOffset = lastBody ? column * lastBodyWidth : 0;

return callback(xx + xOffset + column * columnGap, y, column, row, lastBody, i);
return callback(x + xOffset + column * columnGap, stackY, column, row, lastBody, i);
});
};

/**
* This has now moved to the [newtonsCradle example](https://github.com/liabru/matter-js/blob/master/examples/newtonsCradle.js), follow that instead as this function is deprecated here.
* @deprecated moved to newtonsCradle example
* @method newtonsCradle
* @param {number} xx
* @param {number} yy
* @param {number} x Starting position in X.
* @param {number} y Starting position in Y.
* @param {number} number
* @param {number} size
* @param {number} length
* @return {composite} A new composite newtonsCradle body
*/
Composites.newtonsCradle = function(xx, yy, number, size, length) {
Composites.newtonsCradle = function(x, y, number, size, length) {
var newtonsCradle = Composite.create({ label: 'Newtons Cradle' });

for (var i = 0; i < number; i++) {
var separation = 1.9,
circle = Bodies.circle(xx + i * (size * separation), yy + length, size,
circle = Bodies.circle(x + i * (size * separation), y + length, size,
{ inertia: Infinity, restitution: 1, friction: 0, frictionAir: 0.0001, slop: 1 }),
constraint = Constraint.create({ pointA: { x: xx + i * (size * separation), y: yy }, bodyB: circle });
constraint = Constraint.create({ pointA: { x: x + i * (size * separation), y: y }, bodyB: circle });

Composite.addBody(newtonsCradle, circle);
Composite.addConstraint(newtonsCradle, constraint);
Expand All @@ -235,22 +235,22 @@ var deprecated = Common.deprecated;
* This has now moved to the [car example](https://github.com/liabru/matter-js/blob/master/examples/car.js), follow that instead as this function is deprecated here.
* @deprecated moved to car example
* @method car
* @param {number} xx
* @param {number} yy
* @param {number} x Starting position in X.
* @param {number} y Starting position in Y.
* @param {number} width
* @param {number} height
* @param {number} wheelSize
* @return {composite} A new composite car body
*/
Composites.car = function(xx, yy, width, height, wheelSize) {
Composites.car = function(x, y, width, height, wheelSize) {
var group = Body.nextGroup(true),
wheelBase = 20,
wheelAOffset = -width * 0.5 + wheelBase,
wheelBOffset = width * 0.5 - wheelBase,
wheelYOffset = 0;

var car = Composite.create({ label: 'Car' }),
body = Bodies.rectangle(xx, yy, width, height, {
body = Bodies.rectangle(x, y, width, height, {
collisionFilter: {
group: group
},
Expand All @@ -260,14 +260,14 @@ var deprecated = Common.deprecated;
density: 0.0002
});

var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
var wheelA = Bodies.circle(x + wheelAOffset, y + wheelYOffset, wheelSize, {
collisionFilter: {
group: group
},
friction: 0.8
});

var wheelB = Bodies.circle(xx + wheelBOffset, yy + wheelYOffset, wheelSize, {
var wheelB = Bodies.circle(x + wheelBOffset, y + wheelYOffset, wheelSize, {
collisionFilter: {
group: group
},
Expand Down Expand Up @@ -306,8 +306,8 @@ var deprecated = Common.deprecated;
* and the [cloth example](https://github.com/liabru/matter-js/blob/master/examples/cloth.js), follow those instead as this function is deprecated here.
* @deprecated moved to softBody and cloth examples
* @method softBody
* @param {number} xx
* @param {number} yy
* @param {number} x Starting position in X.
* @param {number} y Starting position in Y.
* @param {number} columns
* @param {number} rows
* @param {number} columnGap
Expand All @@ -318,12 +318,12 @@ var deprecated = Common.deprecated;
* @param {} constraintOptions
* @return {composite} A new composite softBody
*/
Composites.softBody = function(xx, yy, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) {
Composites.softBody = function(x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) {
particleOptions = Common.extend({ inertia: Infinity }, particleOptions);
constraintOptions = Common.extend({ stiffness: 0.2, render: { type: 'line', anchors: false } }, constraintOptions);

var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y) {
return Bodies.circle(x, y, particleRadius, particleOptions);
var softBody = Composites.stack(x, y, columns, rows, columnGap, rowGap, function(stackX, stackY) {
return Bodies.circle(stackX, stackY, particleRadius, particleOptions);
});

Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);
Expand Down

0 comments on commit 6bda7e8

Please sign in to comment.