<commit_before>/*++

Copyright (c) 2020 <NAME>

Module Name:

    product_texture.c

Abstract:

    Allocates a product texture.

--*/

#include <stdalign.h>
#include <stdlib.h>

#include "iris_physx_toolkit/product_texture.h"

//
// Types
//

typedef struct _PRODUCT_FLOAT_TEXTURE {
    PFLOAT_TEXTURE multiplicand0;
    PFLOAT_TEXTURE multiplicand1;
} PRODUCT_FLOAT_TEXTURE, *PPRODUCT_FLOAT_TEXTURE;

typedef const PRODUCT_FLOAT_TEXTURE *PCPRODUCT_FLOAT_TEXTURE;

//
// Static Functions
//

static
ISTATUS
ProductFloatTextureSample(
    _In_ const void *context,
    _In_ POINT3 model_hit_point,
    _In_ const void *additional_data,
    _In_ const void *texture_coordinates,
    _Out_ float_t *value
    )
{
    PPRODUCT_FLOAT_TEXTURE texture = (PPRODUCT_FLOAT_TEXTURE)context;

    float_t multiplicand;
    ISTATUS status = FloatTextureSample(texture->multiplicand0,
                                        model_hit_point,
                                        additional_data,
                                        texture_coordinates,
                                        &multiplicand);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    status = FloatTextureSample(texture->multiplicand0,
                                model_hit_point,
                                additional_data,
                                texture_coordinates,
                                value);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    *value *= multiplicand;

    return ISTATUS_SUCCESS;
}

static
void
ProductFloatTextureFree(
    _In_opt_ _Post_invalid_ void *context
    )
{
    PPRODUCT_FLOAT_TEXTURE texture = (PPRODUCT_FLOAT_TEXTURE)context;
    FloatTextureRelease(texture->multiplicand0);
    FloatTextureRelease(texture->multiplicand1);
}

//
// Static Variables
//

static const FLOAT_TEXTURE_VTABLE product_float_texture_vtable = {
    ProductFloatTextureSample,
    ProductFloatTextureFree
};

//
// Functions
//

ISTATUS
ProductFloatTextureAllocate(
    _In_ PFLOAT_TEXTURE multiplicand0,
    _In_ PFLOAT_TEXTURE multiplicand1,
    _Out_ PFLOAT_TEXTURE *product
    )
{
    if (multiplicand0 == NULL)
    {
        return ISTATUS_INVALID_ARGUMENT_00;
    }

    if (multiplicand1 == NULL)
    {
        return ISTATUS_INVALID_ARGUMENT_01;
    }

    if (product == NULL)
    {
        return ISTATUS_INVALID_ARGUMENT_02;
    }

    PRODUCT_FLOAT_TEXTURE product_texture;
    product_texture.multiplicand0 = multiplicand0;
    product_texture.multiplicand1 = multiplicand1;

    ISTATUS status  = FloatTextureAllocate(&product_float_texture_vtable,
                                           &product_texture,
                                           sizeof(PRODUCT_FLOAT_TEXTURE),
                                           alignof(PRODUCT_FLOAT_TEXTURE),
                                           product);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    FloatTextureRetain(multiplicand0);
    FloatTextureRetain(multiplicand1);

    return status;
}

//
// Types
//

typedef struct _PRODUCT_REFLECTOR_TEXTURE {
    PREFLECTOR_TEXTURE multiplicand0;
    PREFLECTOR_TEXTURE multiplicand1;
} PRODUCT_REFLECTOR_TEXTURE, *PPRODUCT_REFLECTOR_TEXTURE;

typedef const PRODUCT_REFLECTOR_TEXTURE *PCPRODUCT_REFLECTOR_TEXTURE;

//
// Static Functions
//

static
ISTATUS
ProductReflectorTextureSample(
    _In_ const void *context,
    _In_ POINT3 model_hit_point,
    _In_ const void *additional_data,
    _In_ const void *texture_coordinates,
    _Inout_ PREFLECTOR_COMPOSITOR reflector_compositor,
    _Out_ PCREFLECTOR *reflector
    )
{
    PCPRODUCT_REFLECTOR_TEXTURE texture =
        (PCPRODUCT_REFLECTOR_TEXTURE)context;

    PCREFLECTOR multiplicand0;
    ISTATUS status = ReflectorTextureSample(texture->multiplicand0,
                                            model_hit_point,
                                            additional_data,
                                            texture_coordinates,
                                            reflector_compositor,
                                            &multiplicand0);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    PCREFLECTOR multiplicand1;
    status = ReflectorTextureSample(texture->multiplicand0,
                                    model_hit_point,
                                    additional_data,
                                    texture_coordinates,
                                    reflector_compositor,
                                    &multiplicand1);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    status = ReflectorCompositorMultiplyReflectors(reflector_compositor,
                                                   multiplicand0,
                                                   multiplicand1,
                                                   reflector);

    return status;
}

static
void
ProductReflectorTextureFree(
    _In_opt_ _Post_invalid_ void *context
    )
{
    PPRODUCT_REFLECTOR_TEXTURE texture = (PPRODUCT_REFLECTOR_TEXTURE)context;
    ReflectorTextureRelease(texture->multiplicand0);
    ReflectorTextureRelease(texture->multiplicand1);
}

//<commit_msg>Fix bug in product texture<commit_after>/*++

Copyright (c) 2020 <NAME>

Module Name:

    product_texture.c

Abstract:

    Allocates a product texture.

--*/

#include <stdalign.h>
#include <stdlib.h>

#include "iris_physx_toolkit/product_texture.h"

//
// Types
//

typedef struct _PRODUCT_FLOAT_TEXTURE {
    PFLOAT_TEXTURE multiplicand0;
    PFLOAT_TEXTURE multiplicand1;
} PRODUCT_FLOAT_TEXTURE, *PPRODUCT_FLOAT_TEXTURE;

typedef const PRODUCT_FLOAT_TEXTURE *PCPRODUCT_FLOAT_TEXTURE;

//
// Static Functions
//

static
ISTATUS
ProductFloatTextureSample(
    _In_ const void *context,
    _In_ POINT3 model_hit_point,
    _In_ const void *additional_data,
    _In_ const void *texture_coordinates,
    _Out_ float_t *value
    )
{
    PPRODUCT_FLOAT_TEXTURE texture = (PPRODUCT_FLOAT_TEXTURE)context;

    float_t multiplicand;
    ISTATUS status = FloatTextureSample(texture->multiplicand0,
                                        model_hit_point,
                                        additional_data,
                                        texture_coordinates,
                                        &multiplicand);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    status = FloatTextureSample(texture->multiplicand0,
                                model_hit_point,
                                additional_data,
                                texture_coordinates,
                                value);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    *value *= multiplicand;

    return ISTATUS_SUCCESS;
}

static
void
ProductFloatTextureFree(
    _In_opt_ _Post_invalid_ void *context
    )
{
    PPRODUCT_FLOAT_TEXTURE texture = (PPRODUCT_FLOAT_TEXTURE)context;
    FloatTextureRelease(texture->multiplicand0);
    FloatTextureRelease(texture->multiplicand1);
}

//
// Static Variables
//

static const FLOAT_TEXTURE_VTABLE product_float_texture_vtable = {
    ProductFloatTextureSample,
    ProductFloatTextureFree
};

//
// Functions
//

ISTATUS
ProductFloatTextureAllocate(
    _In_ PFLOAT_TEXTURE multiplicand0,
    _In_ PFLOAT_TEXTURE multiplicand1,
    _Out_ PFLOAT_TEXTURE *product
    )
{
    if (multiplicand0 == NULL)
    {
        return ISTATUS_INVALID_ARGUMENT_00;
    }

    if (multiplicand1 == NULL)
    {
        return ISTATUS_INVALID_ARGUMENT_01;
    }

    if (product == NULL)
    {
        return ISTATUS_INVALID_ARGUMENT_02;
    }

    PRODUCT_FLOAT_TEXTURE product_texture;
    product_texture.multiplicand0 = multiplicand0;
    product_texture.multiplicand1 = multiplicand1;

    ISTATUS status  = FloatTextureAllocate(&product_float_texture_vtable,
                                           &product_texture,
                                           sizeof(PRODUCT_FLOAT_TEXTURE),
                                           alignof(PRODUCT_FLOAT_TEXTURE),
                                           product);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    FloatTextureRetain(multiplicand0);
    FloatTextureRetain(multiplicand1);

    return status;
}

//
// Types
//

typedef struct _PRODUCT_REFLECTOR_TEXTURE {
    PREFLECTOR_TEXTURE multiplicand0;
    PREFLECTOR_TEXTURE multiplicand1;
} PRODUCT_REFLECTOR_TEXTURE, *PPRODUCT_REFLECTOR_TEXTURE;

typedef const PRODUCT_REFLECTOR_TEXTURE *PCPRODUCT_REFLECTOR_TEXTURE;

//
// Static Functions
//

static
ISTATUS
ProductReflectorTextureSample(
    _In_ const void *context,
    _In_ POINT3 model_hit_point,
    _In_ const void *additional_data,
    _In_ const void *texture_coordinates,
    _Inout_ PREFLECTOR_COMPOSITOR reflector_compositor,
    _Out_ PCREFLECTOR *reflector
    )
{
    PCPRODUCT_REFLECTOR_TEXTURE texture =
        (PCPRODUCT_REFLECTOR_TEXTURE)context;

    PCREFLECTOR multiplicand0;
    ISTATUS status = ReflectorTextureSample(texture->multiplicand0,
                                            model_hit_point,
                                            additional_data,
                                            texture_coordinates,
                                            reflector_compositor,
                                            &multiplicand0);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    PCREFLECTOR multiplicand1;
    status = ReflectorTextureSample(texture->multiplicand1,
                                    model_hit_point,
                                    additional_data,
                                    texture_coordinates,
                                    reflector_compositor,
                                    &multiplicand1);

    if (status != ISTATUS_SUCCESS)
    {
        return status;
    }

    status = ReflectorCompositorMultiplyReflectors(reflector_compositor,
                                                   multiplicand0,
                                                   multiplicand1,
                                                   reflector);

    return status;
}

static
void
ProductReflectorTextureFree(
    _In_opt_ _Post_invalid_ void *context
    )
{
    PPRODUCT_REFLECTOR_TEXTURE texture = (PPRODUCT_REFLECTOR_TEXTURE)context;
    ReflectorTextureRelease(texture->multiplicand0);
    ReflectorTextureRelease(texture->multiplicand1);
}

//
{'fraction_non_alphanumeric': 0.06031109838725069, 'fraction_numerical': 0.007634316251550721, 'mean_word_length': 1.859481582537517, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4994561', 'n_tokens_mistral': 2979, 'n_tokens_neox': 2794, 'n_words': 500}