-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intersection: Provide sort functions
- Loading branch information
1 parent
d717502
commit 13793f0
Showing
5 changed files
with
63 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#import "/src/vector.typ" | ||
#import "/src/util.typ" | ||
|
||
/// Sort list of points by distance to a | ||
/// reference point. | ||
/// | ||
/// - points (array): List of points to sort | ||
/// - reference (vec): Reference point | ||
/// -> List of points | ||
#let points-by-distance(ctx, points, reference: (0, 0, 0)) = { | ||
let reference = util.apply-transform(ctx.transform, reference) | ||
return points.sorted(key: pt => { | ||
vector.dist(pt, reference) | ||
}) | ||
} | ||
|
||
/// Sort list of 2D points by angle to a | ||
/// reference 2D point in CCW order. | ||
/// Z component is ignored. | ||
/// | ||
/// - points (array): List of points to sort | ||
/// - reference (vec): Reference point | ||
/// -> List of points | ||
#let points-by-angle(ctx, points, reference: (0, 0, 0)) = { | ||
let (rx, ry, ..) = util.apply-transform(ctx.transform, reference) | ||
return points.sorted(key: ((px, py, ..)) => { | ||
360deg - calc.atan2(rx - px, ry - py) | ||
}) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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