function House() { this.apertures = { doors: {}, windows: {} }; this.corners = { inner: {}, outer: {} }; this.cornices = {}; this.pediments = {}; this.walls = {}; this.newIdentifierFor = { cornice: 0, door: 0, innerCorner: 0, outerCorner: 0, pediment: 0, wall: 0, window: 0 } } House.prototype.addCornice = function (id, width, length, count) { this.cornices[id] = new Line(width, length, count); this.newIdentifierFor.cornice++; return true; }; House.prototype.addDoor = function (id, height, width, count) { this.apertures.doors[id] = new Rectangle(height, width, count); this.newIdentifierFor.door++; return true; }; House.prototype.addInnerCorner = function(id, height, count) { this.corners.inner[id] = new Corner(height, count); this.newIdentifierFor.innerCorner++; return true; }; House.prototype.addOuterCorner = function(id, height, count) { this.corners.outer[id] = new Corner(height, count); this.newIdentifierFor.outerCorner++; return true; }; House.prototype.addPediment = function (id, height, width, count) { this.pediments[id] = new RectangleHalf(height, width, count); this.newIdentifierFor.pediment++; return true; }; House.prototype.addWall = function (id, height, width, count) { this.walls[id] = new Rectangle(height, width, count); this.newIdentifierFor.wall++; return id; }; House.prototype.addWindow = function(id, height, width, count) { this.apertures.windows[id] = new Rectangle(height, width, count); this.newIdentifierFor.window++; return id; }; House.prototype.deleteCornice = function(id) { delete this.cornices[id]; }; House.prototype.deleteDoor = function(id) { delete this.apertures.doors[id]; }; House.prototype.deleteInnerCorner = function(id) { delete this.corners.inner[id]; }; House.prototype.deleteOuterCorner = function(id) { delete this.corners.outer[id]; }; House.prototype.deletePediment = function(id) { delete this.pediments[id]; }; House.prototype.deleteWall = function(id) { delete this.walls[id]; }; House.prototype.deleteWindow = function(id) { delete this.apertures.windows[id]; }; House.prototype.getAperturesSquare = function() { return this.getDoorsSquare() + this.getWindowsSquare(); }; House.prototype.getCornicesFinishPlanksCount = function() { var sum = 0; var item; for (var id in this.cornices) { if (this.cornices.hasOwnProperty(id)) { item = this.cornices[id]; sum += item.length * item.count; } } return Math.ceil(sum / 3); }; House.prototype.getCornicesJProfilesCount = function() { var sum = 0; var item; var sqrt; var id; for (id in this.pediments) { if (this.pediments.hasOwnProperty(id)) { item = this.pediments[id]; //noinspection MagicNumberJS sqrt = Math.sqrt(0.25 * Math.pow(item.width, 2) + Math.pow(item.height, 2)); sum += 2 * sqrt * item.count; } } for (id in this.cornices) { if (this.cornices.hasOwnProperty(id)) { item = this.cornices[id]; sum += item.length * item.count; } } return Math.ceil(sum / 3); }; House.prototype.getCornicesSquare = function() { var sum = 0; for (var id in this.cornices) { if (this.cornices.hasOwnProperty(id)) { sum += this.cornices[id].getSquare(); } } return sum; }; House.prototype.getDoorsSquare = function() { var sum = 0; for (var id in this.apertures.doors) { if (this.apertures.doors.hasOwnProperty(id)) { sum += this.apertures.doors[id].getSquare(); } } return sum; }; House.prototype.getHProfilesCount = function() { var sum = 0; var wall; for (var id in this.walls) { if (this.walls.hasOwnProperty(id)) { wall = this.walls[id]; //noinspection MagicNumberJS sum += Math.floor(wall.width / 3.6) * wall.height * wall.count / 3; } } return Math.ceil(sum); }; House.prototype.getJFacetCount = function() { var sum = 0; var cornice; for (var id in this.cornices) { if (this.cornices.hasOwnProperty(id)) { cornice = this.cornices[id]; sum += cornice.length * cornice.count / 3; } } return Math.ceil(sum); }; House.prototype.getInnerCornersCount = function() { var sum = 0; for (var id in this.corners.inner) { if (this.corners.inner.hasOwnProperty(id)) { sum += this.corners.inner[id].getCount(); } } return Math.ceil(sum); }; House.prototype.getOuterCornersCount = function() { var sum = 0; for (var id in this.corners.outer) { if (this.corners.outer.hasOwnProperty(id)) { sum += this.corners.outer[id].getCount(); } } return Math.ceil(sum); }; House.prototype.getPanelsFinishPlanksCount = function() { var wallsSum = 0; var pedimentsSum = 0; var item; var id; for (id in this.walls) { if (this.walls.hasOwnProperty(id)) { item = this.walls[id]; wallsSum += item.width * item.count; } } for (id in this.pediments) { if (this.pediments.hasOwnProperty(id)) { item = this.pediments[id]; pedimentsSum += item.width * item.count; } } //noinspection MagicNumberJS return Math.ceil(1.1 * (wallsSum - pedimentsSum) / 3); }; House.prototype.getPedimentsJProfilesCount = function() { var sum = 0; var item; var sqrt; for (var id in this.pediments) { if (this.pediments.hasOwnProperty(id)) { item = this.pediments[id]; //noinspection MagicNumberJS sqrt = Math.sqrt(0.25 * Math.pow(item.width, 2) + Math.pow(item.height, 2)); sum += 2 * sqrt * item.count; } } return Math.ceil(sum / 3); }; House.prototype.getPedimentsSquare = function() { var sum = 0; for (var id in this.pediments) { if (this.pediments.hasOwnProperty(id)) { sum += this.pediments[id].getSquare(); } } return sum; }; House.prototype.getSiberianVinylPanelsCount = function() { //noinspection MagicNumberJS return Math.ceil(this.getTotalSquareWithoutApertures() / 0.61 * 1.1); }; House.prototype.getSoffitsCount = function() { var sum = 0; var cornice; for (var id in this.cornices) { if (this.cornices.hasOwnProperty(id)) { cornice = this.cornices[id]; //noinspection MagicNumberJS sum += cornice.width * cornice.length * cornice.count / 0.91; } } //noinspection MagicNumberJS return Math.ceil(sum * 1.1); }; House.prototype.getStartPlanksCount = function() { var sum = 0; var wall; for (var id in this.walls) { if (this.walls.hasOwnProperty(id)) { wall = this.walls[id]; sum += wall.width * wall.count; } } return Math.ceil(sum / 3); }; House.prototype.getTotalSquare = function() { return this.getWallsSquare() + this.getPedimentsSquare(); }; House.prototype.getTotalSquareWithoutApertures = function() { var square = this.getTotalSquare() - this.getAperturesSquare(); if (square > 0) { return square; } else { return 0; } }; House.prototype.getVinylPanelsCount = function() { //noinspection MagicNumberJS return Math.ceil(this.getTotalSquareWithoutApertures() / 0.81 * 1.1); }; House.prototype.getWallsSquare = function() { var sum = 0; for (var id in this.walls) { if (this.walls.hasOwnProperty(id)) { sum += this.walls[id].getSquare(); } } return sum; }; House.prototype.getWideJProfilesCount = function() { var sum = 0; var door; for (var id in this.apertures.doors) { if (this.apertures.doors.hasOwnProperty(id)) { door = this.apertures.doors[id]; sum += (door.height * 2 + door.width) * door.count / 3; } } return Math.ceil(sum); }; House.prototype.getWindowsFinishPlanksCount = function() { var sum = 0; var w; for (var id in this.apertures.windows) { if (this.apertures.windows.hasOwnProperty(id)) { w = this.apertures.windows[id]; sum += 2 * (w.height + w.width) * w.count; } } return Math.ceil(sum / 3); }; House.prototype.getWindowsPlanksCount = function() { var sum = 0; var w; for (var id in this.apertures.windows) { if (this.apertures.windows.hasOwnProperty(id)) { w = this.apertures.windows[id]; //noinspection MagicNumberJS sum += (w.height * 2 + w.width * 2 + 0.4) * w.count / 3; } } return Math.ceil(sum); }; House.prototype.getWindowsSquare = function() { var sum = 0; for (var id in this.apertures.windows) { if (this.apertures.windows.hasOwnProperty(id)) { sum += this.apertures.windows[id].getSquare(); } } return sum; }; function Corner(height, count) { this.height = height; this.count = count; } Corner.prototype.getCount = function() { return this.height / 3 * this.count; }; function Line(width, length, count) { this.width = width; this.length = length; this.count = count; } Line.prototype.getSquare = function() { return this.length * this.width * this.count; }; function Rectangle(height, width, count) { this.height = height; this.width = width; this.count = count; } Rectangle.prototype.getSquare = function() { return this.height * this.width * this.count; }; function RectangleHalf(height, width, count) { this.height = height; this.width = width; this.count = count; } RectangleHalf.prototype.getSquare = function() { return this.height * this.width * this.count / 2; }; var model = new House();