Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added exercise/01/Release/color_test.iobj
Binary file not shown.
Binary file added exercise/01/Release/color_test.ipdb
Binary file not shown.
66 changes: 66 additions & 0 deletions exercise/01/color.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "stdafx.h"
#include "color.h"
#include <Windows.h>

// Error C2678 binary '==': no operator found which takes a left - hand operand of type 'const T'
bool color::operator==(const color& other) const
{
return red == other.red && green == other.green && blue == other.blue;
}

double color::get_red() const
{
return red;
}

double color::get_green() const
{
return green;
}

double color::get_blue() const
{
return blue;
}


double setToValidRange(double val)
{
if (val < 0.0)
val = 0.0;
else if (val > 1.0)
val = 1.0;
return val;

}

void color::set_red(double red)
{
this->red = setToValidRange(red);
}
void color::set_green(double green)
{
this->green = setToValidRange(green);
}
void color::set_blue(double blue)
{
this->blue = setToValidRange(blue);
}

color::color(double red, double green, double blue)
{
set_red(red);
set_green(green);
set_blue(blue);
}

unsigned long color::get_color_ref() const
{
return RGB(static_cast<int>(red * 255), static_cast<int>(green * 255), static_cast<int>(blue * 255));
//return RGB((int)red * 255, (int)green * 255, (int)blue * 255);
}

double color::get_luminance() const
{
return 0.2126*red + 0.7152*green + 0.0722*blue;
}
26 changes: 26 additions & 0 deletions exercise/01/color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

class color
{
private:
double red;
double green;
double blue;

public:
color(double r = 0.0, double g = 0.0, double b = 0.0);
double get_red() const;
double get_green() const;
double get_blue() const;

void set_red(double value);
void set_green(double value);
void set_blue(double value);

// Error C2678 binary '==': no operator found which takes a left - hand operand of type 'const T'
bool operator==(const color& other) const;

unsigned long get_color_ref() const;
double get_luminance() const;

};
48 changes: 48 additions & 0 deletions exercise/01/colorD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "stdafx.h"
#include "color.h"
#include <algorithm>
const double color_min = 0.0;
const double color_max = 1.0;
color::color(double r, double g, double b) :
red(std::clamp(r, color_min, color_max)),
green(std::clamp(g, color_min, color_max)),
blue(std::clamp(b, color_min, color_max))
{ }
double color::get_red() const
{
return red;
}
double color::get_green() const
{
return green;
}
double color::get_blue() const
{
return blue;
}
void color::set_red(const double value)
{
red = std::clamp(value, color_min, color_max);
}
void color::set_green(const double value)
{
green = std::clamp(value, color_min, color_max);
}
void color::set_blue(const double value)
{
blue = std::clamp(value, color_min, color_max);
}
bool color::operator==(const color& other) const
{
return red == other.red && green == other.green && blue == other.blue;
}
COLORREF color::get_color_ref() const
{
return RGB(static_cast<BYTE> (red * 255),
static_cast<BYTE> (green * 255),
static_cast<BYTE> (blue * 255));
}
double color::get_luminance() const
{
return 0.2126 * red + 0.7152 * green + 0.0722* blue;
}
20 changes: 20 additions & 0 deletions exercise/01/colorD.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <windows.h>
class color
{
public:
color(double r = 0.0, double g = 0.0, double b = 0.0);
double get_red() const;
double get_green() const;
double get_blue() const;
void set_red(double value);
void set_green(double value);
void set_blue(double value);
bool operator==(const color& other) const;
COLORREF get_color_ref() const;
double get_luminance() const;
private:
double red;
double green;
double blue;
};
4 changes: 2 additions & 2 deletions exercise/01/color_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace color_test
Assert::AreEqual(a, b);
Assert::AreEqual(a, c);
}

TEST_METHOD(test_conversion_colorref)
{
Assert::AreEqual(RGB(255, 0, 0), color( 1, 0, 0 ).get_color_ref());
Expand All @@ -84,6 +84,6 @@ namespace color_test
Assert::AreEqual(0.0722, color( 0, 0, 1 ).get_luminance());
Assert::AreEqual( 1., color( 1, 1, 1 ).get_luminance());
}

};
}
31 changes: 31 additions & 0 deletions exercise/01/color_test.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "color_test", "color_test.vcxproj", "{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x64.ActiveCfg = Debug|x64
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x64.Build.0 = Debug|x64
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x86.ActiveCfg = Debug|Win32
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x86.Build.0 = Debug|Win32
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x64.ActiveCfg = Release|x64
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x64.Build.0 = Release|x64
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x86.ActiveCfg = Release|Win32
{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8A6DA6F2-69B3-42AA-BE15-F8B8E72FECF2}
EndGlobalSection
EndGlobal
Loading