feat(Graphics): add `fitScale` function

Open Beginner friendly
#25 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
fsharp

Research direction

Start from the proposed fitScale definition and the commented Assert.equal example in issue #25. Locate the project entry point for the Size-related graphics code, add the function there, and run the project tests; done means the shown 4×3 image in a 3×4 viewport satisfies the asserted result.

Written by the indexing model from the issue text.

Description

good first issue
/// Вычисляет коэффициент масштаба, необходимый, чтобы вписать изображение в указанную область
let fitScale (viewportSize: Size) (imageSize: Size) =
    let dw = imageSize.Width - viewportSize.Width
    let dh = imageSize.Height - viewportSize.Height

    if dw > dh then
        if dw > 0 then
            float viewportSize.Width / float imageSize.Width
        else
            1.0
    else
        if dh > 0 then
            float viewportSize.Height / float imageSize.Height
        else
            1.0

// Assert.equal
//     (
//         let imageSize = Size.create 4 3
//         let scale = fitScale (Size.create 3 4) imageSize
//         imageSize * scale
//     )
//     (Size.create 3 2)
//     ""
Dominant language
F#
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gretmn102/FsharpMyExtension

All issues in gretmn102/FsharpMyExtension

Similar issues

More Computer Graphics issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.