Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
belongs-line
(version: 0)
Comparing performance of:
belongsToRectangle vs belongsToInfiniteLine vs belongsToInfiniteLine_fixed
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var x = 490; var y = 334; var from = { x: 320, y: 160 } var to = { x: 640, y: 480 } function belongsToRectangle(point, rectangle) { const from = { x: rectangle.x - 0.5*rectangle.width, y: rectangle.y - 0.5*rectangle.height }; const to = { x: from.x + rectangle.width, y: from.y + rectangle.height }; return (from.x <= point.x) && (point.x <= to.x) && (from.y <= point.y) && (point.y <= to.y); } function belongsToInfiniteLine(point, from, to) { const distance = (to.x - from.x)*(point.y - from.y) - (to.y - from.y)*(point.x - from.x); return Math.abs(distance) < 1000; }
Tests:
belongsToRectangle
const rectangle = { x: 0.5*(from.x + to.x), y: 0.5*(from.y + to.y), width: Math.max(Math.abs(from.x - to.x), 10), height: Math.max(Math.abs(from.y - to.y), 10), }; belongsToRectangle({ x, y }, rectangle);
belongsToInfiniteLine
const rectangle = { x: 0.5*(from.x + to.x), y: 0.5*(from.y + to.y), width: Math.max(Math.abs(from.x - to.x), 10), height: Math.max(Math.abs(from.y - to.y), 10), }; belongsToInfiniteLine({ x, y }, from, to);
belongsToInfiniteLine_fixed
belongsToInfiniteLine({ x, y }, from, to);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
belongsToRectangle
belongsToInfiniteLine
belongsToInfiniteLine_fixed
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
path2d-vs-math
Canvas cache or Path 2D (updated++)
path2d-vs-math-no-function-overhead
pointDistance vs rectDistance
Comments
Confirm delete:
Do you really want to delete benchmark?