diff options
Diffstat (limited to 'src/bezier.cpp')
-rw-r--r-- | src/bezier.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/bezier.cpp b/src/bezier.cpp index 6bb1541..1585495 100644 --- a/src/bezier.cpp +++ b/src/bezier.cpp @@ -34,6 +34,48 @@ Bezier_SolveYForX(v2 Point_P0, v2 Point_P1, v2 Point_P2, v2 Point_P3, real32 Tar return Y; } +// TODO(fox): Incorporate sorting for non-continuous shapes. +static uint32 +Bezier_Shape_Sort(memory *Memory, shape_layer *Shape, bezier_point *PointData) +{ + real32 Radius = Shape->Opt.Roundness; + bezier_point *PointStart = PointData; + for (int i = 0; i < Shape->Point_Count; i++) { + bezier_point *Point = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, i, 1); + if (Radius <= 0 && Point->Type == interpolation_type_linear) { + v2 Pos = Point->Pos[0]; + int Index_Prev = (i != 0) ? i-1 : Shape->Point_Count-1; + int Index_Next = (i != Shape->Point_Count-1) ? i+1 : 0; + v2 Pos_Prev = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, Index_Prev, 1)->Pos[0]; + v2 Pos_Next = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, Index_Next, 1)->Pos[0]; + v2 Vector_Prev = Pos - Pos_Prev; + v2 Vector_Next = Pos - Pos_Next; + real32 Length_Prev = sqrtf(LengthSq(Vector_Prev)); + real32 Length_Next = sqrtf(LengthSq(Vector_Next)); + + // real32 RadAngle = acos(Inner(Vector_Prev, VectorR) / (LengthL * LengthR)) * PI / 180; + // real32 AngleKappa = (4.f/3) * tan(RadAngle * 1/4); + + real32 Ratio_Prev = Radius / Length_Prev; + real32 Ratio_Prev_Inv = 1.0f - Ratio_Prev; + + real32 Ratio_Next = Radius / Length_Next; + real32 Ratio_Next_Inv = 1.0f - Ratio_Next; + + v2 Point_1 = Pos_Prev + V2(Vector_Prev.x * Ratio_Prev_Inv, (Vector_Prev.y * Ratio_Prev_Inv)); + v2 Point_2 = Vector_Prev * Ratio_Prev * (1-KAPPA); + v2 Point_3 = Pos_Next + V2(Vector_Next.x * Ratio_Next_Inv, Vector_Next.y * Ratio_Next_Inv); + v2 Point_4 = Vector_Next * Ratio_Next * (1-KAPPA); + + *PointData++ = { 1, { Point_1, Point_2, V2(0, 0) }, interpolation_type_bezier, 0 }; + *PointData++ = { 1, { Point_3, V2(0, 0), Point_4 }, interpolation_type_bezier, 0 }; + } else { + *PointData++ = *Point; + } + } + return PointData - PointStart; +} + static bezier_point * Bezier_LookupAddress(memory *Memory, uint16 *Block_Bezier_Index, uint16 Index, bool32 AssertExists) { |