better shortcut detection, improves polygon test
This commit is contained in:
parent
71766a16f4
commit
7225883aa9
2 changed files with 24 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
import chroma, common, system/memory, vmath
|
import bumpy, chroma, common, system/memory, vmath
|
||||||
|
|
||||||
const allowSimd* = not defined(pixieNoSimd) and not defined(tcc)
|
const allowSimd* = not defined(pixieNoSimd) and not defined(tcc)
|
||||||
|
|
||||||
|
@ -51,6 +51,20 @@ proc `*`*(color: ColorRGBX, opacity: float32): ColorRGBX {.raises: [].} =
|
||||||
a = ((color.a * x) div 255).uint8
|
a = ((color.a * x) div 255).uint8
|
||||||
rgbx(r, g, b, a)
|
rgbx(r, g, b, a)
|
||||||
|
|
||||||
|
proc intersectsInside*(a, b: Segment, at: var Vec2): bool {.inline.} =
|
||||||
|
## Checks if the a segment intersects b segment (excluding endpoints).
|
||||||
|
## If it returns true, at will have point of intersection
|
||||||
|
let
|
||||||
|
s1 = a.to - a.at
|
||||||
|
s2 = b.to - b.at
|
||||||
|
denominator = (-s2.x * s1.y + s1.x * s2.y)
|
||||||
|
s = (-s1.y * (a.at.x - b.at.x) + s1.x * (a.at.y - b.at.y)) / denominator
|
||||||
|
t = (s2.x * (a.at.y - b.at.y) - s2.y * (a.at.x - b.at.x)) / denominator
|
||||||
|
|
||||||
|
if s > 0 and s < 1 and t > 0 and t < 1:
|
||||||
|
at = a.at + (t * s1)
|
||||||
|
return true
|
||||||
|
|
||||||
proc fillUnsafe*(
|
proc fillUnsafe*(
|
||||||
data: var seq[uint8], value: uint8, start, len: int
|
data: var seq[uint8], value: uint8, start, len: int
|
||||||
) {.inline, raises: [].} =
|
) {.inline, raises: [].} =
|
||||||
|
|
|
@ -1205,7 +1205,7 @@ proc partitionSegments(
|
||||||
entry0 = partition.entries[0].segment
|
entry0 = partition.entries[0].segment
|
||||||
entry1 = partition.entries[1].segment
|
entry1 = partition.entries[1].segment
|
||||||
var at: Vec2
|
var at: Vec2
|
||||||
if not intersects(entry0, entry1, at):
|
if not intersectsInside(entry0, entry1, at):
|
||||||
# These two segments do not intersect, enable shortcut
|
# These two segments do not intersect, enable shortcut
|
||||||
partition.twoNonintersectingSpanningSegments = true
|
partition.twoNonintersectingSpanningSegments = true
|
||||||
# Ensure entry[0] is on the left
|
# Ensure entry[0] is on the left
|
||||||
|
@ -1916,7 +1916,7 @@ proc fillShapes(
|
||||||
|
|
||||||
if allEntriesInScanlineSpanIt and tmp == 2:
|
if allEntriesInScanlineSpanIt and tmp == 2:
|
||||||
var at: Vec2
|
var at: Vec2
|
||||||
if not intersects(
|
if not intersectsInside(
|
||||||
partitions[partitionIndex].entries[entryIndices[0]].segment,
|
partitions[partitionIndex].entries[entryIndices[0]].segment,
|
||||||
partitions[partitionIndex].entries[entryIndices[1]].segment,
|
partitions[partitionIndex].entries[entryIndices[1]].segment,
|
||||||
at
|
at
|
||||||
|
@ -1925,9 +1925,13 @@ proc fillShapes(
|
||||||
var
|
var
|
||||||
left = partitions[partitionIndex].entries[entryIndices[0]]
|
left = partitions[partitionIndex].entries[entryIndices[0]]
|
||||||
right = partitions[partitionIndex].entries[entryIndices[1]]
|
right = partitions[partitionIndex].entries[entryIndices[1]]
|
||||||
# Ensure left is on the left
|
block:
|
||||||
if left.segment.at.x > right.segment.at.x:
|
# Ensure left is actually on the left
|
||||||
swap left, right
|
let
|
||||||
|
maybeLeftMaxX = max(left.segment.at.x, left.segment.to.x)
|
||||||
|
maybeRightMaxX = max(right.segment.at.x, right.segment.to.x)
|
||||||
|
if maybeLeftMaxX > maybeRightMaxX:
|
||||||
|
swap left, right
|
||||||
|
|
||||||
let requiresAntiAliasing =
|
let requiresAntiAliasing =
|
||||||
left.segment.requiresAntiAliasing or
|
left.segment.requiresAntiAliasing or
|
||||||
|
|
Loading…
Reference in a new issue