Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed setCropzoneRect floating point bug (fix #114) #301

Merged
merged 2 commits into from
Jan 17, 2020

Conversation

jinwoo-kim-nhn
Copy link
Contributor

@jinwoo-kim-nhn jinwoo-kim-nhn commented Jan 15, 2020

Please check if the PR fulfills these requirements

  • It's submitted to right branch according to our branching model
  • It's right issue type on title
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • It does not introduce a breaking change or has description for the breaking change

Description

issue

원인

  • 원본 이미지의 크기에 맞게 16 : 9 의 비율값을 이용하여 cropzone 크기 계산시 부동 소수점 계산 오차에 의해 width값에 +0.00000000003 의 오차가 생김
  • (보통의 경우에 미세한 오차는 큰 상관이 없음 하지만 아래와 같은 경우에 문제가 생김)
  • width값 오차로 인해 left 값 계산시 left = (originalWidth - width) / 2 또한 오차가 생기고 left가 마이너스 값이 되면서 캔버스 유효 범위를 벗어나게됨.

해결

  • 부동 소수점 오차를 해결하기 위해 width, height 최종 결과값에 소수점 2 번째 자리에서 반올림 하여 0.00000000003의 오차를 해결 (오차 해결방식은 fabricjs 코드를 참고함)
  • width, height 값만 정확하면 그에 따른 left, top 값은 부동소수점 오차가 있어도 isValid 값에 영향을 받지 않게 되는 값을 갖게 되므로 문제가 없게됨

Thank you for your contribution to TOAST UI product. 🎉 😘 ✨

@jinwoo-kim-nhn jinwoo-kim-nhn changed the title fix: fixed setCropzoneRect floating point bug fix: fixed setCropzoneRect floating point bug (fix #114) Jan 16, 2020
Copy link
Member

@junghwan-park junghwan-park left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료입니다!!

@dongsik-yoo
Copy link
Contributor

수고 많으셨습니다.

@jinwoo-kim-nhn jinwoo-kim-nhn merged commit fc06ef4 into master Jan 17, 2020
@jinwoo-kim-nhn jinwoo-kim-nhn deleted the fix/setCropzoneRectFloatigPointBug branch March 20, 2020 08:13
HerlinMatos pushed a commit to EveryMundo/tui.image-editor that referenced this pull request Jul 2, 2020
* fix: fixed setCropzoneRect floating point bug

* added jsdoc for new util function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants