Permalink
Browse files

Added CxMath.h tests

  • Loading branch information...
1 parent 1cc3bfc commit af2fc2018d32fbdea52147e595ecef4beacfd580 @grahamboree committed Nov 14, 2012
@@ -184,6 +184,7 @@ namespace CppImage
#endif
#if 1
+ //////////////////////////////////////////////////////////////////////////
class COLORREF
{
public:
@@ -230,13 +231,15 @@ namespace CppImage
}
#endif
+ //////////////////////////////////////////////////////////////////////////
template<typename T>
inline T RGB2GRAY(const T r, const T g, const T b)
{
return (b * 117 + g * 601 + r * 306) >> 10;
}
#if 1
+ //////////////////////////////////////////////////////////////////////////
class Complex
{
public:
@@ -256,10 +259,9 @@ namespace CppImage
double x;
double y;
};
-
-#ifdef CPPIMAGE_TESTING
-# define MACRO__cabs(c) sqrt(c.x*c.x+c.y*c.y)
-#endif
+# ifdef CPPIMAGE_TESTING
+# define MACRO__cabs(c) sqrt(c.x*c.x+c.y*c.y)
+# endif
static inline double _cabs(const _complex& c) { return sqrt(c.x * c.x + c.y * c.y); }
#endif
}
@@ -14,8 +14,8 @@ CxRect2 CxRect2::CrossSection(const CxRect2& inRect2) const
*/
{
CxRect2 cs;
- cs.botLeft.x = max(botLeft.x, inRect2.botLeft.x);
- cs.botLeft.y = max(botLeft.y, inRect2.botLeft.y);
+ cs.botLeft.x = max(botLeft.x, inRect2.botLeft.x);
+ cs.botLeft.y = max(botLeft.y, inRect2.botLeft.y);
cs.topRight.x = min(topRight.x, inRect2.topRight.x);
cs.topRight.y = min(topRight.y, inRect2.topRight.y);
if (cs.botLeft.x <= cs.topRight.x && cs.botLeft.y <= cs.topRight.y)
View
@@ -1,129 +1,135 @@
+//
+// CxMath.h
+// cppimage
+//
+// Created by Graham Pentheny on 11/10/12.
+// Copyright (c) 2012 Graham Pentheny. All rights reserved.
+//
+
#pragma once
#include "CxDefines.h"
-//////////////////////////////////////////////////////////////////////////
-class DLL_EXP CxPoint2
-{
-public:
- CxPoint2();
- CxPoint2(const float inX, const float inY);
- CxPoint2(const CxPoint2& inPoint);
-
- float Distance(const CxPoint2& p2) const;
- float Distance(float inX, float inY) const;
-
- float x;
- float y;
-};
-
-//////////////////////////////////////////////////////////////////////////
-class DLL_EXP CxRect2
-{
-public:
- CxRect2();
- CxRect2(const float inBotLeftX, const float inBotLeftY, const float inTopRightX, const float inTopRightY);
- CxRect2(CxPoint2 const& bl, CxPoint2 const& tr);
- CxRect2(const CxRect2& inRect);
-
- float Surface() const;
- CxRect2 CrossSection(const CxRect2& inRect2) const;
- CxPoint2 Center() const;
- float Width() const;
- float Height() const;
-
- CxPoint2 botLeft;
- CxPoint2 topRight;
-};
-
-//////////////////////////////////////////////////////////////////////////
-inline CxPoint2::CxPoint2()
-: x(0.0f)
-, y(0.0f)
-{
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline CxPoint2::CxPoint2(const float inX, const float inY)
-: x(inX)
-, y(inY)
-{
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline CxPoint2::CxPoint2(const CxPoint2& inPoint)
-: x(inPoint.x)
-, y(inPoint.y)
-{
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline float CxPoint2::Distance(const CxPoint2& p2) const
+namespace CppImage
{
- return (float)sqrt((x - p2.x) * (x - p2.x) + (y - p2.y) * (y - p2.y));
+ //////////////////////////////////////////////////////////////////////////
+ class DLL_EXP Point2
+ {
+ public:
+ Point2();
+ Point2(float inX, float inY);
+
+ float Distance(const Point2& p2) const;
+ float Distance(float inX, float inY) const;
+
+ float x;
+ float y;
+ };
+ /// @todo remove this. Exists for compatibility.
+ typedef Point2 CxPoint2;
+
+ //////////////////////////////////////////////////////////////////////////
+ class DLL_EXP Rect2
+ {
+ public:
+ Rect2(float inBotLeftX, float inBotLeftY, float inTopRightX, float inTopRightY);
+ Rect2(const Point2& inBottomLeft, const Point2& inTopRight);
+
+ float Area() const;
+ Rect2 CrossSection(const Rect2& inRect2) const;
+ Point2 Center() const;
+ float Width() const;
+ float Height() const;
+
+ Point2 botLeft;
+ Point2 topRight;
+ };
+ /// @todo remove this. Exists for compatibility.
+ typedef Rect2 CxRect2;
}
-//////////////////////////////////////////////////////////////////////////
-inline float CxPoint2::Distance(float inX, float inY) const
-{
- return (float)sqrt((x - inX) * (x - inX) + (y - inY) * (y - inY));
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline CxRect2::CxRect2()
-{
-}
-//////////////////////////////////////////////////////////////////////////
-inline CxRect2::CxRect2(const float inBotLeftX, const float inBotLeftY, const float inTopRightX, const float inTopRightY)
-: botLeft(inBotLeftX, inBotLeftY)
-, topRight(inTopRightX, inTopRightY)
+namespace CppImage
{
+ //////////////////////////////////////////////////////////////////////////
+ /// Default constructs a point at the origin.
+ inline Point2::Point2()
+ : x(0.0f)
+ , y(0.0f)
+ {
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @param[in] inX The point's x coordinate.
+ /// @param[in] inY The point's y coordinate.
+ inline Point2::Point2(const float inX, const float inY)
+ : x(inX)
+ , y(inY)
+ {
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @param[in] inPoint The other point.
+ /// @returns The distance between this point and the other point.
+ inline float Point2::Distance(const Point2& p2) const
+ {
+ return (float)sqrt((x - p2.x) * (x - p2.x) + (y - p2.y) * (y - p2.y));
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @param[in] inX The x coordinate of the other point.
+ /// @param[in] inY The y coordinate of the other point.
+ /// @returns The distance between this and the other point.
+ inline float Point2::Distance(const float inX, const float inY) const
+ {
+ return (float)sqrt((x - inX) * (x - inX) + (y - inY) * (y - inY));
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @param[in] inLeft The rect's minimum x extent.
+ /// @param[in] inBottom The rect's minimum y extent.
+ /// @param[in] inRight The rect's maximum x extent.
+ /// @param[in] inTop The rect's maximum y extent.
+ inline Rect2::Rect2(const float inLeft, const float inBottom, const float inRight, const float inTop)
+ : botLeft(inLeft, inBottom)
+ , topRight(inRight, inTop)
+ {
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @param[in] inBototmLeft The bottom left corner of the rectangle.
+ /// @param[in] inTopRight The top right corner of the rectangle.
+ inline Rect2::Rect2(const Point2& inBottomLeft, const Point2& inTopRight)
+ : botLeft(inBottomLeft)
+ , topRight(inTopRight)
+ {
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @returns The area of the rectangle.
+ inline float Rect2::Area() const
+ {
+ return (topRight.x - botLeft.x) * (topRight.y - botLeft.y);
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @returns The center point of rectangle.
+ inline Point2 Rect2::Center() const
+ {
+ return Point2((topRight.x + botLeft.x) / 2.0f, (topRight.y + botLeft.y) / 2.0f);
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @returns The rectangle width.
+ inline float Rect2::Width() const
+ {
+ return topRight.x - botLeft.x;
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ /// @returns The rectangle height.
+ inline float Rect2::Height() const
+ {
+ return topRight.y - botLeft.y;
+ }
}
-
-//////////////////////////////////////////////////////////////////////////
-inline CxRect2::CxRect2(const CxRect2& inRect)
-: botLeft(inRect.botLeft)
-, topRight(inRect.topRight)
-{
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline CxRect2::CxRect2(const CxPoint2& inBottomLeft, const CxPoint2& inTopRight)
-: botLeft(inBottomLeft)
-, topRight(inTopRight)
-{
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline float CxRect2::Surface() const
-/*
- * Returns the surface of rectangle.
- */
-{
- return (topRight.x - botLeft.x) * (topRight.y - botLeft.y);
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline CxPoint2 CxRect2::Center() const
-/*
- * Returns the center point of rectangle.
- */
-{
- return CxPoint2((topRight.x + botLeft.x) / 2.0f, (topRight.y + botLeft.y) / 2.0f);
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline float CxRect2::Width() const
-//returns rectangle width
-{
- return topRight.x - botLeft.x;
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline float CxRect2::Height() const
-//returns rectangle height
-{
- return topRight.y - botLeft.y;
-}
-
@@ -158,6 +158,7 @@
C9CA7AD61650742500192514 /* cppimage_tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cppimage_tests; sourceTree = BUILT_PRODUCTS_DIR; };
C9CA7AD91650742500192514 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
C9CA7ADB1650742500192514 /* cppimage_tests.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = cppimage_tests.1; sourceTree = "<group>"; };
+ C9CA7AEA1651FF3000192514 /* TestCxMath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = TestCxMath.h; path = CppImageTests/TestCxMath.h; sourceTree = "<group>"; };
C9FA0F541610296F0010C75D /* libcppimage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcppimage.a; sourceTree = BUILT_PRODUCTS_DIR; };
C9FA104216102B9E0010C75D /* tif_xfile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tif_xfile.cpp; path = ../tif_xfile.cpp; sourceTree = "<group>"; };
C9FA104816102B9E0010C75D /* ximadsp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ximadsp.cpp; path = Source/cppimage/ximadsp.cpp; sourceTree = "<group>"; };
@@ -238,9 +239,16 @@
isa = PBXGroup;
children = (
C92685A91621667300D4EB54 /* Format Specific */,
+ C92685A716215C8600D4EB54 /* CImageIterator.h */,
C92689AC162212CB00D4EB54 /* CxConfig.h */,
C92689AD162212CC00D4EB54 /* CxDefines.h */,
+ C926859E16215C5500D4EB54 /* CxFile.h */,
+ C92685A116215C6800D4EB54 /* CxImage.h */,
+ C92685A216215C6800D4EB54 /* CxIOFile.h */,
C92685EA1621F2D300D4EB54 /* CxMath.cpp */,
+ C92685EB1621F2D400D4EB54 /* CxMath.h */,
+ C92685A316215C6800D4EB54 /* CxMemFile.h */,
+ C935CA6B1612A6EE00C72CD1 /* Types.h */,
C9FA104816102B9E0010C75D /* ximadsp.cpp */,
C9FA104916102B9E0010C75D /* ximaenc.cpp */,
C9FA104A16102B9E0010C75D /* ximaexif.cpp */,
@@ -254,13 +262,6 @@
C9FA106816102B9E0010C75D /* ximasel.cpp */,
C9FA107116102B9E0010C75D /* ximatran.cpp */,
C9FA107616102B9E0010C75D /* ximawnd.cpp */,
- C92685A716215C8600D4EB54 /* CImageIterator.h */,
- C926859E16215C5500D4EB54 /* CxFile.h */,
- C92685A116215C6800D4EB54 /* CxImage.h */,
- C92685A216215C6800D4EB54 /* CxIOFile.h */,
- C92685EB1621F2D400D4EB54 /* CxMath.h */,
- C92685A316215C6800D4EB54 /* CxMemFile.h */,
- C935CA6B1612A6EE00C72CD1 /* Types.h */,
);
name = Source;
sourceTree = "<group>";
@@ -275,9 +276,9 @@
C984971D164B6F8300F7F2B4 /* Tests */ = {
isa = PBXGroup;
children = (
+ C9CA7AE91651FF0B00192514 /* CppImageTests */,
C9CA7AA616506FC000192514 /* CPPTest */,
C984972B164B771A00F7F2B4 /* App */,
- C984972C164ECEC600F7F2B4 /* TestCxDefines.h */,
);
name = Tests;
path = cppimage_tests;
@@ -329,6 +330,15 @@
path = cppimage_tests;
sourceTree = "<group>";
};
+ C9CA7AE91651FF0B00192514 /* CppImageTests */ = {
+ isa = PBXGroup;
+ children = (
+ C9CA7AEA1651FF3000192514 /* TestCxMath.h */,
+ C984972C164ECEC600F7F2B4 /* TestCxDefines.h */,
+ );
+ name = CppImageTests;
+ sourceTree = "<group>";
+ };
C9FA0F491610296F0010C75D = {
isa = PBXGroup;
children = (
Oops, something went wrong.

0 comments on commit af2fc20

Please sign in to comment.