<commit_before>#pragma once
#include "shape.h"
#include "bezier.h"
//曲线的类型
enum class CurveType
{
    FLAT
};

//完整的曲线
struct CurveCommon
{
  public:
    const CubicBezier bezier;
    const Float width[2];
    const CurveType type;

  public:
    CurveCommon(const CubicBezier &bezier, Float w0, Float w1, CurveType type) : bezier(bezier), width{w0, w1}, type(type) {}
    CurveCommon(const Point3f p[4], Float w0, Float w1, CurveType type) : bezier(CubicBezier(p)), width{w0, w1}, type(type) {}
    CurveCommon(const Point3f &p0, const Point3f &p1, const Point3f &p2, const Point3f &p3, Float w0, Float w1, CurveType type) : bezier(CubicBezier(p0, p1, p2, p3)), width{w0, w1}, type(type) {}
};

class Curve : public Shape
{
  private:
    const std::shared_ptr<CurveCommon> _common;
    const Float _uMin;
    const Float _uMax;

    bool RecursiveIntersect(const Ray& ray,Float *tHit, SurfaceInteraction *surfaceInsect,const Point3f cp[4],const Transform& rayToObject,Float u0,Float u1,int depth) const{
        return false;
    }
  public:
    Curve(const Transform *objectToWorld, const Transform *worldToObject,
          bool reverseOrientation, const std::shared_ptr<CurveCommon> &common, Float uMin, Float uMax)
        : Shape(objectToWorld, worldToObject, reverseOrientation), _common(common), _uMin(uMin), _uMax(uMax)
    {
        Assert(_uMin >= 0);
        Assert(_uMax <= 1);
    }

    virtual Bound3f ObjectBound() const override
    {
        //先计算当前曲线的4个控制点
        Point3f cp[4] = {Blossom(_common->bezier, _uMin, _uMin, _uMin), Blossom(_common->bezier, _uMin, _uMin, _uMax), Blossom(_common->bezier, _uMin, _uMax, _uMax), Blossom(_common->bezier, _uMax, _uMax, _uMax)};
        //计算不考虑width情况下的Bound
        auto bound = Union(Bound3f(cp[0], cp[1]), Bound3f(cp[2], cp[3]));
        //计算参数范围内最大的宽度
        Float w0 = Lerp(_uMin, _common->width[0], _common->width[1]);
        Float w1 = Lerp(_uMax, _common->width[0], _common->width[1]);
        Float w = std::max(w0, w1);
        //扩大bound,获得保守的bound
        bound = Expand(bound, w * (Float)0.5);
        return bound;
    }

    virtual Float Area() const override<commit_msg>上传一些Curve的代码<commit_after>#pragma once
#include "shape.h"
#include "bezier.h"
//曲线的类型
enum class CurveType
{
    FLAT
};

//完整的曲线
struct CurveCommon
{
  public:
    const CubicBezier bezier;
    const Float width[2];
    const CurveType type;

  public:
    CurveCommon(const CubicBezier &bezier, Float w0, Float w1, CurveType type) : bezier(bezier), width{w0, w1}, type(type) {}
    CurveCommon(const Point3f p[4], Float w0, Float w1, CurveType type) : bezier(CubicBezier(p)), width{w0, w1}, type(type) {}
    CurveCommon(const Point3f &p0, const Point3f &p1, const Point3f &p2, const Point3f &p3, Float w0, Float w1, CurveType type) : bezier(CubicBezier(p0, p1, p2, p3)), width{w0, w1}, type(type) {}
};

class Curve : public Shape
{
  private:
    const std::shared_ptr<CurveCommon> _common;
    const Float _uMin;
    const Float _uMax;

    bool RecursiveIntersect(const Ray& ray,Float *tHit, SurfaceInteraction *surfaceInsect,const Point3f cp[4],const Transform& rayToObject,Float u0,Float u1,int depth) const{
        //计算Ray空间的curve bound
        auto curveBound = Union(Bound3f(cp[0], cp[1]), Bound3f(cp[2], cp[3]));
        //计算最大的width
        Float w0 = Lerp(u0, _common->width[0], _common->width[1]);
        Float w1 = Lerp(u1, _common->width[0], _common->width[1]);
        Float w = std::max(w0, w1);
        //扩大bound,获得保守的bound
        curveBound = Expand(curveBound, w * (Float)0.5);

        //计算Ray空间下的Ray的bound
        Float zMax=ray.d.Length()*ray.tMax;
        Bound3f rayBound(Point3f(0,0,0),Point3f(0,0,zMax));

        //判断rayBound和curveBound是否相交
        if(Overlap(rayBound,curveBound)==false){
            return false;
        }
        //到这里，已经和现在的bound相交了，所以要开始迭代的判断子curve是否相交，
        //直到深度为0的时候，再判断是都和实际的curve相交
        if(depth>0){
            //迭代
           
        }
        else{
            //相交测试
             return true;
        }
       
    }
  public:
    Curve(const Transform *objectToWorld, const Transform *worldToObject,
          bool reverseOrientation, const std::shared_ptr<CurveCommon> &common, Float uMin, Float uMax)
        : Shape(objectToWorld, worldToObject, reverseOrientation), _common(common), _uMin(uMin), _uMax(uMax)
    {
        Assert(_uMin >= 0);
        Assert(_uMax <= 1);
    }

    virtual Bound3f ObjectBound() const override
    {
        //先计算当前曲线的4个控制点
        Point3f cp[4] = {Blossom(_common->bezier, _uMin, _uMin, _uMin), Blossom(_common->bezier, _uMin, _uMin, _uMax), Blossom(_common->bezier, _uMin, _uMax, _uMax), Blossom(_common->bezier, _uMax, _uMax, _uMax)};
        //计算不考虑width情况下的Bound
        auto bound = Union(Bound3f(cp[0], cp[1]), Bound3f(cp[2], cp[3]));
        //计算参数范围内最大的宽度
        Float w0 = Lerp(_uMin, _common->width[0], _common->width[1]);
        Float w1 = Lerp(_uMax, _common->width[0], _common->width[1]);
        Float w = std::max(w0, w1);
        //扩大bound,获得保守的bound
        bound = Expand(bound, w * (Float)0.5);
        return bound;
    }

    virtual Float Area() const override
{'fraction_non_alphanumeric': 0.1335017489312087, 'fraction_numerical': 0.026039642440730666, 'mean_word_length': 3.2119476268412437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1956367', 'n_tokens_mistral': 2014, 'n_tokens_neox': 2024, 'n_words': 424}