-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* projection: Implement depth ordering and face culling * grouping: Fix missing scope export * tests: Update refs * polygon: Move polygon rel. fn's to new file * shapes: Make shapes CCW by default * tests: Update refs * Changelog * PR Fixes
- Loading branch information
1 parent
035a667
commit 7141c4e
Showing
22 changed files
with
232 additions
and
48 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
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,61 @@ | ||
/// Returns a list of polygon points from | ||
/// a list of segments. | ||
/// | ||
/// Cubic segments get linearized by sampling. | ||
/// | ||
/// - segment (array): List of segments | ||
/// - samples (int): Number of samples | ||
/// -> array | ||
#let from-segments(segments, samples: 10) = { | ||
import "/src/bezier.typ": cubic-point | ||
let poly = () | ||
for ((kind, ..pts)) in segments { | ||
if kind == "cubic" { | ||
poly += range(0, samples).map(t => { | ||
cubic-point(..pts, t / (samples - 1)) | ||
}) | ||
} else { | ||
poly += pts | ||
} | ||
} | ||
return poly | ||
} | ||
|
||
/// Computes the signed area of a 2D polygon. | ||
/// | ||
/// The formula used is the following: | ||
/// $ 1/2 \sum_{i}=0^{n-1} x_i*y_i+1 - x_i+1*y_i $ | ||
/// | ||
/// - points (array): List of Vectors of dimension >= 2 | ||
/// -> float | ||
#let signed-area(points) = { | ||
let a = 0 | ||
let n = points.len() | ||
let (cx, cy) = (0, 0) | ||
for i in range(0, n) { | ||
let (x0, y0, ..) = points.at(i) | ||
let (x1, y1, ..) = points.at(calc.rem(i + 1, n)) | ||
cx += (x0 + x1) * (x0 * y1 - x1 * y0) | ||
cy += (y0 + y1) * (x0 * y1 - x1 * y0) | ||
a += x0 * y1 - x1 * y0 | ||
} | ||
return .5 * a | ||
} | ||
|
||
/// Returns the winding order of a 2D polygon | ||
/// by using it's signed area. | ||
/// | ||
/// Returns either "ccw" (counter clock-wise) or "cw" (clock-wise) or none. | ||
/// | ||
/// - point (array): List of polygon points | ||
/// -> str,none | ||
#let winding-order(points) = { | ||
let area = signed-area(points) | ||
if area > 0 { | ||
"cw" | ||
} else if area < 0 { | ||
"ccw" | ||
} else { | ||
none | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.