Skip to content

Commit

Permalink
heart - formula update
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyBirdSoar authored and SkyBirdSoar committed Sep 21, 2014
1 parent 10d04dc commit 46e2585
Showing 1 changed file with 3 additions and 69 deletions.
72 changes: 3 additions & 69 deletions mathpw/res/giftboxes/giftboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ window.Heart = function(radius, height, lidHeight) {
var volumeOfBox = baseAreaOfHeart * height;
var perimeterOfHeartBase = (2 * pi * radius) + 4 * radius;
var perimeterOfLid = (2 * pi * lidRadius) + 4 * lidRadius;
var lengthOfHeart = 2 * Math.sqrt(0.5 * (2 * radius).square()) + (radius - (radius * Math.cos(toRadians(45))));
var breadthOfHeart = 2 * Math.sqrt(0.5 * (2 * radius).square()) + (radius - (radius * Math.cos(toRadians(45)))) + (radius - (radius * Math.cos(toRadians(45))));
var lengthOfHeart = 2 * Math.sqrt(2 * radius.square()) + (radius - (radius * Math.cos(toRadians(45))));
var breadthOfHeart = 2 * Math.sqrt(2 * radius.square()) + (2 * (radius - (radius * Math.cos(toRadians(45)))));
var areaOfPaperUsedByHeartBase = breadthOfHeart * lengthOfHeart;
var lengthOfLid = 2 * Math.sqrt(0.5 * (2 * lidRadius).square()) + (lidRadius - (lidRadius * Math.cos(toRadians(45))));
var breadthOfLid = 2 * Math.sqrt(0.5 * (2 * lidRadius).square()) + (lidRadius - (lidRadius * Math.cos(toRadians(45)))) + (lidRadius - (lidRadius * Math.cos(toRadians(45))));
Expand Down Expand Up @@ -187,73 +187,7 @@ window.Box = function(length, breadth, height, lidHeight) {
};

this.calculatePaperRequired = function() {
var paperRequired = 1; // minimum
var box = {x: this.length, y: this.breadth};
var lid = {x: this.length + 0.2, y: this.length + 0.2};
if ((lid.y > window.PAPER.y) || (lid.x > window.PAPER.x)) { // using heartLid due to it being bigger.
return {
error: true,
error_msg: 'The box is bigger than paper size, try reducing the values.'
};
}
var rY = window.PAPER.y; // r stands for remaining
var rX = window.PAPER.x;
var lateralArea = {length: (properties.perimeterOfHeartBase / 2) + 1, breadth: height + 1}; // half only!
var lidLateralArea = {length: (properties.perimeterOfLid / 2) + 1, breadth: lidHeight + 1};

var id = ['heart', 'latA', 'latB', 'heartLid', 'lidLatA', 'lidLatB'];
if ((window.PAPER.y >= lidLateralArea.length) && (window.PAPER.x >= lidLateralArea.breadth)) { // vertical alignment (x dominant) |||
var formula = [heart.x, lateralArea.breadth + 1, lateralArea.breadth + 1, heartLid.x, lidLateralArea.breadth + 1, lidLateralArea.breadth + 1];
for (var i = 0; i < formula.length; i++) {
if (rX > formula[i]) {
rX = rX - formula[i];
} else {
paperRequired = paperRequired + 1;
rX = window.PAPER.x;
if (rX > formula[i]) {
rX = rX - formula[i];
} else {
return {
error: true,
error_msg: id[i] + 'x exceeded paper breadth, try reducing the values.',
alignment: 'vertical'
};
}
}
}
return {
paperRequired: paperRequired,
alignment: 'vertical'
};
} else if ((window.PAPER.y >= lidLateralArea.breadth) && (window.PAPER.x >= lidLateralArea.length)) { // horizontal alignment (y dominant) =
var formula = [heart.y, lateralArea.breadth + 1, lateralArea.breadth + 1, heartLid.y, lidLateralArea.breadth + 1, lidLateralArea.breadth + 1];
for (var i = 0; i < formula.length; i++) {
if (rY > formula[i]) {
rY = rY - formula[i];
} else {
paperRequired = paperRequired + 1;
rY = window.PAPER.x;
if (rY > formula[i]) {
rY = rY - formula[i];
} else {
return {
error: true,
error_msg: id[i] + 'y exceeded paper height, try reducing the values.',
alignment: 'horizontal'
};
}
}
}
return {
paperRequired: paperRequired,
alignment: 'horizontal'
};
} else {
return {
error: true,
error_msg: 'The perimeter is bigger than paper size, try reducing the values.'
};
}
return {paperRequired: Math.ceil((properties.baseArea + properties.baseAreaOfLid + properties.lateralArea + properties.lateralAreaOfLid) / window.PAPER.area)};
};

this.calculateBaseCost = function(paperSelected) {
Expand Down

0 comments on commit 46e2585

Please sign in to comment.