Coder Social home page Coder Social logo

Interpolator issue about kinetic HOT 1 CLOSED

omarojo avatar omarojo commented on June 16, 2024
Interpolator issue

from kinetic.

Comments (1)

u10int avatar u10int commented on June 16, 2024

The issue is because you're comparing floating point values which doesn't always work as expected due to precision of floats and doubles and small rounding errors that's not apparent when outputting one of these values as a string which uses less precision. This is a common programming concern that's not specific to Swift. You can observe this by outputting the values differently:

let duration = 5.0
let start = 0.2
let end = 0.9

start.interpolator(to: end, duration: duration*0.5, function: Easing.type(.sineIn)) { (value) in
	print("\(value), string: \(String(format: "%.20f", value)), end: \(String(format: "%.20f", end))")
	print(value == end)
	
	if value == end { //reverse
		end.interpolator(to: start, duration: duration*0.5, function: Easing.type(.backIn)) { (value) in
			print("\(value)")
		}.run()
	}
}.run()

Here's more info:

https://stackoverflow.com/a/43911753
https://stackoverflow.com/questions/43236212/surprising-difference-for-floating-point-arrithmetic-for-double-vs-float
http://www.floating-point-gui.de/errors/comparison/

The solution would be to explicitly provide the type for start and end as floats:

let start: Float = 0.2
let end: Float = 0.9

Also, to help resolve this, I've updated the library to add Float as an interpolatable type which works as expected alongside using the above change.

from kinetic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.