Triangle Clipping Challenge remix

410
0
2017-07-16に共有
Not sure I'm following all the rules here. I didn't implement the "res"-parameter and it's not faster, but it was fun. Also, I'm not dividing the filled area into smaller triangle, just chopping on the original (one/two) triangle(s).

Thanks to @gtoal (and @chooper-beta) for the challenge!
# Original Text:
Clips triangles to a given rectangle

The clipped triangle is made by the division of the original triangle into smaller ones

Credit to @TheLogFather for his hybrid triangle filler I used

CHALLENGE:
Can you make a faster clipping algorithm that satisfies all the tests?
Have a go, and if you can make an algorithm faster than the one shown here, I'll give you a follow from @chooper100 (or something equivalent)

RULES:
You must provide 2 blocks:
- fill triangle (Ax) (Ay) (Bx) (By) (Cx) (Cy) res (res)
- clip and fill triangle (Ax) (Ay) (Bx) (By) (Cx) (Cy) res (res)
The testing code must not be changed
The outline of the original triangle and the clipping area must also be visible and they must be easy to distinguish from the clipped triangle
You may change the algorithm used to draw triangles if you have a more efficient algorithm
You may also remove the "Triangles Drawn" variable. The "Test Time" variable must be kept however