-
Notifications
You must be signed in to change notification settings - Fork 70
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
interpolateNumberArray #77
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb34407
interpolateNumberArray
Fil df8daef
style
Fil 333f98d
var not let
Fil 5a32b88
exact ends for interpolateNumberArray
Fil 9669bad
don't switch arrays of numbers from interpolateArray to interpolateNu…
Fil 24d1dea
Update numberArray.js
mbostock ba015f0
Update array.js
mbostock d211ea7
Avoid redundant isNumberArray call.
mbostock 92e0bc7
examples notebook
Fil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function(a, b) { | ||
if (!b) b = []; | ||
var n = a ? Math.min(b.length, a.length) : 0, | ||
c = b.slice(), | ||
i; | ||
return function(t) { | ||
for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t; | ||
return c; | ||
}; | ||
} | ||
|
||
export function isNumberArray(x) { | ||
return ArrayBuffer.isView(x) && !(x instanceof DataView); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var tape = require("tape"), | ||
interpolate = require("../"); | ||
|
||
tape("interpolateNumberArray(a, b) interpolates defined elements in a and b", function(test) { | ||
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float64Array.of(4, 24))(0.5), Float64Array.of(3, 18)); | ||
test.end(); | ||
}); | ||
|
||
tape("interpolateNumberArray(a, b) ignores elements in a that are not in b", function(test) { | ||
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.of(2, 12, 12), Float64Array.of(4, 24))(0.5), Float64Array.of(3, 18)); | ||
test.end(); | ||
}); | ||
|
||
tape("interpolateNumberArray(a, b) uses constant elements in b that are not in a", function(test) { | ||
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float64Array.of(4, 24, 12))(0.5), Float64Array.of(3, 18, 12)); | ||
test.end(); | ||
}); | ||
|
||
tape("interpolateNumberArray(a, b) treats undefined as an empty array", function(test) { | ||
test.deepEqual(interpolate.interpolateNumberArray(undefined, [2, 12])(0.5), [2, 12]); | ||
test.deepEqual(interpolate.interpolateNumberArray([2, 12], undefined)(0.5), []); | ||
test.deepEqual(interpolate.interpolateNumberArray(undefined, undefined)(0.5), []); | ||
test.end(); | ||
}); | ||
|
||
tape("interpolateNumberArray(a, b) uses b’s array type", function(test) { | ||
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float64Array.of(4, 24, 12))(0.5) instanceof Float64Array); | ||
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float32Array.of(4, 24, 12))(0.5) instanceof Float32Array); | ||
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Uint8Array.of(4, 24, 12))(0.5) instanceof Uint8Array); | ||
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Uint16Array.of(4, 24, 12))(0.5) instanceof Uint16Array); | ||
test.end(); | ||
}); | ||
|
||
tape("interpolateNumberArray(a, b) works with unsigned data", function(test) { | ||
test.deepEqual(interpolate.interpolateNumberArray(Uint8Array.of(1, 12), Uint8Array.of(255, 0))(0.5), Uint8Array.of(128, 6)); | ||
test.end(); | ||
}); | ||
|
||
tape("interpolateNumberArray(a, b) gives exact ends", function(test) { | ||
var i = interpolate.interpolateNumberArray(Float64Array.of(2e42), Float64Array.of(355)); | ||
test.deepEqual(i(0), Float64Array.of(2e42)); | ||
test.deepEqual(i(1), Float64Array.of(355)); | ||
test.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Just wanted to flag that
typeof ArrayBuffer.isView === 'undefined'
in PhantomJS. I know it's a super old browser and I'm not really expecting D3 to be perfectly compatible with it, but just commenting here in case someone else gets the same error. Thanks!re: openstreetmap/iD#7072 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could test for it?
return ArrayBuffer.isView && ArrayBuffer.isView(x) && !(x instanceof DataView);