Skip to content

Commit

Permalink
docs(): added docs to findScaleToFit and findScaleToCover
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur committed Feb 15, 2020
1 parent f7e8069 commit d3c4959
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/util/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,36 @@
return Math.max(min, Math.min(value, max));
},

/**
* Finds the scale for the object source to fit inside the object destination,
* keeping aspect ratio intact.
* respect the total allowed area for the cache.
* @memberOf fabric.util
* @param {Object | fabric.Object} source
* @param {Number} source.height natural unscaled height of the object
* @param {Number} source.width natural unscaled width of the object
* @param {Object | fabric.Object} destination
* @param {Number} destination.height natural unscaled height of the object
* @param {Number} destination.width natural unscaled width of the object
* @return {Number} scale factor to apply to source to fit into destination
*/
findScaleToFit: function(source, destination) {
return Math.min(destination.width / source.width, destination.height / source.height);
},

/**
* Finds the scale for the object source to cover entirely the object destination,
* keeping aspect ratio intact.
* respect the total allowed area for the cache.
* @memberOf fabric.util
* @param {Object | fabric.Object} source
* @param {Number} source.height natural unscaled height of the object
* @param {Number} source.width natural unscaled width of the object
* @param {Object | fabric.Object} destination
* @param {Number} destination.height natural unscaled height of the object
* @param {Number} destination.width natural unscaled width of the object
* @return {Number} scale factor to apply to source to cover destination
*/
findScaleToCover: function(source, destination) {
return Math.max(destination.width / source.width, destination.height / source.height);
},
Expand Down

0 comments on commit d3c4959

Please sign in to comment.