diff --git a/.vscode/settings.json b/.vscode/settings.json index 825caf94..77d274f1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "ARGB", "Bezier", "BGRA", + "bitmapdata", "bitmask", "blit", "Blitting", @@ -33,6 +34,7 @@ "fceil", "ffloor", "Flixel", + "flxsprite", "frameworking", "fround", "grayscale", @@ -45,6 +47,7 @@ "haxeui", "hxml", "ifies", + "imagedata", "interp", "Ints", "kernal", diff --git a/CHANGELOG.md b/CHANGELOG.md index 1077c478..73bca14c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +# 2.1.1 + +### `Image.hx` + - **Added `Image.copyImageFrom`** + +### `vision.ds` + - **Added `ImageFormat.JPEG`, `ImageFormat.VISION`** + +### `vision.tools` + - **Added `ImageTools.loadFromFile` (synchronous version)** + - **Added `ImageTools.loadFromBytes`** + - **Added `ImageTools.loadFromURL`** + - **Added `ImageTools.exportToBytes`** + - **Added `ImageTools.exportToFile`** + - **Deprecated `ImageTools.saveToFile` in favor of `ImageTools.exportToFile`** + +### `vision.formats` + - **New Subdirectory inside the `vision` package for cleaner image format conversions** + - **Added `ImageIO` - reads/writes images from/to different formats/frameworks** + - **Added support for `jpeg` encoding for non-js platforms using `format`** + # 2.1.0 ### `Vision.hx` diff --git a/src/VisionMain.hx b/src/VisionMain.hx index 8d63d3b5..64eade12 100644 --- a/src/VisionMain.hx +++ b/src/VisionMain.hx @@ -1,5 +1,6 @@ package; +import vision.formats.ImageIO; import vision.algorithms.SimpleHough; import vision.ds.Matrix2D; import vision.ds.Color; @@ -35,6 +36,7 @@ using vision.tools.MathTools; printImage(image); printImage(image.filterForColorChannel(RED)); + #if simple_tests printSectionDivider("Simple image manipulation"); start = haxe.Timer.stamp(); diff --git a/src/vision/Vision.hx b/src/vision/Vision.hx index 5730a8c0..e704c308 100644 --- a/src/vision/Vision.hx +++ b/src/vision/Vision.hx @@ -74,8 +74,9 @@ class Vision { @param image The image to combine on. When this function returns, that image should be modified @param with The second image to combine with. That image is preserved throughout the function. @param percentage The ratio between the contributions of each pixel within the two images, from 0 to 100: a lower value will make the first image's pixels contribute more to the the final image, thus making that image more similar to the first image, and vice-versa. + @return The combined image. The original copy (The first parameter) is modified. **/ - public static function combine(image:Image, ?with:Image, percentage:Float = 50) { + public static function combine(image:Image, ?with:Image, percentage:Float = 50):Image { if (with == null) with = new Image(image.width, image.height); final translated = percentage / 100; image.forEachPixelInView((x, y, first) -> { @@ -96,7 +97,7 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-tint.png)| @param image The image to tint - @param withColor The color to tint the image with. Each channel is considered separately, so a color with `alpha` of 0 won't affect other color channels. + @param withColor The color to tint the image with. Each channel is considered separately, so a color with `alpha` of 0 won't affect other color channels. Default is `Color.BLACK` @param percentage The amount by which to tint. `100` yields an image completely colored with `withColor`, while `0` yields the original image. Default is `50` @return The tinted image. The original image is modified. **/ @@ -125,9 +126,8 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-grayscale.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-grayscale&vision_better_grayscale.png)| @param image The image to be grayscaled. - @param simpleGrayscale When enabled, gets the gray by averaging pixel's color-channel values, instead of using a special ratio for more accurate grayscaling. Defaults to `false`. - - @return The grayscaled image. + @param simpleGrayscale When enabled, gets the gray by averaging pixel's color-channel values, instead of using a special ratio for more accurate grayscaling. Default is `false`. + @return The grayscaled image. The original image is modified. **/ public static function grayscale(image:Image, simpleGrayscale:Bool = false):Image { image.forEachPixelInView((x, y, pixel) -> { @@ -157,9 +157,9 @@ class Vision { @param image The image to be inverted. - @return The inverted image. + @return The inverted image. The original image is modified. **/ - public static function invert(image:Image) { + public static function invert(image:Image):Image { image.forEachPixelInView((x, y, pixel) -> { image.setUnsafePixel(x, y, Color.fromRGBA(255 - pixel.red, 255 - pixel.green, 255 - pixel.blue)); }); @@ -174,8 +174,12 @@ class Vision { | Original | `strength = 0.25` | |---|---| |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-sepia.png)| + + @param image The image to be tinted. + @param strength The amount of sepia to apply. The higher the value, the older the image looks. Default is `0.25`. + @return The tinted image. The original image is modified. **/ - public static function sepia(image:Image, strength:Float = 0.25) { + public static function sepia(image:Image, strength:Float = 0.25):Image { image.forEachPixelInView((x, y, pixel) -> { image.setUnsafePixel(x, y, Color.interpolate(pixel, Color.SEPIA, strength)); }); @@ -192,9 +196,8 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-blackAndWhite.png)| @param image The image to be converted. - @param threshold The threshold for converting to black and white: `threshold` is the maximum average of the three color components, that will still be considered black. `threshold` is a value between 0 and 255. The higher the value, the more "sensitive" the conversion. The default value is 128. - - @return The converted image. + @param threshold The threshold for converting to black and white: `threshold` is the maximum average of the three color components, that will still be considered black. `threshold` is a value between 0 and 255. The higher the value, the more "sensitive" the conversion. Default is `128`. + @return The converted image. The original image is modified. **/ public static function blackAndWhite(image:Image, threshold:Int = 128):Image { image.forEachPixelInView((x, y, pixel) -> { @@ -217,6 +220,7 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-contrast.png)| @param image The image to be contrasted. + @return The contrasted image. The original image is modified. **/ public static function contrast(image:Image):Image { return convolve(image, UnsharpMasking); @@ -234,11 +238,11 @@ class Vision { @param image The image to be smoothed. @param strength The strength of the smoothing. Higher values will result in more smoothing. Ranges from 0 to 1. Default is `0.1`. - @param affectAlpha If `true`, the alpha channel will be smoothed as well. Defaults to `false`. + @param affectAlpha If `true`, the alpha channel will be smoothed as well. Default is `false`. @param kernelRadius The radius of the smoothing kernel. Higher values will result in more smoothing. Default is `1`, which uses a 3x3 kernel. - @param circularKernel If `true`, the kernel will be circular. If `false`, the kernel will be square. + @param circularKernel If `true`, the kernel will be circular. If `false`, the kernel will be square. Default is `true`. @param iterations The number of times the smoothing should be applied. Higher values will result in more smoothing. Default is `1`. - @return The smoothed image. The given image is modified. + @return The smoothed image. The original image is modified. **/ public static function smooth(image:Image, strength:Float = 0.1, affectAlpha:Bool = false, kernelRadius:Int = 1, circularKernel:Bool = true, iterations:Int = 1):Image { var size = kernelRadius * 2 + 1; @@ -274,9 +278,9 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-pixelate.png)| @param image The image to pixelate - @param averagePixels Whether to use pixel averaging to get resulting pixels, or just use the original, remaining pixel. - @param pixelSize the new "pixel size" - @param affectAlpha Whether this effect applies to the alpha channel of each pixel or not + @param averagePixels Whether to use pixel averaging to get resulting pixels, or just use the original, remaining pixel. Default is `true`. + @param pixelSize the new "pixel size". Default is `2`. + @param affectAlpha Whether this effect applies to the alpha channel of each pixel or not. Default is `true`. @return The given image, pixelated. The original image is modified. **/ public static function pixelate(image:Image, averagePixels:Bool = true, pixelSize:Int = 2, affectAlpha:Bool = true):Image { @@ -326,10 +330,11 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-posterize.png)| @param image The image to be posterized. - @param bitsPerChannel The number of bits per channel. Defaults to `4`. Ranges from `1` to `8`. - @param affectAlpha If `true`, the alpha channel will be posterized as well. Defaults to `true`. + @param bitsPerChannel The number of bits per channel. Default is `4`. Ranges from `1` to `8`. + @param affectAlpha If `true`, the alpha channel will be posterized as well. Default is `true`. + @return The given image, posterized. The original image is modified. **/ - public static function posterize(image:Image, bitsPerChannel:Int = 4, affectAlpha:Bool = true) { + public static function posterize(image:Image, bitsPerChannel:Int = 4, affectAlpha:Bool = true):Image { var denominator = (256 / bitsPerChannel).floor(); // Is an integer anyways. image.forEachPixelInView((x, y, pixel) -> { var r = (pixel.red / denominator).round() * denominator; @@ -355,7 +360,7 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-sharpen.png)| @param image The image to be contrasted. - @return The sharpened image. The original copy is not preserved. + @return The sharpened image. The original copy is modified. **/ public static function sharpen(image:Image):Image { return convolve(image, Sharpen); @@ -372,8 +377,8 @@ class Vision { The higher the value, the more deepfried the image will look. @param image The image to be deepfried. - @param iterations The amount of times the image gets sharpened. default is `2`. - @return The deepfried image. The original copy is not preserved. + @param iterations The amount of times the image gets sharpened. Default is `2`. + @return The deepfried image. The original copy is modified. **/ public static function deepfry(image:Image, iterations:Int = 2):Image { for (i in 0...iterations) @@ -392,14 +397,14 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-vignette%28ratioDependent%20=%20true%29.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-vignette%28ratioDependent%20=%20false%29.png)| @param image The image to apply vignette on - @param strength in percentage, the amount of the image that has vignette, from the edge. Ranges from `0` to `1`. Defaults to `0.2` + @param strength in percentage, the amount of the image that has vignette, from the edge. Ranges from `0` to `1`. Default is `0.2`. @param intensity Determines how quickly vignette sets in when a pixel is supposed to be affected. The higher the value, the quicker it turns to the target color. The closer the value is to `0`, the slower it - turns into the target color, and the less effected the edges. + turns into the target color, and the less effected the edges. Default is `1`. @param ratioDependent DEtermines if the effect should always treat the image as a square, and thus be circular (`false`) or if it should consider different dimensions, - and appear "elliptical" (`true`) - @param color The target color for the vignette effect + and appear "elliptical" (`true`). Default is `false`. + @param color The target color for the vignette effect. Default is `Color.BLACK` @return the given image, with vignette applied. The original image is modified. **/ public static function vignette(image:Image, ?strength:Float = 0.2, ?intensity:Float = 1, ratioDependent:Bool = false, color:Color = Color.BLACK):Image { @@ -427,8 +432,8 @@ class Vision { @param image The image to apply the distortion to - @param strength The "amount" of warping done to the image. A higher value means pixels closer to the center are more distorted. @return Image - @returns the image, with fish-eye effect. The original image is preserved. + @param strength The "amount" of warping done to the image. A higher value means pixels closer to the center are more distorted. Default is `1.5`. + @return the given image, with fish-eye effect. The original image is preserved. **/ public static function fisheyeDistortion(image:Image, ?strength:Float = 1.5):Image { var centerX = image.width / 2, @@ -471,11 +476,11 @@ class Vision { @param image The image to distort @param strength The amount of distortion to apply. The higher the value the more distortion - there is. A negative value implies `Vision.pincushionDistortion`. + there is. A negative value implies `Vision.pincushionDistortion`. Values converging to 0 distort the image less and less. Default is `0.2`. - @returns A distorted copy of the given image. + @return The given image, with barrel distortion applied. The original image is preserved. **/ - public static function barrelDistortion(image:Image, ?strength:Float = 0.2) { + public static function barrelDistortion(image:Image, ?strength:Float = 0.2):Image { var centerX = image.width / 2, centerY = image.height / 2; var maxRadius = Math.min(centerX, centerY); @@ -518,9 +523,9 @@ class Vision { @param strength The amount of distortion to apply. The higher the value, the more distortion there is. A negative value implies `Vision.barrelDistortion`. Values converging to 0 distort the image less and less. Default is `0.2`. - @returns A distorted copy of the given image. The original image is preserved. + @return The given image, with pincushion distortion applied. The original image is preserved. **/ - public static function pincushionDistortion(image:Image, ?strength:Float = 0.2) { + public static function pincushionDistortion(image:Image, ?strength:Float = 0.2):Image { return barrelDistortion(image, -strength); } @@ -536,12 +541,12 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![Processed](https://spacebubble-io.pages.dev/vision/docs/valve-barrelDistortion.png)|![Processed](https://spacebubble-io.pages.dev/vision/docs/valve-pincushionDistortion.png)|![Processed](https://spacebubble-io.pages.dev/vision/docs/valve-mustacheDistortion.png)| @param image The image to distort - @param strength The amount of distortion to apply. The higher the value, the more distortion + @param amplitude The amount of distortion to apply. The higher the value, the more distortion there is. A negative value flips the effect. Values converging to 0 distort the image less and less. Default is `0.2`. - @returns A distorted copy of the image. The original image is preserved. + @return The given image, with mustache distortion applied. The original image is preserved. **/ - public static function mustacheDistortion(image:Image, amplitude:Float = 0.2) { + public static function mustacheDistortion(image:Image, amplitude:Float = 0.2):Image { var centerX = image.width / 2, centerY = image.height / 2; var maxRadius = Math.min(centerX, centerY); @@ -589,10 +594,18 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-dilate.png)| @param image The image to operate on. - @param dilationRadius The radius of the kernel used for the dilation process. The radius does not include the center pixel, so a radius of `2` should give a `5x5` kernel. The higher this value, the further each pixel checks for a nearby lighter pixel. - @param colorImportanceOrder Since there may be conflicts when calculating the difference in lightness between colors with similar values in different color channels (e.g. `0xFF0000` and `0x0000FF` - channel values are "similar", colors are not), this parameter is used to favor the given color channels. The default is `RedGreenBlue` - `red` is the most important, and is considered the "lightest", followed by green, and blue is considered the "darkest". - @param circularKernel When enabled, the kernel used to loop over the pixels becomes circular instead of being a square. This results in a slight performance increase, and a massive quality increase. Turned on by default. - @return The dilated image. The original copy is not preserved. + @param dilationRadius The radius of the kernel used for the dilation process. + The radius does not include the center pixel, so a radius of `2` should give a `5x5` kernel. + The higher this value, the further each pixel checks for a nearby lighter pixel. Default is `2`. + @param colorImportanceOrder Since there may be conflicts when calculating the difference in lightness + between colors with similar values in different color channels + (e.g. `0xFF0000` and `0x0000FF` - channel values are "similar", colors are not), + this parameter is used to favor the given color channels. Default is `RedGreenBlue` - + `red` is the most important, and is considered the "lightest", followed by green, + and blue is considered the "darkest". + @param circularKernel When enabled, the kernel used to loop over the pixels becomes circular instead of being a + square. This results in a slight performance increase, and a great quality increase. Default is `true`. + @return The dilated image. The original copy is modified. **/ public static function dilate(image:Image, ?dilationRadius:Int = 2, ?colorImportanceOrder:ColorImportanceOrder = RedGreenBlue, circularKernel:Bool = true):Image { var intermediate = image.clone(); @@ -627,10 +640,17 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-erode.png)| @param image The image to operate on. - @param dilationRadius The radius of the kernel used for the erosion process. The radius does not include the center pixel, so a radius of `2` should give a `5x5` kernel. The higher this value, the further each pixel checks for a nearby darker pixel. - @param colorImportanceOrder Since there may be conflicts when calculating the difference in darkness between colors with similar values in different color channels (e.g. `0xFF0000` and `0x0000FF` - channel values are "similar", colors are not), this parameter is used to favor the given color channels. The default is `RedGreenBlue` - `red` is the most important, and is considered the "darkest", followed by green, and blue is considered the "lightest". - @param circularKernel When enabled, the kernel used to loop over the pixels becomes circular instead of being a square. This results in a slight performance increase, and a massive quality increase. Turned on by default. - @return The eroded image. The original copy is not preserved. + @param dilationRadius The radius of the kernel used for the erosion process. + The radius does not include the center pixel, so a radius of `2` should give a `5x5` kernel. + The higher this value, the further each pixel checks for a nearby darker pixel. Default is `2`. + @param colorImportanceOrder Since there may be conflicts when calculating the difference in darkness between + colors with similar values in different color channels + (e.g. `0xFF0000` and `0x0000FF` - channel values are "similar", colors are not), this parameter is used to + favor the given color channels. The default is `RedGreenBlue` - `red` is the most important, and is considered + the "darkest", followed by green, and blue is considered the "lightest". + @param circularKernel When enabled, the kernel used to loop over the pixels becomes circular instead of being a + square. This results in a slight performance increase, and a massive quality increase. Default is `true`. + @return The eroded image. The original copy is modified. **/ public static function erode(image:Image, ?erosionRadius:Int = 2, ?colorImportanceOrder:ColorImportanceOrder = RedGreenBlue, circularKernel:Bool = true):Image { var intermediate = image.clone(); @@ -658,10 +678,11 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-saltAndPepperNoise.png) @param image The image to apply salt&pepper noise on. - @param percentage How much of the image should be "corrupted", in percentages between 0 to 100 - 0 means no change, 100 means fully "corrupted". Default is 25. - @return The noisy image. The original copy is not preserved. + @param percentage How much of the image should be "corrupted", in percentages between `0` to `100` - `0` + means no change, `100` means fully "corrupted". Default is `25`. + @return The noisy image. The original copy is modified. - @see Color.interpolate() + @see **`Color.interpolate()`** **/ public static function saltAndPepperNoise(image:Image, percentage:Float = 25):Image { var translated = percentage / 100; @@ -691,9 +712,12 @@ class Vision { |---|---| |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-dropOutNoise.png) - @param image The image to apply salt&pepper noise on - @param percentage How much of the image should be "corrupted", in percentages between 0 to 100 - 0 means no change, 100 means fully "corrupted". Default is 5 - @return The noisy image. The original copy is not preserved. + @param image The image to apply drop-out noise on + @param percentage How much of the image should be "corrupted", in percentages between `0` to `100` - + `0` means no change, `100` means fully "corrupted". Default is `5`. + @param threshold The threshold at which a pixel is considered "black" or "white". A color measures against + this threshold by grabbing the largest color channel value, and comparing it. Default is `128`. + @return The noisy image. The original copy is modified. **/ public static function dropOutNoise(image:Image, percentage:Float = 5, threshold:Int = 128):Image { var translated = percentage / 100; @@ -720,9 +744,9 @@ class Vision { @param image The image to apply salt&pepper noise on @param percentage How white-noisy the resulting image should be, or, the ratio between the contributions of each pixel from the original image and the white noise to the final image, from 0 to 100: a lower value will make the first image's pixels contribute more to the the final image, thus making the resulting image less noisy, and vice-versa. @param whiteNoiseRange The number of shades of gray used to generate the white noise. Shouldn't really effect performance, but you may want to change it to get a "higher/lower quality" white noise. - @return The noisy image. The original copy is not preserved. + @return The noisy image. The original copy is modified. **/ - public static function whiteNoise(image:Image, percentage:Float = 25, whiteNoiseRange:WhiteNoiseRange = RANGE_16) { + public static function whiteNoise(image:Image, percentage:Float = 25, whiteNoiseRange:WhiteNoiseRange = RANGE_16):Image { var colorVector:Vector = new Vector(whiteNoiseRange); colorVector[0] = 0; colorVector[colorVector.length - 1] = 255; @@ -761,7 +785,7 @@ class Vision { @param image The image to be normalized. @param rangeStart The start of the range of channels. By default, this value is `0x00000000` @param rangeEnd The end of the range of channels. By default, this value is `0xFFFFFFFF` - @return The normalized image. The original copy is not preserved. + @return The normalized image. The original copy is modified. **/ public static function normalize(image:Image, rangeStart:Color = 0x00000000, rangeEnd:Color = 0xFFFFFFFF):Image { var max:Color = 0x0, min:Color = 0x0, step:Color = 0x0; @@ -791,7 +815,7 @@ class Vision { @param image The image to be li processed. @param rangeStart The start of the range of channels. By default, this value is `0x00000000` @param rangeEnd The end of the range of channels. By default, this value is `0xFFFFFFFF` - @return The normalized image. The original copy is not preserved. + @return The normalized image. The original copy is modified. **/ public static function limitColorRanges(image:Image, rangeStart:Color = 0x00000000, rangeEnd:Color = 0xFFFFFFFF):Image { image.forEachPixelInView((x, y, color) -> { @@ -812,7 +836,7 @@ class Vision { @param image The image process. @param ranges array of color ranges & replacement colors. - @return A processed version of the image. The original image is not preserved. + @return A processed version of the image. The original image is modified. **/ public static function replaceColorRanges(image:Image, ?ranges:Array<{rangeStart:Color, rangeEnd:Color, replacement:Color}>):Image { if (ranges == null) return image; @@ -840,7 +864,7 @@ class Vision { @param image The image to be processed @param channel The color channel to be isolated - @return The processed image. The original image is not preserved + @return The processed image. The original image is modified **/ public static function filterForColorChannel(image:Image, channel:ColorChannel = ColorChannel.RED):Image { var output = image.clone(); @@ -889,7 +913,7 @@ class Vision { @param image the image to be manipulated @param kernel the type/value of the kernel. can be: **`Identity`**, **`BoxBlur`**, **`RidgeDetection`**, **`Sharpen`**, **`UnsharpMasking`**, **`Assemble3x3`**, **`Assemble5x5`**, or just a matrix: both `convolve(image, BoxBlur)` and `convolve(image, [[1,1,1],[1,1,1],[1,1,1]])` are valid ways to represent a box blur. - @return A convolved version of the image. The original image is not preserved. + @return A convolved version of the image. The original image is modified. **/ public static function convolve(image:Image, kernel:EitherType>> = Identity):Image { var matrix:Array>; @@ -978,16 +1002,16 @@ class Vision { @param image The image to manipulate. @param matrix a transformation matrix to use when manipulating the image. expects a 3x3 matrix. any other size may throw an error. - @param expansionMode how to expand the image if the matrix moves the image outside of its original bounds, or never reaches the original bounds. Defaults to `ImageExpansionMode.SAME_SIZE`. - @param originPoint **OPTION 1**: the point in the image to use as the origin of the transformation matrix. Before a point is passed to the matrix, it's coordinates are incremented by this point, and after the matrix is applied, it's coordinates are decremented by this point. Useful for rotation transformations. Defaults to `(0, 0)`. - @param originMode **OPTION 2**: To avoid code-bloat, you can provide a pre-made representation of the origin point, via `TransformationMatrixOrigination` enum. Defaults to `TransformationMatrixOrigination.TOP_LEFT`. - @returns A new, manipulated image. The provided image remains unchanged. + @param expansionMode how to expand the image if the matrix moves the image outside of its original bounds, or never reaches the original bounds. Default is `ImageExpansionMode.SAME_SIZE`. + @param originPoint **OPTION 1**: the point in the image to use as the origin of the transformation matrix. Before a point is passed to the matrix, it's coordinates are incremented by this point, and after the matrix is applied, it's coordinates are decremented by this point. Useful for rotation transformations. Default is `(0, 0)`. + @param originMode **OPTION 2**: To avoid code-bloat, you can provide a pre-made representation of the origin point, via `TransformationMatrixOrigination` enum. Default is `TransformationMatrixOrigination.TOP_LEFT`. + @return A new, manipulated image. The provided image remains unchanged. @throws MatrixMultiplicationError if the size of the given matrix is not 3x3. @see `Vision.convolve()` for color-manipulation matrices (or, kernels). @see `Vision.perspectiveWarp()` for "3d" manipulations. **/ - public static function affineTransform(image:Image, ?matrix:TransformationMatrix2D, expansionMode:ImageExpansionMode = RESIZE, ?originPoint:Point2D, ?originMode:TransformationMatrixOrigination = CENTER) { + public static function affineTransform(image:Image, ?matrix:TransformationMatrix2D, expansionMode:ImageExpansionMode = RESIZE, ?originPoint:Point2D, ?originMode:TransformationMatrixOrigination = CENTER):Image { if (matrix == null) matrix = Matrix2D.IDENTITY(); // Get the max values for bounds expansion var mix = MathTools.POSITIVE_INFINITY, max = MathTools.NEGATIVE_INFINITY, miy = MathTools.POSITIVE_INFINITY, may = MathTools.NEGATIVE_INFINITY; @@ -1036,7 +1060,6 @@ class Vision { y = 0; } - // Interpolate missing pixels, using bilinear interpolation. pixel radius is chosen by the ratio of the distance from `mix to max` to width, same for height. return img; } @@ -1061,7 +1084,7 @@ class Vision { @param image The image to manipulate. @param matrix a transformation matrix to use when manipulating the image. expects a 3x3 matrix. any other size may throw an error. - @param expansionMode How to expand the image's bounds when the resulting image after transformation changes dimensions. Defaults to `RESIZE`. + @param expansionMode How to expand the image's bounds when the resulting image after transformation changes dimensions. Default is `RESIZE`. **/ public static function projectiveTransform(image:Image, ?matrix:TransformationMatrix2D, expansionMode:ImageExpansionMode = RESIZE):Image { @@ -1122,7 +1145,7 @@ class Vision { @param image The image to be blurred. @param iterations The number of times the algorithm will be run. The more iterations, the more blurry the image will be, and the higher the "blur range". **For example:** a value of 3 will produce a blur range of 3 pixels on each object. - @return A blurred version of the image. The original image is not preserved. + @return A blurred version of the image. The original image is modified. **/ public static function nearestNeighborBlur(image:Image, iterations:Int = 1):Image { for (i in 0...iterations) image = convolve(image, BoxBlur); @@ -1149,7 +1172,7 @@ class Vision { @param sigma The sigma value to use for the gaussian distribution on the kernel. a lower value will focus more on the center pixel, while a higher value will shift focus to the surrounding pixels more, effectively blurring it better. @param kernelSize The size of the kernel (`width` & `height`) @throws InvalidGaussianKernelSize if the kernel size is even, negative or `0`, this error is thrown. - @return A blurred version of the image. The original image is not preserved. + @return A blurred version of the image. The original image is modified. **/ public static function gaussianBlur(image:Image, ?sigma:Float = 1, ?kernelSize:GaussianKernelSize = GaussianKernelSize.X5, ?fast:Bool = false):Image { if (fast) return Gauss.fastBlur(image, kernelSize, sigma); @@ -1170,7 +1193,7 @@ class Vision { @param image The image to apply median blurring to. @param kernelSize the width & height of the kernel in which we should search for the median. A radius of `9` will check in a `19x19` (`radius(9)` + `center(1)` + `radius(9)`) square around the center pixel. - @return A filtered version of the image, using median blurring. The original image is not preserved. + @return A filtered version of the image, using median blurring. The original image is modified. **/ public static function medianBlur(image:Image, kernelSize:Int = 5):Image { var median = image.clone(); @@ -1255,7 +1278,7 @@ class Vision { @param image The image to be operated on @return A new image, containing the gradients of the edges as whitened pixels. **/ - public static function sobelEdgeDiffOperator(image:Image) { + public static function sobelEdgeDiffOperator(image:Image):Image { return Sobel.convolveWithSobelOperator(grayscale(image.clone())); } @@ -1276,7 +1299,7 @@ class Vision { @param image The image to be operated on @return A new image, containing the gradients of the edges as whitened pixels. **/ - public static function perwittEdgeDiffOperator(image:Image) { + public static function perwittEdgeDiffOperator(image:Image):Image { return Perwitt.convolveWithPerwittOperator(grayscale(image.clone())); } @@ -1298,7 +1321,7 @@ class Vision { @param image The image to be operated on @return A new image, containing the gradients of the edges as whitened pixels. **/ - public static function robertEdgeDiffOperator(image:Image) { + public static function robertEdgeDiffOperator(image:Image):Image { return RobertsCross.convolveWithRobertsCross(grayscale(image.clone())); } @@ -1320,7 +1343,7 @@ class Vision { @param filterPositive Which version of the laplacian filter should the function use: the negative (detects "outward" edges), or the positive (detects "inward" edges). Default is positive (`true`). @return A new image, containing the gradients of the edges as whitened pixels. **/ - public static function laplacianEdgeDiffOperator(image:Image, filterPositive:Bool = true) { + public static function laplacianEdgeDiffOperator(image:Image, filterPositive:Bool = true):Image { return Laplace.convolveWithLaplacianOperator(image.clone(), filterPositive); } @@ -1422,7 +1445,7 @@ class Vision { @param kernelSize The size of the kernel (`width` & `height`) - a kernel size of `7`/ will produce a `7x7` kernel. Default is `GaussianKernelSize.X3`. @return A new, black and white image, with white pixels being the detected edges. **/ - public static function laplacianOfGaussianEdgeDetection(image:Image, ?threshold:Int = 2, ?filterPositive:Bool = true, ?sigma:Float = 1, ?kernelSize:GaussianKernelSize = X3) { + public static function laplacianOfGaussianEdgeDetection(image:Image, ?threshold:Int = 2, ?filterPositive:Bool = true, ?sigma:Float = 1, ?kernelSize:GaussianKernelSize = X3):Image { return Laplace.laplacianOfGaussian(image, kernelSize, sigma, threshold, filterPositive); } @@ -1552,7 +1575,7 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-kmeansPosterize%28maxColorCount%20=%2016%29.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-kmeansPosterize%28maxColorCount%20=%208%29.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-kmeansPosterize%28maxColorCount%20=%204%29.png)| @param image The image to posterize - @param maxColorCount The amount of colors to use for the resulting image. At the algorithm's level, this also means the amount of color clusters to calculate. Defaults to `16` + @param maxColorCount The amount of colors to use for the resulting image. At the algorithm's level, this also means the amount of color clusters to calculate. Default is `16` @return A posterized version of the image. The original image is preserved **/ public static function kmeansPosterize(image:Image, maxColorCount:Int = 16):Image { @@ -1586,8 +1609,8 @@ class Vision { |![Before](https://spacebubble-io.pages.dev/vision/docs/valve-original.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-kmeansGroupImageColors%28groupCount%20=%2016%29.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-kmeansGroupImageColors%28groupCount%20=%208%29.png)|![After](https://spacebubble-io.pages.dev/vision/docs/valve-kmeansGroupImageColors%28groupCount%20=%204%29.png)| @param image The image to try color grouping on - @param groupCount The amount of color groups we want to find. The more groups, the more accurate the grouping will be, but only to a certain point (an image with only 4 distinct colors won't have more than 4 groups). Defaults to `16` - @param considerTransparency Whether or not to consider transparency in the grouping. Defaults to `false` + @param groupCount The amount of color groups we want to find. The more groups, the more accurate the grouping will be, but only to a certain point (an image with only 4 distinct colors won't have more than 4 groups). Default is `16` + @param considerTransparency Whether or not to consider transparency in the grouping. Default is `false` @return An array of color clusters. Each cluster contains both it's colors and the centroid used to group them. **/ public static function kmeansGroupImageColors(image:Image, groupCount:Int = 16, considerTransparency:Bool = false):Array { diff --git a/src/vision/algorithms/BilinearInterpolation.hx b/src/vision/algorithms/BilinearInterpolation.hx index 74f8b7d4..00d8d593 100644 --- a/src/vision/algorithms/BilinearInterpolation.hx +++ b/src/vision/algorithms/BilinearInterpolation.hx @@ -1,8 +1,6 @@ package vision.algorithms; import vision.ds.Color; -import vision.tools.ImageTools; -import vision.exceptions.OutOfBounds; import vision.ds.Image; import vision.tools.MathTools.*; diff --git a/src/vision/algorithms/Cramer.hx b/src/vision/algorithms/Cramer.hx index fbaa7b4d..c45b4b94 100644 --- a/src/vision/algorithms/Cramer.hx +++ b/src/vision/algorithms/Cramer.hx @@ -2,10 +2,7 @@ package vision.algorithms; import vision.exceptions.InvalidCramerSetup; import vision.exceptions.InvalidCramerCoefficientsMatrix; -import vision.tools.MathTools; import vision.ds.Matrix2D; -import haxe.ds.Vector; -import vision.ds.Array2D; /** Solve a system of linear equations using Cramer's rule. diff --git a/src/vision/algorithms/Gauss.hx b/src/vision/algorithms/Gauss.hx index ced34276..1d008d0d 100644 --- a/src/vision/algorithms/Gauss.hx +++ b/src/vision/algorithms/Gauss.hx @@ -115,7 +115,7 @@ class Gauss { return kernel; } @:deprecated("Gaussian.createKernelOfSize() is deprecated. use Gaussian.create2DKernelOfSize() instead") - public static function createKernelOfSize(size:Int, sigma:Int) { + public static function createKernelOfSize(size:Int, sigma:Int):Array2D { return create2DKernelOfSize(size, sigma); } @@ -172,7 +172,7 @@ class Gauss { return kernel; } - public static function fastBlur(image:Image, size:Int, sigma:Float) { + public static function fastBlur(image:Image, size:Int, sigma:Float):Image { var preprocessed = image.clone(); #if vision_quiet if (size <= 0) size = -size; diff --git a/src/vision/algorithms/ImageHashing.hx b/src/vision/algorithms/ImageHashing.hx index 09cd2307..13b46982 100644 --- a/src/vision/algorithms/ImageHashing.hx +++ b/src/vision/algorithms/ImageHashing.hx @@ -2,10 +2,8 @@ package vision.algorithms; import haxe.Int64; import vision.ds.Matrix2D; -import vision.tools.ImageTools; import vision.ds.ByteArray; import vision.ds.Image; -import vision.ds.ImageResizeAlgorithm; using vision.tools.MathTools; @@ -32,7 +30,7 @@ class ImageHashing { } } - return clone.toBytes(); + return clone.exportToBytes(); } public static function phash(image:Image):ByteArray { diff --git a/src/vision/algorithms/KMeans.hx b/src/vision/algorithms/KMeans.hx index 3b2323cf..28edc125 100644 --- a/src/vision/algorithms/KMeans.hx +++ b/src/vision/algorithms/KMeans.hx @@ -9,8 +9,7 @@ using vision.tools.MathTools; using vision.tools.ArrayTools; class KMeans { - public static function generateClustersUsingConvergence(values:Array, clusterAmount:Int, distanceFunction:(T, T) -> Float, - averageFunction:Array->T):Array> { + public static function generateClustersUsingConvergence(values:Array, clusterAmount:Int, distanceFunction:(T, T) -> Float, averageFunction:Array->T):Array> { var clusterCenters = pickElementsAtRandom(values, clusterAmount, true); // We don't use clusterAmount in case where the image doesnt have enough distinct colors to satisfy diff --git a/src/vision/algorithms/Laplace.hx b/src/vision/algorithms/Laplace.hx index 888a1ff4..0a52c86d 100644 --- a/src/vision/algorithms/Laplace.hx +++ b/src/vision/algorithms/Laplace.hx @@ -7,7 +7,7 @@ import vision.ds.Image; class Laplace { - public static function convolveWithLaplacianOperator(image:Image, positive:Bool) { + public static function convolveWithLaplacianOperator(image:Image, positive:Bool):Image { var edgeColors:Image = new Image(image.width, image.height); for (i in 0...image.width) { @@ -28,7 +28,7 @@ class Laplace { return edgeColors; } - public static function laplacianOfGaussian(image:Image, kernelSize:GaussianKernelSize, sigma:Float, threshold:Float, positive:Bool) { + public static function laplacianOfGaussian(image:Image, kernelSize:GaussianKernelSize, sigma:Float, threshold:Float, positive:Bool):Image { var returned = new Image(image.width, image.height); var blurred = Vision.gaussianBlur(image.clone().removeView(), sigma, kernelSize); var imageToProcess:Image; diff --git a/src/vision/algorithms/Perwitt.hx b/src/vision/algorithms/Perwitt.hx index 9a08c988..b640d6e9 100644 --- a/src/vision/algorithms/Perwitt.hx +++ b/src/vision/algorithms/Perwitt.hx @@ -11,7 +11,7 @@ using vision.tools.MathTools; * by [Shahar Marcus](https://www.github.com/ShaharMS) */ class Perwitt { - public static function convolveWithPerwittOperator(image:Image) { + public static function convolveWithPerwittOperator(image:Image):Image { var edgeColors:Image = new Image(image.width, image.height); var maxGradient = -1; @@ -39,7 +39,7 @@ class Perwitt { if (gradient > maxGradient) maxGradient = gradient; final rgb:Int = Std.int(gradient * (255 / maxGradient)); - //turn into ARGB + // turn into ARGB edgeColors.setPixel(i, j, 0xff000000 | (rgb << 16) | (rgb << 8) | rgb); } } @@ -62,6 +62,7 @@ class Perwitt { } // If you came here for the explanation of the algorithm, Congrats! learning is fun :D + /** What does this algorithm do? Basically, it takes 9 pixels chunks each time it performs a calculation, and tries to see how different the @@ -82,38 +83,36 @@ class Perwitt { Now, if this value is greater than the threshold, then we declare it an edge. now, were gonna do the same thing for all chunks of the image, and from top to bottom too if needed. **/ - public static function detectEdges(image:Image, threshold:Float) { - - - var edges = new Image(image.width, image.height, Color.fromRGBA(0, 0, 0)); - var blackAndWhite = Vision.grayscale(image.clone()); - for (x in 0...blackAndWhite.width) { - for (y in 0...blackAndWhite.height) { - var neighbors = [ - blackAndWhite.getSafePixel(x - 1, y - 1), - blackAndWhite.getSafePixel(x, y - 1), - blackAndWhite.getSafePixel(x + 1, y - 1), - blackAndWhite.getSafePixel(x - 1, y), - blackAndWhite.getSafePixel(x, y), - blackAndWhite.getSafePixel(x + 1, y), - blackAndWhite.getSafePixel(x - 1, y + 1), - blackAndWhite.getSafePixel(x, y + 1), - blackAndWhite.getSafePixel(x + 1, y + 1) - ]; - final perwittCalculationIterationLTR = neighbors[0].red * -1 - + neighbors[3].red * -1 + neighbors[6].red * -1 + neighbors[2].red * 1 + neighbors[5].red * 1 + neighbors[8].red * 1; - if (Math.abs(perwittCalculationIterationLTR) > threshold) { - edges.setPixel(x, y, Color.fromRGBA(255, 255, 255)); - continue; - } - final perwittCalculationIterationTTB = neighbors[0].red * -1 - + neighbors[1].red * -1 + neighbors[2].red * -1 + neighbors[6].red * 1 + neighbors[7].red * 1 + neighbors[8].red * 1; - if (Math.abs(perwittCalculationIterationTTB) > threshold) { - edges.setPixel(x, y, Color.fromRGBA(255, 255, 255)); - continue; - } + public static function detectEdges(image:Image, threshold:Float):Image { + var edges = new Image(image.width, image.height, Color.fromRGBA(0, 0, 0)); + var blackAndWhite = Vision.grayscale(image.clone()); + for (x in 0...blackAndWhite.width) { + for (y in 0...blackAndWhite.height) { + var neighbors = [ + blackAndWhite.getSafePixel(x - 1, y - 1), + blackAndWhite.getSafePixel(x, y - 1), + blackAndWhite.getSafePixel(x + 1, y - 1), + blackAndWhite.getSafePixel(x - 1, y), + blackAndWhite.getSafePixel(x, y), + blackAndWhite.getSafePixel(x + 1, y), + blackAndWhite.getSafePixel(x - 1, y + 1), + blackAndWhite.getSafePixel(x, y + 1), + blackAndWhite.getSafePixel(x + 1, y + 1) + ]; + final perwittCalculationIterationLTR = neighbors[0].red * -1 + + neighbors[3].red * -1 + neighbors[6].red * -1 + neighbors[2].red * 1 + neighbors[5].red * 1 + neighbors[8].red * 1; + if (Math.abs(perwittCalculationIterationLTR) > threshold) { + edges.setPixel(x, y, Color.fromRGBA(255, 255, 255)); + continue; + } + final perwittCalculationIterationTTB = neighbors[0].red * -1 + + neighbors[1].red * -1 + neighbors[2].red * -1 + neighbors[6].red * 1 + neighbors[7].red * 1 + neighbors[8].red * 1; + if (Math.abs(perwittCalculationIterationTTB) > threshold) { + edges.setPixel(x, y, Color.fromRGBA(255, 255, 255)); + continue; } } - return edges; + } + return edges; } } diff --git a/src/vision/algorithms/Radix.hx b/src/vision/algorithms/Radix.hx index f85c91ab..68899407 100644 --- a/src/vision/algorithms/Radix.hx +++ b/src/vision/algorithms/Radix.hx @@ -84,7 +84,7 @@ class Radix { /** Sorts an array of `Int`s / `UInt`s / `Int64` using **Radix Sort**. **/ - public static overload extern inline function sort(main:Array) { + overload extern public static inline function sort(main:Array):Array { var negatives = [], positives = []; for (i in 0...main.length) { @@ -113,7 +113,7 @@ class Radix { return main = negatives.concat(positives); } - public static overload extern inline function sort(main:Array) { + overload extern public static inline function sort(main:Array):Array { // Find the maximum number to know the number of digits final max = getMax(main, main.length); var exp = 1; @@ -129,7 +129,7 @@ class Radix { return main; } - public static overload extern inline function sort(main:Array) { + overload extern public static inline function sort(main:Array):Array { var negatives = [], positives = []; for (i in 0...main.length) { diff --git a/src/vision/algorithms/RobertsCross.hx b/src/vision/algorithms/RobertsCross.hx index 0bc7941f..50193b70 100644 --- a/src/vision/algorithms/RobertsCross.hx +++ b/src/vision/algorithms/RobertsCross.hx @@ -13,7 +13,7 @@ import vision.ds.Image; **/ class RobertsCross { - public static function convolveWithRobertsCross(image:Image) { + public static function convolveWithRobertsCross(image:Image):Image { var edgeColors:Image = new Image(image.width, image.height); var maxGradient = -1; diff --git a/src/vision/algorithms/SimpleHough.hx b/src/vision/algorithms/SimpleHough.hx index dd897c52..8c8bf4c7 100644 --- a/src/vision/algorithms/SimpleHough.hx +++ b/src/vision/algorithms/SimpleHough.hx @@ -34,7 +34,7 @@ class SimpleHough { return rays; } - public static function mapLines(image:Image, rays:Array) { + public static function mapLines(image:Image, rays:Array):Image { for (ray in rays) { image.drawRay2D(ray, Color.CYAN); } diff --git a/src/vision/algorithms/SimpleLineDetector.hx b/src/vision/algorithms/SimpleLineDetector.hx index 0192559a..cb8efa89 100644 --- a/src/vision/algorithms/SimpleLineDetector.hx +++ b/src/vision/algorithms/SimpleLineDetector.hx @@ -174,7 +174,7 @@ class SimpleLineDetector { return lines; } - static extern inline function p(x:Int = 0, y:Int = 0) { + static extern inline function p(x:Int = 0, y:Int = 0):Int16Point2D { return new Int16Point2D(x, y); } diff --git a/src/vision/algorithms/Sobel.hx b/src/vision/algorithms/Sobel.hx index 9f1128cd..8af7b715 100644 --- a/src/vision/algorithms/Sobel.hx +++ b/src/vision/algorithms/Sobel.hx @@ -11,7 +11,7 @@ using vision.tools.MathTools; by [Shahar Marcus](https://www.github.com/ShaharMS) **/ class Sobel { - public static function convolveWithSobelOperator(image:Image) { + public static function convolveWithSobelOperator(image:Image):Image { var edgeColors:Image = new Image(image.width, image.height); var maxGradient = -1; @@ -68,7 +68,7 @@ class Sobel { If this value is greater than the threshold, then we declare it an edge. now, were gonna do the same thing for all chunks of the image, and from top to bottom too if needed. **/ - public static function detectEdges(image:Image, threshold:Float) { + public static function detectEdges(image:Image, threshold:Float):Image { final edges = new Image(image.width, image.height, Color.fromRGBA(0, 0, 0)); final blackAndWhite = Vision.grayscale(image.clone()); for (x in 0...blackAndWhite.width) { diff --git a/src/vision/ds/Array2D.hx b/src/vision/ds/Array2D.hx index e43d73c1..32929e2c 100644 --- a/src/vision/ds/Array2D.hx +++ b/src/vision/ds/Array2D.hx @@ -1,5 +1,6 @@ package vision.ds; +import haxe.iterators.ArrayIterator; #if !vision_fancy_array_access /** A 2D array, faster than an `Array>`. @@ -106,7 +107,7 @@ class Array2D { `(x, y)...(x + 5, y) -> (x, y + 1)...(x + 5, y + 1) -> (x, y + 2)...` **/ - public inline function iterator() { + public inline function iterator():ArrayIterator { return inner.iterator(); } diff --git a/src/vision/ds/ByteArray.hx b/src/vision/ds/ByteArray.hx index e9ec41ec..77e1970c 100644 --- a/src/vision/ds/ByteArray.hx +++ b/src/vision/ds/ByteArray.hx @@ -3,7 +3,6 @@ package vision.ds; import haxe.Int64; import vision.tools.MathTools; import haxe.Serializer; -import haxe.io.BytesData; import haxe.io.Bytes; /** @@ -18,13 +17,13 @@ abstract ByteArray(Bytes) from Bytes to Bytes { @param value The given integer @return The resulting `ByteArray` **/ - overload extern inline public static function from(value:Int):ByteArray { + overload extern public static inline function from(value:Int):ByteArray { var bytes = new ByteArray(4); bytes.setInt32(0, value); return bytes; } - overload extern inline public static function from(value:Int64):ByteArray { + overload extern public static inline function from(value:Int64):ByteArray { var bytes = new ByteArray(8); bytes.setInt64(0, value); return bytes; @@ -36,7 +35,7 @@ abstract ByteArray(Bytes) from Bytes to Bytes { @param value The given float @return The resulting `ByteArray` **/ - overload extern inline public static function from(value:Float):ByteArray { + overload extern public static inline function from(value:Float):ByteArray { var bytes = new ByteArray(8); bytes.setDouble(0, value); return bytes; @@ -46,7 +45,7 @@ abstract ByteArray(Bytes) from Bytes to Bytes { If `value` is `true`, generates a byte array of length 1, containing 1. If `value` is `false`, generates a byte array of length 1, containing 0. **/ - overload extern inline public static function from(value:Bool):ByteArray { + overload extern public static inline function from(value:Bool):ByteArray { return value ? new ByteArray(1, 1) : new ByteArray(1, 0); } @@ -54,10 +53,11 @@ abstract ByteArray(Bytes) from Bytes to Bytes { Encodes the given string into a byte array. `UTF-8` encoding is used by default. If you want to use another type of encoding, provide the second parameter. @param value The given string + @param encoding The encoding to use @return The resulting `ByteArray` **/ - overload extern inline public static function from(value:String, ?encoding:haxe.io.Encoding):ByteArray { - return Bytes.ofString(value); + overload extern public static inline function from(value:String, ?encoding:haxe.io.Encoding):ByteArray { + return Bytes.ofString(value, encoding); } /** @@ -66,14 +66,29 @@ abstract ByteArray(Bytes) from Bytes to Bytes { @param value The given object @return The resulting `ByteArray` **/ - overload extern inline public static function from(value:Dynamic):ByteArray { + overload extern public static inline function from(value:Dynamic):ByteArray { return Bytes.ofString(Serializer.run(value)); } + /** + * Takes an array of numbers of any type, and turns it into a byte array. + * @param value An array of UInts/Ints + * @param itemSize The amount of bytes to capture from each item. Default is `1`, which captures only the first byte + */ + overload extern public static inline function from(value:Array, itemSize:Int = 1) { + var bytes = new ByteArray(0); + for (item in value) { + var itemBytes = ByteArray.from(item); + itemBytes.resize(itemSize); + bytes = bytes.concat(itemBytes); + } + return bytes; + } + /** Reads a byte at the specified index **/ - @:op([]) inline function read(index:Int) { + @:op([]) inline function read(index:Int):Int { return this.get(index); } @@ -160,10 +175,10 @@ abstract ByteArray(Bytes) from Bytes to Bytes { } /** - Concatenates a byte array to this one. **Pay Attention** - + Concatenates a byte array to this one. @param array the array to concatenate. - @return a new `ByteArray`. + @return a new `ByteArray`, containing the concatenation **/ public inline function concat(array:ByteArray):ByteArray { var newBytes = Bytes.alloc(this.length + array.length); diff --git a/src/vision/ds/Color.hx b/src/vision/ds/Color.hx index fa5b36c6..6ae7c42e 100644 --- a/src/vision/ds/Color.hx +++ b/src/vision/ds/Color.hx @@ -608,7 +608,7 @@ abstract Color(Int) from Int from UInt to Int to UInt { @param Value The channel value of the red, green & blue channels of the color @return The color as a `Color` **/ - public static inline function from8Bit(Value:Int) { + public static inline function from8Bit(Value:Int):Color { var color = new Color(); return color.setRGBA(Value, Value, Value, 1); } @@ -619,7 +619,7 @@ abstract Color(Int) from Int from UInt to Int to UInt { @param Value The channel value of the red, green & blue channels of the color @return The color as a `Color` **/ - public static inline function fromFloat(Value:Float) { + public static inline function fromFloat(Value:Float):Color { return fromRGBAFloat(Value, Value, Value, 1); } @@ -768,7 +768,7 @@ abstract Color(Int) from Int from UInt to Int to UInt { @param alphaLock When set to `false`, the alpha channel will get a randomized value to. `true` by default, which makes a color with `alpha = 255`. @param alphaValue When `alphaLock` is true, you can provide this value to override the default alpha value. Since the first argument is optional, you can do `Color.makeRandom(128)` (a random color with `alpha` set to `128`) **/ - public static inline function makeRandom(?alphaLock:Bool = true, alphaValue:Int = 255) { + public static inline function makeRandom(?alphaLock:Bool = true, alphaValue:Int = 255):Color { return Color.fromRGBAFloat(Math.random(), Math.random(), Math.random(), if (alphaLock) alphaValue else Math.random()); } @@ -826,7 +826,7 @@ abstract Color(Int) from Int from UInt to Int to UInt { return diff / (considerTransparency ? 2 : MathTools.SQRT3); } - public static inline function getAverage(fromColors:Array, considerTransparency:Bool = true) { + public static inline function getAverage(fromColors:Array, considerTransparency:Bool = true):Color { var reds = [], blues = [], greens = [], alphas = []; for (color in fromColors) { reds.push(color.redFloat); diff --git a/src/vision/ds/Image.hx b/src/vision/ds/Image.hx index de07cce5..4b5fe22d 100644 --- a/src/vision/ds/Image.hx +++ b/src/vision/ds/Image.hx @@ -1,20 +1,19 @@ package vision.ds; -import vision.algorithms.GaussJordan; -import vision.ds.Matrix2D; -import haxe.Resource; +import vision.formats.ImageIO; import vision.ds.ByteArray; import vision.exceptions.Unimplemented; -import vision.tools.MathTools; -import vision.algorithms.BilinearInterpolation; +import vision.algorithms.BilinearInterpolation as Bilinear; // Avoid naming collisions with ImageResizeAlgorithm import haxe.ds.List; import haxe.Int64; import vision.ds.Color; +import vision.ds.Rectangle; +import vision.ds.ImageView; +import vision.ds.ImageResizeAlgorithm; import vision.exceptions.OutOfBounds; import vision.tools.ImageTools; using vision.tools.MathTools; using vision.tools.ArrayTools; -import vision.tools.MathTools.*; /** Represents a 2D image, as a matrix of Colors. @@ -521,6 +520,20 @@ abstract Image(ByteArray) { return image.copyPixelFrom(cast this, x, y); } + /** + Copies an image's graphics data, while retaining this image's `ImageView` + + @param image The image to copy data from + @returns This image + **/ + public inline function copyImageFrom(image:Image):Image { + var currentView = getView(); + this.resize(image.underlying.length); + this.blit(0, image.underlying, 0, image.underlying.length); + setView(currentView); + return cast this; + } + /** Returns a portion of the image, specified by a rectangle. @@ -1101,7 +1114,7 @@ abstract Image(ByteArray) { algorithm = ImageTools.defaultResizeAlgorithm; switch algorithm { case BilinearInterpolation: - this = cast BilinearInterpolation.interpolate(cast this, newWidth, newHeight); + this = cast Bilinear.interpolate(cast this, newWidth, newHeight); case BicubicInterpolation: throw new Unimplemented("Bicubic Interpolation"); case NearestNeighbor: @@ -1423,95 +1436,95 @@ abstract Image(ByteArray) { //-------------------------------------------------------------------------- #if flixel @:to public function toFlxSprite():flixel.FlxSprite { - return ImageTools.toFlxSprite(cast this); + return ImageIO.to.framework.flixel.flxsprite(cast this); } @:from public static function fromFlxSprite(sprite:flixel.FlxSprite):Image { - return ImageTools.fromFlxSprite(sprite); + return ImageIO.from.framework.flixel.flxsprite(sprite); } #end - #if openfl + #if (openfl || flash) @:to public function toBitmapData():flash.display.BitmapData { - return ImageTools.toBitmapData(cast this); + return ImageIO.to.framework.flash.bitmapdata(cast this); } @:from public static function fromBitmapData(bitmapData:flash.display.BitmapData):Image { - return ImageTools.fromBitmapData(bitmapData); + return ImageIO.from.framework.flash.bitmapdata(bitmapData); } - @:to public function toShape():openfl.display.Shape { - return ImageTools.toShape(cast this); + @:to public function toShape():flash.display.Shape { + return ImageIO.to.framework.flash.shape(cast this); } @:from public static function fromShape(shape:flash.display.Shape):Image { - return ImageTools.fromShape(shape); + return ImageIO.from.framework.flash.shape(shape); } @:to public function toSprite():flash.display.Sprite { - return ImageTools.toSprite(cast this); + return ImageIO.to.framework.flash.sprite(cast this); } @:from public static function fromSprite(sprite:flash.display.Sprite):Image { - return ImageTools.fromSprite(sprite); + return ImageIO.from.framework.flash.sprite(sprite); } #end #if lime @:to public function toLimeImage():lime.graphics.Image { - return ImageTools.toLimeImage(cast this); + return ImageIO.to.framework.lime.image(cast this); } @:from public static function fromLimeImage(image:lime.graphics.Image):Image { - return ImageTools.fromLimeImage(image); + return ImageIO.from.framework.lime.image(image); } #end #if kha @:from public static function fromKhaImage(image:kha.Image):Image { - return ImageTools.fromKhaImage(image); + return ImageIO.from.framework.kha.image(image); } #end #if heaps @:from public static function fromHeapsPixels(pixels:hxd.Pixels):Image { - return ImageTools.fromHeapsPixels(pixels); + return ImageIO.from.framework.heaps.pixels(pixels); } @:to public function toHeapsPixels():hxd.Pixels { - return ImageTools.toHeapsPixels(cast this); + return ImageIO.to.framework.heaps.pixels(cast this); } #end #if js @:from public static function fromJsCanvas(canvas:js.html.CanvasElement):Image { - return ImageTools.fromJsCanvas(canvas); + return ImageIO.from.framework.js.canvas(canvas); } @:to public function toJsCanvas():js.html.CanvasElement { - return ImageTools.toJsCanvas(cast this); + return ImageIO.to.framework.js.canvas(cast this); } @:from public static function fromJsImage(image:js.html.ImageElement):Image { - return ImageTools.fromJsImage(image); + return ImageIO.from.framework.js.image(image); } @:to public function toJsImage():js.html.ImageElement { - return ImageTools.toJsImage(cast this); + return ImageIO.to.framework.js.image(cast this); } #end #if haxeui_core @:from public static function fromHaxeUIImage(image:haxe.ui.components.Image):Image { - return ImageTools.fromHaxeUIImage(image); + return ImageIO.from.framework.haxeui.image(image); } @:to public function toHaxeUIImage():haxe.ui.components.Image { - return ImageTools.toHaxeUIImage(cast this); + return ImageIO.to.framework.haxeui.image(cast this); } @:from public static function fromHaxeUIImageData(image:haxe.ui.backend.ImageData):Image { - return ImageTools.fromHaxeUIImageData(image); + return ImageIO.from.framework.haxeui.imagedata(image); } @:to public function toHaxeUIImageData():haxe.ui.backend.ImageData { - return ImageTools.toHaxeUIImageData(cast this); + return ImageIO.to.framework.haxeui.imagedata(cast this); } #end @@ -1584,7 +1597,7 @@ abstract Image(ByteArray) { @param width The width of the returned image. @param height Optional, the height of the returned image. determined automatically, can be overridden by setting this parameter **/ - public static inline function fromBytes(bytes:ByteArray, width:Int, ?height:Int) { + public static inline function loadFromBytes(bytes:ByteArray, width:Int, ?height:Int):Image { var h = height != null ? height : (bytes.length / 4 / width).ceil(); var array = new ByteArray(width * h * 4 + OFFSET); array.fill(0, array.length, 0); @@ -1604,7 +1617,7 @@ abstract Image(ByteArray) { Returns a `ByteArray` of format `ARGB` of the pixels of this image. @return A new `ByteArray` **/ - @:to overload public extern inline function toBytes():ByteArray { + @:to overload public extern inline function exportToBytes():ByteArray { return underlying.sub(OFFSET, underlying.length - OFFSET); } @@ -1613,7 +1626,7 @@ abstract Image(ByteArray) { @param colorFormat The wanted color format of the returned `ByteArray`. @return A new `ByteArray` **/ - overload public extern inline function toBytes(?colorFormat:PixelFormat = ARGB) { + overload public extern inline function exportToBytes(?colorFormat:PixelFormat = ARGB):ByteArray { return inline PixelFormat.convertPixelFormat(underlying.sub(OFFSET, underlying.length - OFFSET), ARGB, colorFormat); } diff --git a/src/vision/ds/ImageFormat.hx b/src/vision/ds/ImageFormat.hx index 7633e3f9..36303bda 100644 --- a/src/vision/ds/ImageFormat.hx +++ b/src/vision/ds/ImageFormat.hx @@ -14,4 +14,23 @@ enum abstract ImageFormat(Int) { BMP encoding **/ var BMP; + + /** + JPEG encoding + **/ + var JPEG; + + /** + Raw `vision.ds.Image` bytes + **/ + var VISION; + + @:from public static function fromString(type:String):ImageFormat { + return switch type.toLowerCase() { + case "png": PNG; + case "bmp": BMP; + case "jpeg" | "jpg": JPEG; + default: VISION; + } + } } \ No newline at end of file diff --git a/src/vision/ds/ImageView.hx b/src/vision/ds/ImageView.hx index 76e983f9..734a938b 100644 --- a/src/vision/ds/ImageView.hx +++ b/src/vision/ds/ImageView.hx @@ -1,5 +1,7 @@ package vision.ds; +import vision.ds.ImageViewShape; + @:structInit class ImageView { /** @@ -25,7 +27,7 @@ class ImageView { **/ @:optional public var shape:ImageViewShape = RECTANGLE; - public function toString() { + public function toString():String { return '{shape: $shape, x: $x, y: $y, width: $width, height: $height}'; } } \ No newline at end of file diff --git a/src/vision/ds/IntPoint2D.hx b/src/vision/ds/IntPoint2D.hx index 5b22a9b1..1d57ea44 100644 --- a/src/vision/ds/IntPoint2D.hx +++ b/src/vision/ds/IntPoint2D.hx @@ -9,12 +9,12 @@ private typedef Impl = haxe.Int64; #else @:structInit private class Impl { - public var x:Int; - public var y:Int; + public var high:Int; + public var low:Int; public inline function new(x:Int, y:Int) { - this.x = x; - this.y = y; + high = x; + low = y; } } #end @@ -43,58 +43,42 @@ abstract IntPoint2D(Impl) { } inline function get_y() { - #if (((hl_ver >= version("1.12.0") && !hl_legacy32) || cpp || cs) && !vision_disable_point_alloc_optimization) return this.low; - #else - return this.y; - #end } inline function get_x() { - #if (((hl_ver >= version("1.12.0") && !hl_legacy32) || cpp || cs) && !vision_disable_point_alloc_optimization) return this.high; - #else - return this.x; - #end } inline function set_y(y:Int):Int { - #if (((hl_ver >= version("1.12.0") && !hl_legacy32) || cpp || cs) && !vision_disable_point_alloc_optimization) - this = Int64.make(x, y); - #else - this.y = y; - #end + this.low = y; return y; } - inline function set_x(x:Int) { - #if (((hl_ver >= version("1.12.0") && !hl_legacy32) || cpp || cs) && !vision_disable_point_alloc_optimization) - this = Int64.make(x, y); - #else - this.x = x; - #end + inline function set_x(x:Int):Int { + this.high = x; return x; } - @:to public inline function toPoint2D() { + @:to public inline function toPoint2D():Point2D { return new Point2D(x, y); } - @:from public static inline function fromPoint2D(p:Point2D) { + @:from public static inline function fromPoint2D(p:Point2D):IntPoint2D { return new IntPoint2D(Std.int(p.x), Std.int(p.y)); } /** Returns a `String` representations of this `IntPoint2D`. **/ - public inline function toString() { + public inline function toString():String { return '($x, $y)'; } /** Returns a new `IntPoint2D` instance, similar to this one. **/ - public inline function copy() { + public inline function copy():IntPoint2D { return new IntPoint2D(x, y); } diff --git a/src/vision/ds/Line2D.hx b/src/vision/ds/Line2D.hx index bdbf5e89..6317afa1 100644 --- a/src/vision/ds/Line2D.hx +++ b/src/vision/ds/Line2D.hx @@ -87,7 +87,7 @@ class Line2D { Returns a `String` representation of this `Line2D`. **/ @:keep - public inline function toString() { + public inline function toString():String { return '\n (${start.x}, ${start.y}) --> (${end.x}, ${end.y})'; } @@ -111,14 +111,14 @@ class Line2D { return new Ray2D(this.start, this.slope); } - inline function set_start(value:Point2D) { + inline function set_start(value:Point2D):Point2D { radians = MathTools.radiansFromPointToPoint2D(value, end); slope = MathTools.radiansToSlope(radians); degrees = MathTools.radiansToDegrees(radians); return start = value; } - inline function set_end(value:Point2D) { + inline function set_end(value:Point2D):Point2D { radians = MathTools.radiansFromPointToPoint2D(value, end); slope = MathTools.radiansToSlope(radians); degrees = MathTools.radiansToDegrees(radians); diff --git a/src/vision/ds/Matrix2D.hx b/src/vision/ds/Matrix2D.hx index f6b97bb2..a761844b 100644 --- a/src/vision/ds/Matrix2D.hx +++ b/src/vision/ds/Matrix2D.hx @@ -2,7 +2,6 @@ package vision.ds; import vision.algorithms.PerspectiveWarp; import vision.ds.specifics.PointTransformationPair; -import haxe.exceptions.NotImplementedException; import vision.exceptions.MatrixOperationError; import vision.algorithms.GaussJordan; import vision.ds.Array2D; @@ -329,7 +328,7 @@ abstract Matrix2D(Array2D) to Array2D from Array2D { @param pretty Whether to return a pretty-print of the matrix or not. A pretty print adds a distinct matrix border, centered numbers, and ellipsis where numbers are truncated. **/ - public inline function toString(precision:Int = 5, pretty:Bool = true) { + public inline function toString(precision:Int = 5, pretty:Bool = true):String { if (!pretty) return this.toString(); // Get the longest item, this will be the cell width @@ -519,7 +518,7 @@ abstract Matrix2D(Array2D) to Array2D from Array2D { @param z Displacement in pixels to the back. @param towards The point the graphic goes towards, as in, when `z` approaches positive infinity, the graphic goes towards that point. Defaults to `(0, 0)`. **/ - public static inline function DEPTH(z:Float, ?towards:Point2D) { + public static inline function DEPTH(z:Float, ?towards:Point2D):TransformationMatrix2D { return Matrix2D.createTransformation( [1, 0, towards != null ? towards.x * (z - 1) : 0], [0, 1, towards != null ? towards.y * (z - 1) : 0], @@ -658,7 +657,7 @@ abstract Matrix2D(Array2D) to Array2D from Array2D { return cast this; } - @:op(A += B) public inline function add(b:Matrix2D) { + @:op(A += B) public inline function add(b:Matrix2D):Matrix2D { if (rows != b.rows || columns != b.columns) { throw new MatrixOperationError("add", [this, b], Add_MismatchingDimensions); } @@ -672,7 +671,7 @@ abstract Matrix2D(Array2D) to Array2D from Array2D { return cast this; } - @:op(A -= B) public inline function subtract(b:Matrix2D) { + @:op(A -= B) public inline function subtract(b:Matrix2D):Matrix2D { if (rows != b.rows || columns != b.columns) { throw new MatrixOperationError("sub", [this, b], Sub_MismatchingDimensions); diff --git a/src/vision/ds/Point3D.hx b/src/vision/ds/Point3D.hx index 5a4747e1..93e3ba59 100644 --- a/src/vision/ds/Point3D.hx +++ b/src/vision/ds/Point3D.hx @@ -42,21 +42,21 @@ class Point3D { @param point The second point to calculate the distance to @return A `Float` representing the distance. `0` if `this` and `point` are congruent. **/ - public function distanceTo(point:Point3D) { + public function distanceTo(point:Point3D):Float { return MathTools.distanceBetweenPoints(this, point); } /** Returns a new `Point3D` instance, similar to this one. **/ - public function copy() { + public function copy():Point3D { return new Point3D(x, y, z); } /** Returns a `String` representations of this `Point3D`. **/ - public function toString() { + public function toString():String { return '($x, $y, $z)'; } } \ No newline at end of file diff --git a/src/vision/ds/Queue.hx b/src/vision/ds/Queue.hx index c8c4e00f..64c5a2e8 100644 --- a/src/vision/ds/Queue.hx +++ b/src/vision/ds/Queue.hx @@ -1,24 +1,5 @@ package vision.ds; -#if (flash || cpp) @:generic #end -class QueueCell { - public var previous:QueueCell; - - public var value:T; - - public var next:QueueCell; - - public function new(value:T, next:QueueCell, previous:QueueCell) { - this.previous = previous; - this.value = value; - this.next = next; - } - - @:to @:noCompletion public function getValue():T { - return value; - } -} - /** Represents a queue, as a doubly linked list. **/ diff --git a/src/vision/ds/QueueCell.hx b/src/vision/ds/QueueCell.hx new file mode 100644 index 00000000..f8eb7e37 --- /dev/null +++ b/src/vision/ds/QueueCell.hx @@ -0,0 +1,20 @@ +package vision.ds; + +#if (flash || cpp) @:generic #end +class QueueCell { + public var previous:QueueCell; + + public var value:T; + + public var next:QueueCell; + + public function new(value:T, next:QueueCell, previous:QueueCell) { + this.previous = previous; + this.value = value; + this.next = next; + } + + @:to @:noCompletion public function getValue():T { + return value; + } +} \ No newline at end of file diff --git a/src/vision/ds/Ray2D.hx b/src/vision/ds/Ray2D.hx index 953e9fa1..d6408539 100644 --- a/src/vision/ds/Ray2D.hx +++ b/src/vision/ds/Ray2D.hx @@ -68,7 +68,7 @@ class Ray2D { @param point1 First reference point, will be stored in the returned `Ray2D`'s `point` field. @param point2 Second reference point, used to calculate the slope of the ray. **/ - public static inline function from2Points(point1:Point2D, point2:Point2D) { + public static inline function from2Points(point1:Point2D, point2:Point2D):Ray2D { var s = (point2.y - point1.y) / (point2.x - point1.x); return new Ray2D(point1, s); } diff --git a/src/vision/ds/TransformationMatrix2D.hx b/src/vision/ds/TransformationMatrix2D.hx index f48d5257..a4cc1e24 100644 --- a/src/vision/ds/TransformationMatrix2D.hx +++ b/src/vision/ds/TransformationMatrix2D.hx @@ -1,6 +1,7 @@ package vision.ds; import vision.ds.Matrix2D; +import vision.ds.Point3D; @:forward.variance @:forward(getRow, getColumn, setRow, setColumn, map, clone, fill, toString) diff --git a/src/vision/formats/ImageIO.hx b/src/vision/formats/ImageIO.hx new file mode 100644 index 00000000..75072a24 --- /dev/null +++ b/src/vision/formats/ImageIO.hx @@ -0,0 +1,20 @@ +package vision.formats; + +import vision.formats.from.From; +import vision.formats.to.To; + +/** + A factory for loading/saving images to and from different file formats, frameworks and platforms. +**/ +class ImageIO { + + /** + Import a `vision.ds.Image` from different image formats + **/ + public static var from:From = new From(); + + /** + Export a `vision.ds.Image` to different image formats + **/ + public static var to:To = new To(); +} \ No newline at end of file diff --git a/src/vision/formats/__internal/FormatImageExporter.hx b/src/vision/formats/__internal/FormatImageExporter.hx new file mode 100644 index 00000000..ee0bf44f --- /dev/null +++ b/src/vision/formats/__internal/FormatImageExporter.hx @@ -0,0 +1,82 @@ +package vision.formats.__internal; + +import vision.ds.PixelFormat; +#if format +import vision.ds.ByteArray; +import haxe.io.BytesOutput; +import vision.ds.Image; +import vision.ds.ImageFormat; +import vision.exceptions.ImageSavingFailed; +import format.png.Writer as PngWriter; +import format.png.Tools as PngTools; +import format.bmp.Writer as BmpWriter; +import format.bmp.Tools as BmpTools; +import format.jpg.Writer as JpegWriter; +import format.jpg.Data as JpegData; + +@:access(vision.ds.Image) +class FormatImageExporter { + + /** + Exports an image to `PNG` + + @param image The image to export + @return The bytes of the exported image + @throws ImageSavingFailed If something goes wrong (for example, the image is invalid or device is out of memory) + **/ + public static function png(image:Image):ByteArray { + try { + var output = new BytesOutput(); + var writer = new PngWriter(output); + var data = PngTools.build32ARGB(image.width, image.height, image.underlying.sub(Image.OFFSET, image.underlying.length - Image.OFFSET)); + writer.write(data); + return output.getBytes(); + } catch (e) { + throw new ImageSavingFailed(ImageFormat.PNG, e.message); + } + } + + /** + Exports an image to `JPEG` + + @param image The image to export + @return The bytes of the exported image + @throws ImageSavingFailed If something goes wrong (for example, the image is invalid or device is out of memory) + **/ + public static function bmp(image:Image):ByteArray { + try { + var output = new BytesOutput(); + var writer = new BmpWriter(output); + var data = BmpTools.buildFromARGB(image.width, image.height, image.underlying.sub(Image.OFFSET, image.underlying.length - Image.OFFSET)); + writer.write(data); + return output.getBytes(); + } catch (e) { + throw new ImageSavingFailed(ImageFormat.BMP, e.message); + } + } + + /** + Exports an image to `JPEG` + + @param image The image to export + @return The bytes of the exported image + @throws ImageSavingFailed If something goes wrong (for example, the image is invalid or device is out of memory) + **/ + public static function jpeg(image:Image):ByteArray { + try { + var output = new BytesOutput(); + var writer = new JpegWriter(output); + var rawPixelData = PixelFormat.convertPixelFormat(image.underlying.sub(Image.OFFSET, image.underlying.length - Image.OFFSET), PixelFormat.ARGB, PixelFormat.RGB); + writer.write({ + pixels: rawPixelData, + width: image.width, + height: image.height, + quality: 1.0 + }); + return output.getBytes(); + } catch (e) { + throw new ImageSavingFailed(ImageFormat.JPEG, e.message); + } + } +} +#end diff --git a/src/vision/helpers/FormatImageLoader.hx b/src/vision/formats/__internal/FormatImageLoader.hx similarity index 96% rename from src/vision/helpers/FormatImageLoader.hx rename to src/vision/formats/__internal/FormatImageLoader.hx index 33e68521..9f1b79f0 100644 --- a/src/vision/helpers/FormatImageLoader.hx +++ b/src/vision/formats/__internal/FormatImageLoader.hx @@ -1,4 +1,4 @@ -package vision.helpers; +package vision.formats.__internal; #if format import haxe.io.BytesInput; import vision.ds.Image; @@ -51,7 +51,7 @@ class FormatImageLoader { @throws ImageLoadingFailed if the loaded image is not a BMP @throws ImageLoadingFailed if the BMP has incorrect header data, and reports it has more bytes than it should. **/ - public static function bmp(bytes:ByteArray) { + public static function bmp(bytes:ByteArray):Image { try { var reader = new BmpReader(new haxe.io.BytesInput(bytes)); var data = reader.read(); diff --git a/src/vision/formats/__internal/FrameworkImageIO.hx b/src/vision/formats/__internal/FrameworkImageIO.hx new file mode 100644 index 00000000..476ab036 --- /dev/null +++ b/src/vision/formats/__internal/FrameworkImageIO.hx @@ -0,0 +1,255 @@ +package vision.formats.__internal; + +import vision.ds.Image; +import vision.ds.ByteArray; + +@:access(vision.ds.Image) +class FrameworkImageIO { + #if flixel + public static function fromFlxSprite(sprite:flixel.FlxSprite):Image { + var image = new Image(Std.int(sprite.width), Std.int(sprite.height)); + if (sprite.pixels == null) { + lime.utils.Log.warn("FrameworkImageIO.fromFlxSprite() - The given sprite's bitmapData is null. An empty image is returned. Is the given FlxSprite not added?"); + return image; + } + for (x in 0...Std.int(sprite.width)) { + for (y in 0...Std.int(sprite.height)) { + image.setPixel(x, y, sprite.pixels.getPixel(x, y)); + } + } + return image; + } + + public static function toFlxSprite(image:Image):flixel.FlxSprite { + var sprite = new flixel.FlxSprite(0, 0); + sprite.makeGraphic(image.width, image.height, 0x00ffffff); + for (x in 0...image.width) { + for (y in 0...image.height) { + sprite.pixels.setPixel(x, y, image.getPixel(x, y)); + } + } + return sprite; + } + #end + + #if (openfl || flash) + public static function fromBitmapData(bitmapData:flash.display.BitmapData):Image { + var image = new Image(bitmapData.width, bitmapData.height); + for (x in 0...bitmapData.width) { + for (y in 0...bitmapData.height) { + image.setPixel(x, y, bitmapData.getPixel32(x, y)); + } + } + return image; + } + + public static function toBitmapData(image:Image):flash.display.BitmapData { + var bitmapData = new flash.display.BitmapData(image.width, image.height, true, 0x00000000); + for (x in 0...image.width) { + for (y in 0...image.height) { + bitmapData.setPixel32(x, y, image.getPixel(x, y)); + } + } + return bitmapData; + } + + public static function fromSprite(sprite:flash.display.Sprite):Image { + var bmp = new flash.display.BitmapData(Std.int(sprite.width), Std.int(sprite.height)); + bmp.draw(sprite); + return fromBitmapData(bmp); + } + + public static function toSprite(image:Image):flash.display.Sprite { + final bmp = toBitmapData(image); + var s = new flash.display.Sprite(); + s.addChild(new flash.display.Bitmap(bmp)); + return s; + } + + public static function fromShape(shape:flash.display.Shape):Image { + var bmp = new flash.display.BitmapData(Std.int(shape.width), Std.int(shape.height)); + bmp.draw(shape); + return fromBitmapData(bmp); + } + #end + + #if openfl + public static function toShape(image:Image):flash.display.Shape { + var s:openfl.display.Shape = cast toSprite(image); + var sh = new openfl.display.Shape(); + sh.graphics.drawGraphicsData(s.graphics.readGraphicsData()); + return sh; + } + #end + + #if lime + public static function fromLimeImage(limeImage:lime.graphics.Image):Image { + var image = new Image(limeImage.width, limeImage.height); + for (x in 0...image.width) { + for (y in 0...image.height) { + image.setPixel(x, y, limeImage.getPixel(x, y)); + } + } + return image; + } + + public static function toLimeImage(image:Image):lime.graphics.Image { + var limeImage = new lime.graphics.Image(image.width, image.height); + for (x in 0...image.width) { + for (y in 0...image.height) { + limeImage.setPixel(x, y, image.getPixel(x, y)); + } + } + return limeImage; + } + #end + + #if kha + public static function fromKhaImage(khaImage:kha.Image):Image { + var image = new Image(khaImage.width, khaImage.height); + for (x in 0...image.width) { + for (y in 0...image.height) { + image.setPixel(x, y, khaImage.at(x, y)); + } + } + return image; + } + #end + + #if heaps + public static function fromHeapsPixels(pixels:hxd.Pixels):Image { + var image = new Image(pixels.width, pixels.height); + switch pixels.format { + case ARGB: + default: + #if !vision_quiet + throw "pixels format must be in ARGB format, currently: " + pixels.format; + #end + } + for (x in 0...pixels.width) { + for (y in 0...pixels.height) { + image.setPixel(x, y, pixels.getPixel(x, y)); + } + } + return image; + } + + public static function toHeapsPixels(image:Image):hxd.Pixels { + var pixels = hxd.Pixels.alloc(image.width, image.height, ARGB); + for (x in 0...image.width) { + for (y in 0...pixels.height) { + pixels.setPixel(x, y, image.getPixel(x, y)); + } + } + return pixels; + } + #end + #if js + public static function fromJsCanvas(canvas:js.html.CanvasElement):Image { + var image:Image = Image.loadFromBytes(new ByteArray(Image.OFFSET + (canvas.width + canvas.height) * 4), canvas.width, canvas.height); + + final imageData = canvas.getContext2d().getImageData(0, 0, image.width, image.height); + + { + var i = 0; + while (i < imageData.data.length) { + for (o in 0...4) + image.underlying[i + (Image.OFFSET + 1) + o] = imageData.data[i + o]; + i += 4; + } + } + + return image; + } + + public static function toJsCanvas(image:Image):js.html.CanvasElement { + var c = js.Browser.document.createCanvasElement(); + + c.width = image.width; + c.height = image.height; + + var ctx = c.getContext2d(); + final imageData = ctx.getImageData(0, 0, image.width, image.height); + var data = imageData.data; + for (x in 0...image.width) { + for (y in 0...image.height) { + var i = (y * image.width + x) * 4; + for (o in 0...4) + data[i + o] = image.underlying[i + (Image.OFFSET + 1) + o]; + } + } + + ctx.putImageData(imageData, 0, 0); + + return c; + } + + public static function fromJsImage(image:js.html.ImageElement):Image { + var canvas = js.Browser.document.createCanvasElement(); + canvas.width = image.width; + canvas.height = image.height; + canvas.getContext2d().drawImage(image, 0, 0); + return fromJsCanvas(canvas); + } + + public static function toJsImage(image:Image):js.html.ImageElement { + var canvas = image.toJsCanvas(); + var htmlImage = js.Browser.document.createImageElement(); + htmlImage.src = canvas.toDataURL(); + return htmlImage; + } + #end + #if (haxeui_core && (haxeui_flixel || haxeui_openfl || haxeui_heaps || haxeui_html5)) + public static function fromHaxeUIImage(image:haxe.ui.components.Image):Image { + #if haxeui_flixel + return fromFlxSprite(image.resource); + #elseif haxeui_openfl + return fromBitmapData(image.resource); + #elseif haxeui_heaps + return fromHeapsPixels(image.resource); + #else + return fromJsImage(image.resource); + #end + } + + public static function toHaxeUIImage(image:Image):haxe.ui.components.Image { + var huiImage = new haxe.ui.components.Image(); + huiImage.width = image.width; + huiImage.height = image.height; + #if haxeui_flixel + huiImage.resource = toFlxSprite(image); + #elseif haxeui_openfl + huiImage.resource = toBitmapData(image); + #elseif haxeui_heaps + huiImage.resource = toHeapsPixels(image); + #else + huiImage.resource = toJsImage(image); + #end + return huiImage; + } + + public static function fromHaxeUIImageData(image:haxe.ui.backend.ImageData):Image { + #if haxeui_flixel + return fromFlxSprite(image); + #elseif haxeui_openfl + return fromBitmapData(image); + #elseif haxeui_heaps + return fromHeapsPixels(image); + #else + return fromJsImage(image); + #end + } + + public static function toHaxeUIImageData(image:Image):haxe.ui.backend.ImageData { + #if haxeui_flixel + return toFlxSprite(image); + #elseif haxeui_openfl + return fromBitmapData(image); + #elseif haxeui_heaps + return toHeapsPixels(image); + #else + return toJsImage(image); + #end + } + #end +} \ No newline at end of file diff --git a/src/vision/formats/__internal/JsImageExporter.js.hx b/src/vision/formats/__internal/JsImageExporter.js.hx new file mode 100644 index 00000000..3c1b87a2 --- /dev/null +++ b/src/vision/formats/__internal/JsImageExporter.js.hx @@ -0,0 +1,45 @@ +package vision.formats.__internal; + +import vision.ds.ImageFormat; +import haxe.crypto.Base64; +import haxe.io.Bytes; +import vision.ds.ByteArray; +import haxe.io.Path; +import js.Browser; +import vision.ds.Image; + +using vision.tools.ImageTools; +using StringTools; + +class JsImageExporter { + + public static function saveToFileAsync(image:Image, path:String, format:ImageFormat) { + var canvas = image.toJsCanvas(); + var streamType = imageFormatToStreamType(format); + var href = format != VISION ? + canvas.toDataURL(streamType, 1.0).replace(streamType, "application/octet-stream") : + 'data:application/octet-stream;base64,' + Base64.encode(saveToBytesSync(image, streamType)); + var link = Browser.document.createAnchorElement(); + link.download = Path.withoutDirectory(path); + link.href = href; + link.click(); + } + + public static function saveToBytesSync(image:Image, streamType:String):ByteArray { + var canvas = image.toJsCanvas(); + var dataURL = canvas.toDataURL(streamType, 1.0); + var base64Data = dataURL.substring(dataURL.indexOf(",") + 1); + return Base64.decode(base64Data); + + } + + public static function imageFormatToStreamType(format:ImageFormat):String { + return switch format { + case PNG: "image/png"; + case JPEG: "image/jpeg"; + case BMP: "image/bmp"; + case VISION: "application/octet-stream"; + } + } + +} \ No newline at end of file diff --git a/src/vision/formats/__internal/JsImageLoader.js.hx b/src/vision/formats/__internal/JsImageLoader.js.hx new file mode 100644 index 00000000..7173075c --- /dev/null +++ b/src/vision/formats/__internal/JsImageLoader.js.hx @@ -0,0 +1,107 @@ +package vision.formats.__internal; + +import haxe.io.Path; +import vision.exceptions.WebResponseError; +import vision.exceptions.ImageLoadingFailed; +import js.lib.Promise; +import js.Browser; +import js.html.URL; +import js.lib.Uint8Array; +import js.html.Blob; +import vision.ds.ByteArray; +import vision.ds.Image; + +using StringTools; + +class JsImageLoader { + + public static function loadAsync(path:String, source:Image, callback:(Image) -> Void) { + var imgElement = js.Browser.document.createImageElement(); + imgElement.src = path; + imgElement.crossOrigin = "Anonymous"; + imgElement.onload = () -> { + var canvas = js.Browser.document.createCanvasElement(); + + canvas.width = imgElement.width; + canvas.height = imgElement.height; + + canvas.getContext2d().drawImage(imgElement, 0, 0); + + if (source == null) source = new Image(imgElement.width, imgElement.height); + + var imageData = canvas.getContext2d().getImageData(0, 0, source.width, source.height); + + var i = 0; + while (i < imageData.data.length) { + for (o in 0...4) { + source.underlying[i + (@:privateAccess Image.OFFSET + 1) + o] = imageData.data[i + o]; + } + i += 4; + } + + callback(source); + } + } + + public static function loadURLSync(url:String):Image { + var img = Browser.document.createImageElement(); + + img.src = url; + + var promiseStatus = 2; + var promise = new Promise((resolve, reject) -> { + img.onload = () -> { + resolve(img); + promiseStatus = 1; + }; + img.onerror = (e) -> { + reject(e); + promiseStatus = 0; + }; + }); + + while (promiseStatus == 2) { + Browser.window.requestAnimationFrame(null); + } + + URL.revokeObjectURL(url); + + if (promiseStatus == 0) { + throw new WebResponseError(img.src, "Failed to load image"); + } + + var canvas = Browser.document.createCanvasElement(); + canvas.width = img.width; + canvas.height = img.height; + canvas.getContext2d().drawImage(img, 0, 0); + var imageData = canvas.getContext2d().getImageData(0, 0, img.width, img.height); + + var visionImage = new Image(img.width, img.height); + var i = 0; + while (i < imageData.data.length) { + for (o in 0...4) { + visionImage.underlying[@:privateAccess Image.OFFSET + 1 + i + o] = imageData.data[i + o]; + } + i += 4; + } + + + return visionImage; + } + + public static function loadBytesSync(bytes:ByteArray, fileType:String):Image { + var blob = new Blob([Uint8Array.from(bytes)], { type: fileType }); + var url = URL.createObjectURL(blob); + return loadURLSync(url); + } + + public static function loadFileSync(filePath:String):Image { + if (!filePath.startsWith("file:///")) { + filePath = Path.normalize(filePath); + filePath = "file:///" + filePath; + } + + return loadURLSync(filePath); + } + +} \ No newline at end of file diff --git a/src/vision/formats/from/From.hx b/src/vision/formats/from/From.hx new file mode 100644 index 00000000..eb2719de --- /dev/null +++ b/src/vision/formats/from/From.hx @@ -0,0 +1,20 @@ +package vision.formats.from; + +/** + A container class for image loader types +**/ +@:noCompletion class From { + + public function new() {} + + /** + Load an image from bytes + **/ + public var bytes:FromBytes = new FromBytes(); + + /** + Convert an image from a specific framework's image type to `vision.ds.Image` + **/ + public var framework:FromFramework = new FromFramework(); + +} \ No newline at end of file diff --git a/src/vision/formats/from/FromBytes.hx b/src/vision/formats/from/FromBytes.hx new file mode 100644 index 00000000..c6d09d26 --- /dev/null +++ b/src/vision/formats/from/FromBytes.hx @@ -0,0 +1,61 @@ +package vision.formats.from; + +import vision.exceptions.LibraryRequired; +import vision.ds.Image; +import vision.exceptions.Unimplemented; +import vision.ds.ByteArray; + +/** + A class for loading images from bytes. +**/ +@:noCompletion class FromBytes { + + public function new() {} + + /** + Loads an image from `PNG` bytes + + @param bytes The image's bytes + @throws ImageLoadingFailed if the loaded image is not a PNG + @throws ImageLoadingFailed if the PNG has incorrect header data + @throws LibraryRequired if used without installing & including `format` + @return the loaded image + **/ + public function png(bytes:ByteArray):Image { + #if format + return vision.formats.__internal.FormatImageLoader.png(bytes); + #elseif js + return vision.formats.__internal.JsImageLoader.loadBytesSync(bytes, "image/png"); + #else + throw new LibraryRequired("format", [], "vision.formats.from.FromBytes.png", "function"); + #end + } + + /** + Loads an image from `BMP` bytes + + @param bytes The image's bytes + @throws ImageLoadingFailed if the loaded image is not a BMP + @throws ImageLoadingFailed if the BMP has incorrect header data, and reports it has more bytes than it should. + @throws LibraryRequired if used without installing & including `format` + @return the loaded image + **/ + public function bmp(bytes:ByteArray):Image { + #if format + return vision.formats.__internal.FormatImageLoader.bmp(bytes); + #elseif js + return vision.formats.__internal.JsImageLoader.loadBytesSync(bytes, "image/bmp"); + #else + throw new LibraryRequired("format", [], "vision.formats.from.FromBytes.bmp", "function"); + #end + + } + + public function jpeg(bytes:ByteArray):Image { + #if js + return vision.formats.__internal.JsImageLoader.loadBytesSync(bytes, "image/jpeg"); + #else + throw new Unimplemented('vision.formats.from.FromBytes.jpeg'); + #end + } +} \ No newline at end of file diff --git a/src/vision/formats/from/FromFramework.hx b/src/vision/formats/from/FromFramework.hx new file mode 100644 index 00000000..7302df52 --- /dev/null +++ b/src/vision/formats/from/FromFramework.hx @@ -0,0 +1,58 @@ +package vision.formats.from; + +import vision.formats.__internal.FrameworkImageIO; + +/** + A class for loading images from different frameworks +**/ +@:noCompletion class FromFramework { + + #if js + public var js = { + canvas: (canvas:js.html.CanvasElement) -> FrameworkImageIO.fromJsCanvas(canvas), + image: (image:js.html.ImageElement) -> FrameworkImageIO.fromJsImage(image) + } + #end + #if flixel + public var flixel = { + flxsprite: (sprite:flixel.FlxSprite) -> FrameworkImageIO.fromFlxSprite(sprite) + } + #end + #if flash + public var flash = { + bitmapdata: (bitmapData:flash.display.BitmapData) -> FrameworkImageIO.fromBitmapData(bitmapData), + sprite: (sprite:flash.display.Sprite) -> FrameworkImageIO.fromSprite(sprite), + shape: (shape:flash.display.Shape) -> FrameworkImageIO.fromShape(shape) + } + #end + #if openfl + public var openfl = { + bitmapdata: (bitmapData:openfl.display.BitmapData) -> FrameworkImageIO.fromBitmapData(bitmapData), + sprite: (sprite:openfl.display.Sprite) -> FrameworkImageIO.fromSprite(sprite), + shape: (shape:openfl.display.Shape) -> FrameworkImageIO.fromShape(shape) + } + #end + #if lime + public var lime = { + image: (image:lime.graphics.Image) -> FrameworkImageIO.fromLimeImage(bitmapData) + } + #end + #if heaps + public var heaps = { + pixels: (pixels:hxd.Pixels) -> FrameworkImageIO.fromHeapsPixels(pixels) + } + #end + #if kha + public var kha = { + image: (image:kha.Image) -> FrameworkImageIO.fromKhaImage(image) + } + #end + #if (haxeui_core && (haxeui_flixel || haxeui_openfl || haxeui_heaps || haxeui_html5)) + public var haxeui = { + image: (image:haxe.ui.components.Image) -> FrameworkImageIO.fromHaxeUIImage(image), + imagedata: (imageData:haxe.ui.backend.ImageData) -> FrameworkImageIO.fromHaxeUIImageData(imageData) + } + #end + + public function new() {} +} \ No newline at end of file diff --git a/src/vision/formats/to/To.hx b/src/vision/formats/to/To.hx new file mode 100644 index 00000000..c2336962 --- /dev/null +++ b/src/vision/formats/to/To.hx @@ -0,0 +1,19 @@ +package vision.formats.to; + +/** + A container class for image saver types +**/ +@:noCompletion class To { + + public function new() {} + + /** + Save an image to bytes + **/ + public var bytes:ToBytes = new ToBytes(); + + /** + Convert an image to a specific framework's image type + **/ + public var framework:ToFramework = new ToFramework(); +} \ No newline at end of file diff --git a/src/vision/formats/to/ToBytes.hx b/src/vision/formats/to/ToBytes.hx new file mode 100644 index 00000000..64b48c84 --- /dev/null +++ b/src/vision/formats/to/ToBytes.hx @@ -0,0 +1,68 @@ +package vision.formats.to; + +import vision.ds.ByteArray; +import vision.ds.Image; +import vision.exceptions.LibraryRequired; + +/** + A class for saving images to bytes +**/ +@:noCompletion class ToBytes { + + public function new() {} + + /** + Exports an image to `PNG` bytes + + @param image The image to export + @return The bytes of the exported image + @throws ImageSavingFailed If something goes wrong (for example, the image is invalid or device is out of memory) + @throws LibraryRequired if used without installing & including `format` on non-`js` targets + **/ + public function png(image:Image):ByteArray { + #if format + return vision.formats.__internal.FormatImageExporter.png(image); + #elseif js + return vision.formats.__internal.JsImageExporter.saveToBytesSync(image, "image/png"); + #else + throw new LibraryRequired("format", [], "vision.formats.to.ToBytes.png", "function"); + #end + } + + /** + Exports an image to `BMP` bytes + + @param image The image to export + @return The bytes of the exported image + @throws ImageSavingFailed If something goes wrong (for example, the image is invalid or device is out of memory) + @throws LibraryRequired if used without installing & including `format` on non-`js` targets + **/ + public function bmp(image:Image):ByteArray { + #if format + return vision.formats.__internal.FormatImageExporter.bmp(image); + #elseif js + return vision.formats.__internal.JsImageExporter.saveToBytesSync(image, "image/bmp"); + #else + throw new LibraryRequired("format", [], "vision.formats.to.ToBytes.bmp", "function"); + #end + } + + /** + Exports an image to `JPEG` bytes + + @param image The image to export + @return The bytes of the exported image + @throws ImageSavingFailed If something goes wrong (for example, the image is invalid or device is out of memory) + @throws LibraryRequired if used without installing & including `format` on non-`js` targets + **/ + public function jpeg(image:Image):ByteArray { + #if format + return vision.formats.__internal.FormatImageExporter.jpeg(image); + #elseif js + return vision.formats.__internal.JsImageExporter.saveToBytesSync(image, "image/jpeg"); + #else + throw new LibraryRequired("format", [], "vision.formats.to.ToBytes.jpeg", "function"); + #end + } + +} \ No newline at end of file diff --git a/src/vision/formats/to/ToFramework.hx b/src/vision/formats/to/ToFramework.hx new file mode 100644 index 00000000..489ef3e0 --- /dev/null +++ b/src/vision/formats/to/ToFramework.hx @@ -0,0 +1,58 @@ +package vision.formats.to; + +import vision.ds.Image; +import vision.formats.__internal.FrameworkImageIO; + +/** + A class for saving images to different frameworks +**/ +@:noCompletion class ToFramework { + #if js + public var js = { + canvas: (image:Image) -> FrameworkImageIO.toJsCanvas(image), + image: (image:Image) -> FrameworkImageIO.toJsImage(image) + } + #end + #if flixel + public var flixel = { + flxsprite: (image:Image) -> FrameworkImageIO.toFlxSprite(image) + } + #end + #if flash + public var flash = { + bitmapdata: (image:Image) -> FrameworkImageIO.toBitmapData(image), + sprite: (image:Image) -> FrameworkImageIO.toSprite(image), + shape: (image:Image) -> FrameworkImageIO.toShape(image) + } + #end + #if openfl + public var openfl = { + bitmapdata: (image:Image) -> FrameworkImageIO.toBitmapData(image), + sprite: (image:Image) -> FrameworkImageIO.toSprite(image), + shape: (image:Image) -> FrameworkImageIO.toShape(image) + } + #end + #if lime + public var lime = { + image: (image:Image) -> FrameworkImageIO.toLimeImage(image) + } + #end + #if heaps + public var heaps = { + pixels: (image:Image) -> FrameworkImageIO.toHeapsPixels(image) + } + #end + #if kha + public var kha = { + image: (image:Image) -> FrameworkImageIO.toKhaImage(image) + } + #end + #if (haxeui_core && (haxeui_flixel || haxeui_openfl || haxeui_heaps || haxeui_html5)) + public var haxeui = { + image: (image:Image) -> FrameworkImageIO.toHaxeUIImage(image), + imagedata: (image:Image) -> FrameworkImageIO.toHaxeUIImageData(image) + } + #end + + public function new() {} +} \ No newline at end of file diff --git a/src/vision/helpers/VisionThread.hx b/src/vision/helpers/VisionThread.hx index 8af345db..7f8318d1 100644 --- a/src/vision/helpers/VisionThread.hx +++ b/src/vision/helpers/VisionThread.hx @@ -2,16 +2,11 @@ package vision.helpers; import vision.exceptions.MultithreadFailure; import haxe.Exception; -#if js -import js.lib.Promise; -#elseif (sys) -import sys.thread.Thread; -#end class VisionThread { static var COUNT:Int = 0; - var underlying:#if js Promise #elseif (target.threaded) Thread #else Dynamic #end; + var underlying:#if js js.lib.Promise #elseif (target.threaded) sys.thread.Thread #else Dynamic #end; /** * The currently assigned job. should be a function with 0 parameters and no return type (`Void` `->` `Void`) @@ -58,12 +53,12 @@ class VisionThread { public function start() { #if js - underlying = new Promise((onDone, onFailedWrapper) -> { + underlying = new js.lib.Promise((onDone, onFailedWrapper) -> { job(); jobDone = true; }); #elseif (sys) - underlying = Thread.create(() -> { + underlying = sys.thread.Thread.create(() -> { try { job(); jobDone = true; diff --git a/src/vision/tools/ArrayTools.hx b/src/vision/tools/ArrayTools.hx index a9e08794..478d1027 100644 --- a/src/vision/tools/ArrayTools.hx +++ b/src/vision/tools/ArrayTools.hx @@ -27,7 +27,7 @@ class ArrayTools { @param delimiter The number of elements in each subarray @return An array of one higer dimension. **/ - overload extern inline public static function raise(array:Array, delimiter:Int):Array> { + overload extern public static inline function raise(array:Array, delimiter:Int):Array> { var raised = []; for (i in 0...array.length) { if (raised[floor(i / delimiter)] == null) raised[floor(i / delimiter)] = []; @@ -43,7 +43,7 @@ class ArrayTools { @param predicate A function that takes an element and returns true if the element should be used as a delimiter. @return An array of one higer dimension. **/ - overload extern inline public static function raise(array:Array, predicateOpensArray:Bool, predicate:T->Bool):Array> { + overload extern public static inline function raise(array:Array, predicateOpensArray:Bool, predicate:T->Bool):Array> { var raised:Array> = []; var temp:Array = []; @@ -60,7 +60,7 @@ class ArrayTools { return raised; } - public overload extern static inline function min>(values:Array):T { + overload extern public static inline function min>(values:Array):T { var min = values[0]; for (i in 0...values.length) { if ((values[i] - min) < 0) min = values[i]; @@ -68,7 +68,7 @@ class ArrayTools { return min; } - public overload extern static inline function min(values:Array):Int64 { + overload extern public static inline function min(values:Array):Int64 { var min = values[0]; for (i in 0...values.length) { if ((values[i] - min) < 0) min = values[i]; @@ -76,7 +76,7 @@ class ArrayTools { return min; } - public overload extern static inline function min(values:Array, valueFunction:T->Float):T { + overload extern public static inline function min(values:Array, valueFunction:T->Float):T { var min = values[0]; var minValue = valueFunction(min); for (i in 0...values.length) { @@ -90,7 +90,7 @@ class ArrayTools { return min; } - public overload extern static inline function max>(values:Array):T { + overload extern public static inline function max>(values:Array):T { var max = values[0]; for (i in 0...values.length) { if ((values[i] - max) > 0) max = values[i]; @@ -98,7 +98,7 @@ class ArrayTools { return max; } - public overload extern static inline function max(values:Array):Int64 { + overload extern public static inline function max(values:Array):Int64 { var max = values[0]; for (i in 0...values.length) { if ((values[i] - max) > 0) max = values[i]; @@ -106,7 +106,7 @@ class ArrayTools { return max; } - public overload extern static inline function max(values:Array, valueFunction:T->Float):T { + overload extern public static inline function max(values:Array, valueFunction:T->Float):T { var max = values[0]; var maxValue = valueFunction(max); for (i in 0...values.length) { @@ -120,7 +120,7 @@ class ArrayTools { return max; } - public overload extern static inline function average>(values:Array):Float { + overload extern public static inline function average>(values:Array):Float { var sum = 0.; for (v in values) { sum += cast v; @@ -128,7 +128,7 @@ class ArrayTools { return sum / values.length; } - public overload extern static inline function average(values:Array):Float { + overload extern public static inline function average(values:Array):Float { var sum = Int64.make(0, 0); for (v in values) { sum += v; @@ -169,7 +169,7 @@ class ArrayTools { return s[floor(values.length / 2)]; } - public static function distanceTo(array:Array, to:Array, distanceFunction:(T, T) -> Float) { + public static function distanceTo(array:Array, to:Array, distanceFunction:(T, T) -> Float):Float { var sum = 0.; for (i in 0...array.length - 1) { sum += distanceFunction(array[i], array[i + 1]); diff --git a/src/vision/tools/ImageTools.hx b/src/vision/tools/ImageTools.hx index adc69be5..4c65e757 100644 --- a/src/vision/tools/ImageTools.hx +++ b/src/vision/tools/ImageTools.hx @@ -1,7 +1,12 @@ package vision.tools; +#if sys +import sys.io.File; +#end +import haxe.Http; +import vision.formats.ImageIO; #if format -import vision.helpers.FormatImageLoader; +import vision.formats.__internal.FormatImageLoader; #end import haxe.io.Path; import haxe.crypto.Base64; @@ -16,10 +21,10 @@ import vision.exceptions.Unimplemented; import vision.exceptions.WebResponseError; import vision.ds.ImageResizeAlgorithm; #if js -import js.lib.Promise; import js.Browser; import js.html.CanvasElement; - +import vision.formats.__internal.JsImageLoader; +import vision.formats.__internal.JsImageExporter; #end import haxe.ds.Vector; import vision.ds.IntPoint2D; @@ -66,7 +71,7 @@ class ImageTools { @throws WebResponseError Thrown when a file loading attempt from a URL fails. @throws Unimplemented Thrown when used with unsupported file types. **/ - public static function loadFromFile(?image:Image, path:String, ?onComplete:Image->Void) { + overload extern public static inline function loadFromFile(?image:Image, path:String, ?onComplete:Image->Void) { #if (!js) #if format var func:ByteArray -> Image; @@ -115,35 +120,10 @@ class ImageTools { #end #end #else - var imgElement = js.Browser.document.createImageElement(); - imgElement.src = path; - imgElement.crossOrigin = "Anonymous"; - imgElement.onload = () -> { - var canvas = js.Browser.document.createCanvasElement(); - - canvas.width = imgElement.width; - canvas.height = imgElement.height; - - canvas.getContext2d().drawImage(imgElement, 0, 0); - - if (image == null) image = new Image(imgElement.width, imgElement.height); - - var imageData = canvas.getContext2d().getImageData(0, 0, image.width, image.height); - - var i = 0; - while (i < imageData.data.length) { - for (o in 0...4) { - image.underlying[i + (@:privateAccess Image.OFFSET + 1) + o] = imageData.data[i + o]; - } - i += 4; - } - - if(onComplete != null) - onComplete(image); - } + JsImageLoader.loadAsync(path, image, onComplete); #end } - + /** Saves an image to a path. @@ -160,62 +140,96 @@ class ImageTools { @throws LibraryRequired Thrown when used without installing & including `format` @throws ImageSavingFailed Thrown when trying to save a corrupted image. **/ + @:deprecated("ImageTools.saveToFile() is deprecated. use ImageTools.exportToFile() instead") public static function saveToFile(image:Image, pathWithFileName:String, saveFormat:ImageFormat = PNG) { - #if (!js) - #if format - switch saveFormat { - case PNG: { - try { - final out = sys.io.File.write(pathWithFileName); - var writer = new format.png.Writer(out); - final data = format.png.Tools.build32ARGB(image.width, image.height, image.underlying.sub(Image.OFFSET, image.underlying.length - Image.OFFSET)); - writer.write(data); - out.close(); - } catch (e:haxe.Exception) { - #if !vision_quiet - throw new ImageSavingFailed(saveFormat, e.message); - #end - } - } - case BMP: { + return exportToFile(image, pathWithFileName, saveFormat); + } + + + public static function loadFromBytes(?image:Image, bytes:ByteArray, fileFormat:ImageFormat):Image { + image = image == null ? new Image(0, 0) : image; + image.copyImageFrom( + switch fileFormat { + case VISION: cast bytes; + case PNG: ImageIO.from.bytes.png(bytes); + case BMP: ImageIO.from.bytes.bmp(bytes); + case JPEG: ImageIO.from.bytes.jpeg(bytes); + default: { #if !vision_quiet - throw new Unimplemented('Using `ImageTools.saveToFile` with `BMP` format'); + throw new Unimplemented('Using `ImageTools.fromBytes` with a file of type `${fileFormat}`'); #end + ImageIO.from.bytes.png(bytes); } } - #else - #if !vision_quiet - throw new LibraryRequired("format", [], "ImageTools.loadFromFile", "function"); - #end - #end + ); + + return image; + } + + overload extern public static inline function loadFromFile(?image:Image, path:String):Image { + #if js + return image.copyImageFrom(JsImageLoader.loadFileSync(path)); #else - #if format - switch saveFormat { - case PNG: { - try { - var canvas = image.toJsCanvas(); - var i = canvas.toDataURL("image/png", 1.0).replace("image/png", "image/octet-stream"); - var link = Browser.document.createAnchorElement(); - link.download = new Path(pathWithFileName).file + ".png"; - link.href = i; - link.click(); - } catch (e:haxe.Exception) { - #if !vision_quiet - throw new ImageSavingFailed(saveFormat, e.message); - #end - } - } - case BMP: { - #if !vision_quiet - throw new Unimplemented('Using `ImageTools.saveToFile` with `BMP` format'); - #end - } - } - #else + return loadFromBytes(image, File.getBytes(path), Path.extension(path)); + #end + } + + public static function loadFromURL(?image:Image, url:String):Image { + #if js + return image.copyImageFrom(JsImageLoader.loadURLSync(url)); + #else + var http = new Http(url); + var requestStatus = 2; + http.onBytes = (data) -> { + loadFromBytes(image, data, Path.extension(url)); + requestStatus = 1; + } + http.onError = (msg) -> { + #if !vision_quiet + throw new WebResponseError(url, msg); + #end + requestStatus = 0; + } + http.request(); + + while (requestStatus == 2) { + #if sys + Sys.sleep(0.1); + #end + // This is a busy loop. Pretty bad, but there isn't really a better way. + } + + if (requestStatus == 0) { + #if !vision_quiet + throw new WebResponseError(url, "Failed to load image"); + #end + } + + return image; + #end + } + + public static function exportToBytes(?image:Image, format:ImageFormat):ByteArray { + image = image == null ? new Image(0, 0) : image; + return switch format { + case VISION: image.underlying; + case PNG: ImageIO.to.bytes.png(image); + case BMP: ImageIO.to.bytes.bmp(image); + case JPEG: ImageIO.to.bytes.jpeg(image); + default: { #if !vision_quiet - throw new LibraryRequired("format", [], "ImageTools.loadFromFile", "function"); + throw new Unimplemented('Using `ImageTools.toBytes` with a file of type `${format}`'); #end - #end + ImageIO.to.bytes.png(image); + } + }; + } + + public static function exportToFile(image:Image, pathWithFileName:String, format:ImageFormat = PNG) { + #if js + JsImageExporter.saveToFileAsync(image, pathWithFileName, format); + #else + File.saveBytes(pathWithFileName, exportToBytes(image, format)); #end } @@ -313,256 +327,6 @@ class ImageTools { + pixel.green + pixel.blue) / 3) #end; return Color.fromRGBA(gray, gray, gray, pixel.alpha); } - - #if flixel - public static function fromFlxSprite(sprite:flixel.FlxSprite):Image { - var image = new Image(Std.int(sprite.width), Std.int(sprite.height)); - if (sprite.pixels == null) { - lime.utils.Log.warn("ImageTools.fromFlxSprite() - The given sprite's bitmapData is null. An empty image is returned. Is the given FlxSprite not added?"); - return image; - } - for (x in 0...Std.int(sprite.width)) { - for (y in 0...Std.int(sprite.height)) { - image.setPixel(x, y, sprite.pixels.getPixel(x, y)); - } - } - return image; - } - - public static function toFlxSprite(image:Image):flixel.FlxSprite { - var sprite = new flixel.FlxSprite(0, 0); - sprite.makeGraphic(image.width, image.height, 0x00ffffff); - for (x in 0...image.width) { - for (y in 0...image.height) { - sprite.pixels.setPixel(x, y, image.getPixel(x, y)); - } - } - return sprite; - } - #end - - #if (openfl || flash) - public static function fromBitmapData(bitmapData:flash.display.BitmapData):Image { - var image = new Image(bitmapData.width, bitmapData.height); - for (x in 0...bitmapData.width) { - for (y in 0...bitmapData.height) { - image.setPixel(x, y, bitmapData.getPixel32(x, y)); - } - } - return image; - } - - public static function toBitmapData(image:Image):flash.display.BitmapData { - var bitmapData = new flash.display.BitmapData(image.width, image.height, true, 0x00000000); - for (x in 0...image.width) { - for (y in 0...image.height) { - bitmapData.setPixel32(x, y, image.getPixel(x, y)); - } - } - return bitmapData; - } - - public static function fromSprite(sprite:flash.display.Sprite):Image { - var bmp = new flash.display.BitmapData(Std.int(sprite.width), Std.int(sprite.height)); - bmp.draw(sprite); - return fromBitmapData(bmp); - } - - public static function toSprite(image:Image):flash.display.Sprite { - final bmp = toBitmapData(image); - var s = new flash.display.Sprite(); - s.addChild(new flash.display.Bitmap(bmp)); - return s; - } - - public static function fromShape(shape:flash.display.Shape):Image { - var bmp = new flash.display.BitmapData(Std.int(shape.width), Std.int(shape.height)); - bmp.draw(shape); - return fromBitmapData(bmp); - } - #end - - #if openfl - public static function toShape(image:Image):flash.display.Shape { - var s:openfl.display.Shape = cast toSprite(image); - var sh = new openfl.display.Shape(); - sh.graphics.drawGraphicsData(s.graphics.readGraphicsData()); - return sh; - } - #end - - #if lime - public static function fromLimeImage(limeImage:lime.graphics.Image):Image { - var image = new Image(limeImage.width, limeImage.height); - for (x in 0...image.width) { - for (y in 0...image.height) { - image.setPixel(x, y, limeImage.getPixel(x, y)); - } - } - return image; - } - - public static function toLimeImage(image:Image):lime.graphics.Image { - var limeImage = new lime.graphics.Image(image.width, image.height); - for (x in 0...image.width) { - for (y in 0...image.height) { - limeImage.setPixel(x, y, image.getPixel(x, y)); - } - } - return limeImage; - } - #end - - #if kha - public static function fromKhaImage(khaImage:kha.Image):Image { - var image = new Image(khaImage.width, khaImage.height); - for (x in 0...image.width) { - for (y in 0...image.height) { - image.setPixel(x, y, khaImage.at(x, y)); - } - } - return image; - } - #end - - #if heaps - public static function fromHeapsPixels(pixels:hxd.Pixels):Image { - var image = new Image(pixels.width, pixels.height); - switch pixels.format { - case ARGB: - default: - #if !vision_quiet - throw "pixels format must be in ARGB format, currently: " + pixels.format; - #else - return image; - #end - } - for (x in 0...pixels.width) { - for (y in 0...pixels.height) { - image.setPixel(x, y, pixels.getPixel(x, y)); - } - } - return image; - } - - public static function toHeapsPixels(image:Image):hxd.Pixels { - var pixels = hxd.Pixels.alloc(image.width, image.height, ARGB); - for (x in 0...image.width) { - for (y in 0...pixels.height) { - pixels.setPixel(x, y, image.getPixel(x, y)); - } - } - return pixels; - } - #end - #if js - public static function fromJsCanvas(canvas:js.html.CanvasElement):Image { - var image:Image = Image.fromBytes(new ByteArray(Image.OFFSET + (canvas.width + canvas.height) * 4), canvas.width, canvas.height); - - final imageData = canvas.getContext2d().getImageData(0, 0, image.width, image.height); - - { - var i = 0; - while (i < imageData.data.length) { - for (o in 0...4) - image.underlying[i + (Image.OFFSET + 1) + o] = imageData.data[i + o]; - i += 4; - } - } - - return image; - } - - public static function toJsCanvas(image:Image):js.html.CanvasElement { - var c = js.Browser.document.createCanvasElement(); - - c.width = image.width; - c.height = image.height; - - var ctx = c.getContext2d(); - final imageData = ctx.getImageData(0, 0, image.width, image.height); - var data = imageData.data; - for (x in 0...image.width) { - for (y in 0...image.height) { - var i = (y * image.width + x) * 4; - for (o in 0...4) - data[i + o] = image.underlying[i + (Image.OFFSET + 1) + o]; - } - } - - ctx.putImageData(imageData, 0, 0); - - return c; - } - - public static function fromJsImage(image:js.html.ImageElement):Image { - var canvas = js.Browser.document.createCanvasElement(); - canvas.width = image.width; - canvas.height = image.height; - canvas.getContext2d().drawImage(image, 0, 0); - return fromJsCanvas(canvas); - } - - public static function toJsImage(image:Image):js.html.ImageElement { - var canvas = image.toJsCanvas(); - var htmlImage = js.Browser.document.createImageElement(); - htmlImage.src = canvas.toDataURL(); - return htmlImage; - } - #end - #if (haxeui_core && (haxeui_flixel || haxeui_openfl || haxeui_heaps || haxeui_html5)) - public static function fromHaxeUIImage(image:haxe.ui.components.Image):Image { - #if haxeui_flixel - return fromFlxSprite(image.resource); - #elseif haxeui_openfl - return fromBitmapData(image.resource); - #elseif haxeui_heaps - return fromHeapsPixels(image.resource); - #else - return fromJsImage(image.resource); - #end - } - - public static function toHaxeUIImage(image:Image):haxe.ui.components.Image { - var huiImage = new haxe.ui.components.Image(); - huiImage.width = image.width; - huiImage.height = image.height; - #if haxeui_flixel - huiImage.resource = toFlxSprite(image); - #elseif haxeui_openfl - huiImage.resource = toBitmapData(image); - #elseif haxeui_heaps - huiImage.resource = toHeapsPixels(image); - #else - huiImage.resource = toJsImage(image); - #end - return huiImage; - } - - public static function fromHaxeUIImageData(image:haxe.ui.backend.ImageData):Image { - #if haxeui_flixel - return fromFlxSprite(image); - #elseif haxeui_openfl - return fromBitmapData(image); - #elseif haxeui_heaps - return fromHeapsPixels(image); - #else - return fromJsImage(image); - #end - } - - public static function toHaxeUIImageData(image:Image):haxe.ui.backend.ImageData { - #if haxeui_flixel - return toFlxSprite(image); - #elseif haxeui_openfl - return fromBitmapData(image); - #elseif haxeui_heaps - return toHeapsPixels(image); - #else - return toJsImage(image); - #end - } - #end } private class NeighborsIterator { diff --git a/src/vision/tools/MathTools.hx b/src/vision/tools/MathTools.hx index d1c52d80..6cd72eef 100644 --- a/src/vision/tools/MathTools.hx +++ b/src/vision/tools/MathTools.hx @@ -1,13 +1,8 @@ package vision.tools; -import haxe.ds.Either; import vision.ds.Point3D; -import vision.ds.Matrix2D; import vision.ds.IntPoint2D; -import haxe.ds.Vector; -import vision.algorithms.Radix; import haxe.Int64; -import haxe.ds.ArraySort; import vision.ds.Rectangle; import vision.ds.Ray2D; import vision.ds.Line2D; @@ -44,11 +39,11 @@ class MathTools { // Ray2D Extensions //----------------------------------------------------------------------------------------- - public static inline function distanceFromRayToPoint2D(ray:Ray2D, point:Point2D) { + public static inline function distanceFromRayToPoint2D(ray:Ray2D, point:Point2D):Float { return distanceFromPointToRay2D(point, ray); } - public inline static function intersectionBetweenRay2Ds(ray:Ray2D, ray2:Ray2D):Point2D { + public static inline function intersectionBetweenRay2Ds(ray:Ray2D, ray2:Ray2D):Point2D { final line1StartX = ray.point.x; final line1StartY = ray.point.y; final line1EndX = ray.point.x + cos(ray.radians) * 1000; @@ -223,7 +218,7 @@ class MathTools { // Point2D Extensions //----------------------------------------------------------------------------------------- - overload extern inline public static function distanceFromPointToRay2D(point:Point2D, ray:Ray2D):Float { + overload extern public static inline function distanceFromPointToRay2D(point:Point2D, ray:Ray2D):Float { // Get the closest point on the ray to the given point final closestPoint:Point2D = getClosestPointOnRay2D(point, ray); @@ -235,7 +230,7 @@ class MathTools { return distance; } - overload extern inline public static function distanceFromPointToLine2D(point:Point2D, line:Line2D):Float { + overload extern public static inline function distanceFromPointToLine2D(point:Point2D, line:Line2D):Float { final middle = new Point2D(line.end.x - line.start.x, line.end.y - line.start.y); final denominator = middle.x * middle.x + middle.y * middle.y; var ratio = ((point.x - line.start.x) * middle.x + (point.y - line.start.y) * middle.y) / denominator; @@ -252,53 +247,53 @@ class MathTools { return sqrt(dx * dx + dy * dy); } - overload extern inline public static function radiansFromPointToLine2D(point:Point2D, line:Line2D):Float { + overload extern public static inline function radiansFromPointToLine2D(point:Point2D, line:Line2D):Float { final angle:Float = atan2(line.end.y - line.start.y, line.end.x - line.start.x); final angle2:Float = atan2(point.y - line.start.y, point.x - line.start.x); return angle2 - angle; } - overload extern inline public static function radiansFromPointToPoint2D(point1:Point2D, point2:Point2D):Float { + overload extern public static inline function radiansFromPointToPoint2D(point1:Point2D, point2:Point2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return atan2(y, x); } - overload extern inline public static function degreesFromPointToPoint2D(point1:Point2D, point2:Point2D):Float { + overload extern public static inline function degreesFromPointToPoint2D(point1:Point2D, point2:Point2D):Float { return radiansToDegrees(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function slopeFromPointToPoint2D(point1:Point2D, point2:Point2D):Float { + overload extern public static inline function slopeFromPointToPoint2D(point1:Point2D, point2:Point2D):Float { return radiansToSlope(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function distanceBetweenPoints(point1:Point2D, point2:Point2D):Float { + overload extern public static inline function distanceBetweenPoints(point1:Point2D, point2:Point2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return sqrt(x * x + y * y); } - overload extern inline public static function radiansFromPointToPoint2D(point1:Point2D, point2:IntPoint2D):Float { + overload extern public static inline function radiansFromPointToPoint2D(point1:Point2D, point2:IntPoint2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return atan2(y, x); } - overload extern inline public static function degreesFromPointToPoint2D(point1:Point2D, point2:IntPoint2D):Float { + overload extern public static inline function degreesFromPointToPoint2D(point1:Point2D, point2:IntPoint2D):Float { return radiansToDegrees(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function slopeFromPointToPoint2D(point1:Point2D, point2:IntPoint2D):Float { + overload extern public static inline function slopeFromPointToPoint2D(point1:Point2D, point2:IntPoint2D):Float { return radiansToSlope(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function distanceBetweenPoints(point1:Point2D, point2:IntPoint2D):Float { + overload extern public static inline function distanceBetweenPoints(point1:Point2D, point2:IntPoint2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return sqrt(x * x + y * y); } - overload extern inline public static function getClosestPointOnRay2D(point:Point2D, ray:Ray2D):Point2D { + overload extern public static inline function getClosestPointOnRay2D(point:Point2D, ray:Ray2D):Point2D { // Vector from the origin of the ray to the given point var vx:Float = point.x - ray.point.x; var vy:Float = point.y - ray.point.y; @@ -317,7 +312,7 @@ class MathTools { // IntPoint2D Extensions //----------------------------------------------------------------------------------------- - overload extern inline public static function distanceFromPointToRay2D(point:IntPoint2D, ray:Ray2D):Float { + overload extern public static inline function distanceFromPointToRay2D(point:IntPoint2D, ray:Ray2D):Float { // Get the closest point on the ray to the given point final closestPoint:Point2D = getClosestPointOnRay2D(point, ray); @@ -329,7 +324,7 @@ class MathTools { return distance; } - overload extern inline public static function distanceFromPointToLine2D(point:IntPoint2D, line:Line2D):Float { + overload extern public static inline function distanceFromPointToLine2D(point:IntPoint2D, line:Line2D):Float { final middle = new Point2D(line.end.x - line.start.x, line.end.y - line.start.y); final denominator = middle.x * middle.x + middle.y * middle.y; var ratio = ((point.x - line.start.x) * middle.x + (point.y - line.start.y) * middle.y) / denominator; @@ -346,53 +341,53 @@ class MathTools { return sqrt(dx * dx + dy * dy); } - overload extern inline public static function radiansFromPointToLine2D(point:IntPoint2D, line:Line2D):Float { + overload extern public static inline function radiansFromPointToLine2D(point:IntPoint2D, line:Line2D):Float { final angle:Float = atan2(line.end.y - line.start.y, line.end.x - line.start.x); final angle2:Float = atan2(point.y - line.start.y, point.x - line.start.x); return angle2 - angle; } - overload extern inline public static function radiansFromPointToPoint2D(point1:IntPoint2D, point2:IntPoint2D):Float { + overload extern public static inline function radiansFromPointToPoint2D(point1:IntPoint2D, point2:IntPoint2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return atan2(y, x); } - overload extern inline public static function degreesFromPointToPoint2D(point1:IntPoint2D, point2:IntPoint2D):Float { + overload extern public static inline function degreesFromPointToPoint2D(point1:IntPoint2D, point2:IntPoint2D):Float { return radiansToDegrees(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function slopeFromPointToPoint2D(point1:IntPoint2D, point2:IntPoint2D):Float { + overload extern public static inline function slopeFromPointToPoint2D(point1:IntPoint2D, point2:IntPoint2D):Float { return radiansToSlope(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function distanceBetweenPoints(point1:IntPoint2D, point2:IntPoint2D):Float { + overload extern public static inline function distanceBetweenPoints(point1:IntPoint2D, point2:IntPoint2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return sqrt(x * x + y * y); } - overload extern inline public static function radiansFromPointToPoint2D(point1:IntPoint2D, point2:Point2D):Float { + overload extern public static inline function radiansFromPointToPoint2D(point1:IntPoint2D, point2:Point2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return atan2(y, x); } - overload extern inline public static function degreesFromPointToPoint2D(point1:IntPoint2D, point2:Point2D):Float { + overload extern public static inline function degreesFromPointToPoint2D(point1:IntPoint2D, point2:Point2D):Float { return radiansToDegrees(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function slopeFromPointToPoint2D(point1:IntPoint2D, point2:Point2D):Float { + overload extern public static inline function slopeFromPointToPoint2D(point1:IntPoint2D, point2:Point2D):Float { return radiansToSlope(radiansFromPointToPoint2D(point1, point2)); } - overload extern inline public static function distanceBetweenPoints(point1:IntPoint2D, point2:Point2D):Float { + overload extern public static inline function distanceBetweenPoints(point1:IntPoint2D, point2:Point2D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; return sqrt(x * x + y * y); } - overload extern inline public static function getClosestPointOnRay2D(point:IntPoint2D, ray:Ray2D):Point2D { + overload extern public static inline function getClosestPointOnRay2D(point:IntPoint2D, ray:Ray2D):Point2D { // Vector from the origin of the ray to the given point var vx:Float = point.x - ray.point.x; var vy:Float = point.y - ray.point.y; @@ -411,7 +406,7 @@ class MathTools { // Point3D //----------------------------------------------------------------------------- - overload extern inline public static function distanceBetweenPoints(point1:Point3D, point2:Point3D):Float { + overload extern public static inline function distanceBetweenPoints(point1:Point3D, point2:Point3D):Float { final x:Float = point2.x - point1.x; final y:Float = point2.y - point1.y; final z:Float = point2.z - point1.z; @@ -448,7 +443,7 @@ class MathTools { Ensures that the value is between min and max, by wrapping the value around when it is outside of the range. **/ - public inline static function wrapInt(value:Int, min:Int, max:Int):Int { + public static inline function wrapInt(value:Int, min:Int, max:Int):Int { var range = max - min + 1; if (value < min) value += range * Std.int((min - value) / range + 1); @@ -460,7 +455,7 @@ class MathTools { Ensures that the value is between min and max, by wrapping the value around when it is outside of the range. **/ - public inline static function wrapFloat(value:Float, min:Float, max:Float):Float { + public static inline function wrapFloat(value:Float, min:Float, max:Float):Float { var range = max - min; if (value < min) value += range * (min - value) / range + 1; @@ -610,28 +605,28 @@ class MathTools { // Utilities For Number Arrays //----------------------------------------------------------------------------------------- - overload extern inline public static function max(value:Int, ...values:Int) return ArrayTools.max(values.toArray().concat([value])); - overload extern inline public static function max(value:Float, ...values:Float) return ArrayTools.max(values.toArray().concat([value])); - overload extern inline public static function max(value:Int64, ...values:Int64) return ArrayTools.max(values.toArray().concat([value])); + overload extern public static inline function max(value:Int, ...values:Int):Int return ArrayTools.max(values.toArray().concat([value])); + overload extern public static inline function max(value:Float, ...values:Float):Float return ArrayTools.max(values.toArray().concat([value])); + overload extern public static inline function max(value:Int64, ...values:Int64):Int64 return ArrayTools.max(values.toArray().concat([value])); - overload extern inline public static function min(value:Int, ...values:Int) return ArrayTools.min(values.toArray().concat([value])); - overload extern inline public static function min(value:Float, ...values:Float) return ArrayTools.min(values.toArray().concat([value])); - overload extern inline public static function min(value:Int64, ...values:Int64) return ArrayTools.min(values.toArray().concat([value])); + overload extern public static inline function min(value:Int, ...values:Int):Int return ArrayTools.min(values.toArray().concat([value])); + overload extern public static inline function min(value:Float, ...values:Float):Float return ArrayTools.min(values.toArray().concat([value])); + overload extern public static inline function min(value:Int64, ...values:Int64):Int64 return ArrayTools.min(values.toArray().concat([value])); - overload extern inline public static function average(value:Int, ...values:Int) return ArrayTools.average(values.toArray().concat([value])); - overload extern inline public static function average(value:Float, ...values:Float) return ArrayTools.average(values.toArray().concat([value])); - overload extern inline public static function average(value:Int64, ...values:Int64) return ArrayTools.average(values.toArray().concat([value])); + overload extern public static inline function average(value:Int, ...values:Int):Float return ArrayTools.average(values.toArray().concat([value])); + overload extern public static inline function average(value:Float, ...values:Float):Float return ArrayTools.average(values.toArray().concat([value])); + overload extern public static inline function average(value:Int64, ...values:Int64):Float return ArrayTools.average(values.toArray().concat([value])); - overload extern inline public static function median(value:Int, ...values:Int) return ArrayTools.median(values.toArray().concat([value])); - overload extern inline public static function median(value:Float, ...values:Float) return ArrayTools.median(values.toArray().concat([value])); - overload extern inline public static function median(value:Int64, ...values:Int64) return ArrayTools.median(values.toArray().concat([value])); + overload extern public static inline function median(value:Int, ...values:Int):Int return ArrayTools.median(values.toArray().concat([value])); + overload extern public static inline function median(value:Float, ...values:Float):Float return ArrayTools.median(values.toArray().concat([value])); + overload extern public static inline function median(value:Int64, ...values:Int64):Int64 return ArrayTools.median(values.toArray().concat([value])); // ---------------------------------------------------------------------------------------- // Utilities For Number Types // ---------------------------------------------------------------------------------------- - public static inline function isInt(v:Float) { + public static inline function isInt(v:Float):Bool { return v == Std.int(v); } diff --git a/tests/compile.hxml b/tests/compile.hxml new file mode 100644 index 00000000..39d4971f --- /dev/null +++ b/tests/compile.hxml @@ -0,0 +1,9 @@ +--class-path generator +--main Main + +--library vision + +--define --regenerate-all +--define --no-overwrite + +--interp \ No newline at end of file diff --git a/tests/complete.hxml b/tests/complete.hxml new file mode 100644 index 00000000..6992a4ab --- /dev/null +++ b/tests/complete.hxml @@ -0,0 +1,19 @@ +--class-path generator +--main Main + +--library vision + +--define --regenerate-all +--define --no-overwrite + +--interp + +--next + +--cwd generated +--class-path src +--main Main +--library vision +--library format + +--interp \ No newline at end of file diff --git a/tests/config.json b/tests/config.json new file mode 100644 index 00000000..8155b91d --- /dev/null +++ b/tests/config.json @@ -0,0 +1,12 @@ +{ + "regenerateAll": true, + "overwrite": false, + "source": "../src/vision", + "exclude": [ + "exceptions/", + "Array2DMacro.hx", + "FrameworkImageIO.hx" + ], + "destination": "./generated/src/tests", + "testsToRunFile": "./generated/src/TestsToRun.hx" +} \ No newline at end of file diff --git a/tests/generated/compile.hxml b/tests/generated/compile.hxml new file mode 100644 index 00000000..a5611dc1 --- /dev/null +++ b/tests/generated/compile.hxml @@ -0,0 +1,7 @@ +--class-path src +--main Main + +--library vision +--library format + +--interp \ No newline at end of file diff --git a/tests/generated/src/Main.hx b/tests/generated/src/Main.hx new file mode 100644 index 00000000..f207a05f --- /dev/null +++ b/tests/generated/src/Main.hx @@ -0,0 +1,138 @@ +package; + +import vision.tools.MathTools; +import haxe.SysTools; +import vision.ds.ByteArray; +import haxe.io.Bytes; +import tests.*; + +using vision.tools.ArrayTools; + +import TestStatus; +import TestResult; +import TestsToRun; + +class Main { + + // ANSI colors + static var RED = "\033[31m"; + static var GREEN = "\033[32m"; + static var YELLOW = "\033[33m"; + static var BLUE = "\033[34m"; + static var MAGENTA = "\033[35m"; + static var CYAN = "\033[36m"; + static var WHITE = "\033[37m"; + static var BLACK = "\033[30m"; + static var LIGHT_BLUE = "\033[94m"; + static var GRAY = "\033[90m"; + static var RESET = "\033[0m"; + + static var RED_BACKGROUND = "\033[41m"; + static var GREEN_BACKGROUND = "\033[42m"; + static var YELLOW_BACKGROUND = "\033[43m"; + static var BLUE_BACKGROUND = "\033[44m"; + static var MAGENTA_BACKGROUND = "\033[45m"; + static var CYAN_BACKGROUND = "\033[46m"; + static var WHITE_BACKGROUND = "\033[47m"; + static var BLACK_BACKGROUND = "\033[40m"; + static var LIGHT_BLUE_BACKGROUND = "\033[104m"; + static var GRAY_BACKGROUND = "\033[100m"; + + static var BOLD = "\033[1m"; + static var ITALIC = "\033[3m"; + static var UNDERLINE = "\033[4m"; + + static var bulk = true; + + public static function main() { + var i = 0; + var conclusionMap = new Map>(); + + for (statusType in [Success, Failure, Skipped, Unimplemented]) { + conclusionMap.set(statusType, []); + } + + for (cls in TestsToRun.tests) { + var testFunctions:Array<() -> TestResult> = Type.getClassFields(cls).map(func -> Reflect.field(cls, func)); + for (func in testFunctions) { + i++; + var result:TestResult = func(); + Sys.println('$CYAN$BOLD Unit Test $i:$RESET $BOLD$ITALIC${getTestPassColor(result.status)}${result.testName}$RESET'); + Sys.println(' - $RESET$BOLD$WHITE Result: $ITALIC${getTestPassColor(result.status)}${result.status}$RESET'); + if (result.status == Failure) { + Sys.println(' - $RESET$BOLD$WHITE Expected:$RESET $ITALIC$GREEN${safeStringify(result.expected)}$RESET'); + Sys.println(' - $RESET$BOLD$WHITE Returned:$RESET $ITALIC$RED${safeStringify(result.returned)}$RESET'); + } + + conclusionMap.get(result.status).push(result); + if (result.status != Success && !bulk) Sys.exit(1); + //Sys.sleep(bulk ? 0.01 : 0.2); + } + } + Sys.println(getTestStatusBar(conclusionMap.get(Success).length, conclusionMap.get(Failure).length, conclusionMap.get(Skipped).length, conclusionMap.get(Unimplemented).length)); + if (conclusionMap.get(Success).length == i) { + Sys.println('$GREEN$BOLD🥳 🥳 🥳 All tests passed! 🥳 🥳 🥳$RESET'); + } else { + Sys.println('$RED$BOLD Final Test Status:$RESET'); + Sys.println(' - $RESET$BOLD${getTestPassColor(Success)} ${conclusionMap.get(Success).length}$RESET $BOLD$WHITE Tests $RESET$BOLD${getTestPassColor(Success)} Passed 🥳$RESET'); + Sys.println(' - $RESET$BOLD${getTestPassColor(Failure)} ${conclusionMap.get(Failure).length}$RESET $BOLD$WHITE Tests $RESET$BOLD${getTestPassColor(Failure)} Failed 🥺$RESET'); + Sys.println(' - $RESET$BOLD${getTestPassColor(Skipped)} ${conclusionMap.get(Skipped).length}$RESET $BOLD$WHITE Tests $RESET$BOLD${getTestPassColor(Skipped)} Skipped 🤷$RESET'); + Sys.println(' - $RESET$BOLD${getTestPassColor(Unimplemented)} ${conclusionMap.get(Unimplemented).length}$RESET $BOLD$WHITE Tests $RESET$BOLD${getTestPassColor(Unimplemented)} Unimplemented 😬$RESET'); + } + Sys.println(getTestStatusBar(conclusionMap.get(Success).length, conclusionMap.get(Failure).length, conclusionMap.get(Skipped).length, conclusionMap.get(Unimplemented).length)); + + } + + static function getTestPassColor(status:TestStatus):String { + return switch status { + case Success: GREEN; + case Failure: RED; + case Skipped: LIGHT_BLUE; + case Unimplemented: GRAY; + + } + } + + static function safeStringify(value:Dynamic):String { + if (Std.isOfType(value, Bytes)) { + var hex = (value : ByteArray).toHex(); + return "[" + [for (i in 0...hex.length) hex.charAt(i)].raise(2).map(array -> "0x" + array.join("")).join(", ") + "]"; + } + + return Std.string(value); + } + + static function getTestStatusBar(successes:Int, failures:Int, skipped:Int, unimplemented:Int):String { + var consoleWidth = 100; + + consoleWidth -= 2; + + var successPercent = successes / (successes + failures + skipped + unimplemented); + var successWidth = MathTools.round(successPercent * consoleWidth); + + var failurePercent = failures / (successes + failures + skipped + unimplemented); + var failureWidth = MathTools.round(failurePercent * consoleWidth); + + var skippedPercent = skipped / (successes + failures + skipped + unimplemented); + var skippedWidth = MathTools.round(skippedPercent * consoleWidth); + + var unimplementedPercent = unimplemented / (successes + failures + skipped + unimplemented); + var unimplementedWidth = MathTools.round(unimplementedPercent * consoleWidth); + + var output = '╔${[for (_ in 0...(successWidth + failureWidth + skippedWidth + unimplementedWidth) + 2) '═'].join('')}╗\n'; + + output += '║ $RESET$BOLD$GREEN_BACKGROUND'; + for (_ in 0...successWidth) output += ' '; + output += '$RED_BACKGROUND'; + for (_ in 0...failureWidth) output += ' '; + output += '$LIGHT_BLUE_BACKGROUND'; + for (_ in 0...skippedWidth) output += ' '; + output += '$GRAY_BACKGROUND'; + for (_ in 0...unimplementedWidth) output += ' '; + output += '$RESET ║'; + + output += '\n╚${[for (_ in 0...(successWidth + failureWidth + skippedWidth + unimplementedWidth) + 2) '═'].join('')}╝'; + return output; + + } +} diff --git a/tests/generated/src/TestResult.hx b/tests/generated/src/TestResult.hx new file mode 100644 index 00000000..f27879b2 --- /dev/null +++ b/tests/generated/src/TestResult.hx @@ -0,0 +1,8 @@ +package; + +typedef TestResult = { + testName:String, + returned: Dynamic, + expected: Dynamic, + status:TestStatus, +} diff --git a/tests/generated/src/TestStatus.hx b/tests/generated/src/TestStatus.hx new file mode 100644 index 00000000..1c5a6d52 --- /dev/null +++ b/tests/generated/src/TestStatus.hx @@ -0,0 +1,53 @@ +package; + +import vision.exceptions.Unimplemented; +import vision.ds.ByteArray; +import haxe.io.Bytes; + + +enum abstract TestStatus(String) { + var Success; + var Failure; + var Skipped; + var Unimplemented; + + overload extern public static inline function of(condition:Bool):TestStatus { + return condition ? Success : Failure; + } + + overload extern public static inline function of(item:Dynamic, equals:Dynamic):TestStatus { + function deepEquals (lhs:Dynamic, rhs:Dynamic) { + if (lhs is Bytes) lhs = (lhs : ByteArray).toArray(); + if (rhs is Bytes) rhs = (rhs : ByteArray).toArray(); + if (lhs is Array && rhs is Array) { + var lhsIterator = lhs.iterator(); + var rhsIterator = rhs.iterator(); + while (lhsIterator.hasNext() && rhsIterator.hasNext()) { + if (!deepEquals(lhsIterator.next(), rhsIterator.next())) { + return false; + } + } + return !lhsIterator.hasNext() && !rhsIterator.hasNext(); + } else { + return lhs == rhs; + } + } + + return deepEquals(item, equals) ? Success : Failure; + } + + public static function multiple(...results:TestStatus) { + var items = results.toArray(); + var result:TestStatus = items[0]; + for (i in 1...items.length) { + result = switch (items[i]) { + case Failure: Failure; + case Unimplemented if (result != Failure): Unimplemented; + case Success if (![Failure, Unimplemented].contains(result)): Success; + case Skipped if (result == Success): Success; + default: result; + } + } + return result; + } +} \ No newline at end of file diff --git a/tests/generated/src/TestsToRun.hx b/tests/generated/src/TestsToRun.hx new file mode 100644 index 00000000..f3771ffe --- /dev/null +++ b/tests/generated/src/TestsToRun.hx @@ -0,0 +1,46 @@ +package; + +import tests.*; + +final tests:Array> = [ + BilateralFilterTests, + BilinearInterpolationTests, + CannyTests, + CramerTests, + GaussTests, + GaussJordanTests, + ImageHashingTests, + KMeansTests, + LaplaceTests, + PerspectiveWarpTests, + PerwittTests, + RadixTests, + RobertsCrossTests, + SimpleHoughTests, + SimpleLineDetectorTests, + SobelTests, + Array2DTests, + ByteArrayTests, + ColorTests, + HistogramTests, + ImageTests, + ImageViewTests, + Int16Point2DTests, + IntPoint2DTests, + Line2DTests, + Matrix2DTests, + Point2DTests, + Point3DTests, + QueueTests, + QueueCellTests, + Ray2DTests, + TransformationMatrix2DTests, + UInt16Point2DTests, + FormatImageExporterTests, + FormatImageLoaderTests, + VisionThreadTests, + ArrayToolsTests, + ImageToolsTests, + MathToolsTests, + // VisionTests +]; \ No newline at end of file diff --git a/tests/generated/src/tests/Array2DTests.hx b/tests/generated/src/tests/Array2DTests.hx new file mode 100644 index 00000000..bb5eb43c --- /dev/null +++ b/tests/generated/src/tests/Array2DTests.hx @@ -0,0 +1,344 @@ +package tests; + +import vision.ds.IntPoint2D; +import TestResult; +import TestStatus; + +import vision.ds.Array2D; +import haxe.iterators.ArrayIterator; + +@:access(vision.ds.Array2D) +class Array2DTests { + public static function vision_ds_Array2D__length__ShouldWork():TestResult { + try { + var width = 5; + var height = 6; + var fillWith = 0; + + var object = new vision.ds.Array2D(width, height, fillWith); + var result = object.length; + + return { + testName: "vision.ds.Array2D#length", + returned: result, + expected: 30, + status: TestStatus.of(result == 30) + } + } catch (e) { + return { + testName: "vision.ds.Array2D#length", + returned: e, + expected: 30, + status: Failure + } + } + } + + public static function vision_ds_Array2D__get_Int_Int_T__ShouldWork():TestResult { + try { + var width = 3; + var height = 3; + var fillWith = 3; + + var x = 1; + var y = 0; + + var object = new vision.ds.Array2D(width, height, fillWith); + var result = object.get(x, y); + + return { + testName: "vision.ds.Array2D#get", + returned: result, + expected: 3, + status: TestStatus.of(result == 3) + } + } catch (e) { + return { + testName: "vision.ds.Array2D#get", + returned: e, + expected: 3, + status: Failure + } + } + } + + public static function vision_ds_Array2D__set__ShouldWork():TestResult { + try { + var width = 1; + var height = 2; + var fillWith = 0; + + var x = 0; + var y = 0; + var val = 6; + + var object = new vision.ds.Array2D(width, height, fillWith); + object.set(x, y, val); + + if (object.get(x, y) != val) throw 'Array2D#set failed - expected $val at ($x, $y), got ${object.get(x, y)}'; + + return { + testName: "vision.ds.Array2D#set", + returned: null, + expected: null, + status: Success + } + } catch (e) { + return { + testName: "vision.ds.Array2D#set", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Array2D__setMultiple__ShouldWork():TestResult { + try { + var width = 2; + var height = 2; + var fillWith = 0; + + var points:Array = [{x: 0, y: 1}, {x: 1, y: 0}]; + var val = 6; + + var object = new vision.ds.Array2D(width, height, fillWith); + object.setMultiple(points, val); + + for (index in points) if (object.get(index.x, index.y) != val) throw 'Array2D#setMultiple failed - expected $val at (${index.x}, ${index.y}), got ${object.get(index.x, index.y)}'; + + return { + testName: "vision.ds.Array2D#setMultiple", + returned: null, + expected: null, + status: Success + } + } catch (e) { + return { + testName: "vision.ds.Array2D#setMultiple", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Array2D__row_Int_ArrayT__ShouldWork():TestResult { + try { + var width = 4; + var height = 4; + var fillWith = 3; + + var y = 0; + + var object = new vision.ds.Array2D(width, height, fillWith); + + object.set(0, y, 1); + object.set(1, y, 2); + object.set(2, y, 3); + object.set(3, y, 4); + + var result = object.row(y); + + return { + testName: "vision.ds.Array2D#row", + returned: result, + expected: [1, 2, 3, 4], + status: TestStatus.of(result, [1, 2, 3, 4]) + } + } catch (e) { + return { + testName: "vision.ds.Array2D#row", + returned: e, + expected: [1, 2, 3, 4], + status: Failure + } + } + } + + public static function vision_ds_Array2D__column_Int_ArrayT__ShouldWork():TestResult { + try { + var width = 4; + var height = 4; + var fillWith = 2; + + var x = 0; + + var object = new vision.ds.Array2D(width, height, fillWith); + + object.set(x, 0, 1); + object.set(x, 1, 2); + object.set(x, 2, 3); + object.set(x, 3, 4); + + var result = object.column(x); + + return { + testName: "vision.ds.Array2D#column", + returned: result, + expected: [1, 2, 3, 4], + status: TestStatus.of(result, [1, 2, 3, 4]) + } + } catch (e) { + return { + testName: "vision.ds.Array2D#column", + returned: e, + expected: [1, 2, 3, 4], + status: Failure + } + } + } + + public static function vision_ds_Array2D__iterator__ArrayIteratorT__ShouldWork():TestResult { + try { + var width = 2; + var height = 2; + var fillWith = 1; + + + var object = new vision.ds.Array2D(width, height, fillWith); + + object.set(0, 1, 2); + object.set(1, 0, 3); + object.set(1, 1, 4); + + var result = object.iterator(); + + for (i in 1...5) { + var value = result.next(); + if (value != i) throw 'Array2D#iterator failed - expected $i, got $value'; + } + + return { + testName: "vision.ds.Array2D#iterator", + returned: result, + expected: [1, 2, 3, 4].iterator(), + status: Success + } + } catch (e) { + return { + testName: "vision.ds.Array2D#iterator", + returned: e, + expected: [1, 2, 3, 4].iterator(), + status: Failure + } + } + } + + public static function vision_ds_Array2D__fill_T_Array2DT__ShouldWork():TestResult { + try { + var width = 5; + var height = 5; + var fillWith = 0; + + var value = 5; + + var object = new vision.ds.Array2D(width, height, fillWith); + var result = object.fill(value); + + return { + testName: "vision.ds.Array2D#fill", + returned: result, + expected: new Array2D(5, 5, 5), + status: TestStatus.of(object.inner, new Array2D(5, 5, 5).inner) + } + } catch (e) { + return { + testName: "vision.ds.Array2D#fill", + returned: e, + expected: new Array2D(5, 5, 5), + status: Failure + } + } + } + + public static function vision_ds_Array2D__clone__Array2DT__ShouldWork():TestResult { + try { + var width = 3; + var height = 3; + var fillWith = 3; + + + var object = new vision.ds.Array2D(width, height, fillWith); + var result = object.clone(); + + return { + testName: "vision.ds.Array2D#clone", + returned: result, + expected: new Array2D(3, 3, 3), + status: TestStatus.of(object.inner, new Array2D(width, height, fillWith).inner) + } + } catch (e) { + return { + testName: "vision.ds.Array2D#clone", + returned: e, + expected: new Array2D(3, 3, 3), + status: Failure + } + } + } + + public static function vision_ds_Array2D__toString__String__ShouldWork():TestResult { + try { + var width = 6; + var height = 6; + var fillWith = 6; + + + var object = new vision.ds.Array2D(width, height, fillWith); + var result = object.toString(); + + return { + testName: "vision.ds.Array2D#toString", + returned: result, + expected: "\n[[6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6]]", + status: TestStatus.of(result == "\n[[6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6]]") + } + } catch (e) { + return { + testName: "vision.ds.Array2D#toString", + returned: e, + expected: "\n[[6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6],\n [6, 6, 6, 6, 6, 6]]", + status: Failure + } + } + } + + public static function vision_ds_Array2D__to2DArray__ArrayArrayT__ShouldWork():TestResult { + try { + var width = 6; + var height = 6; + var fillWith = 6; + + + var object = new vision.ds.Array2D(width, height, fillWith); + var result = object.to2DArray(); + + return { + testName: "vision.ds.Array2D#to2DArray", + returned: result, + expected: [[6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6]], + status: TestStatus.of(result, [[6, 6, 6, 6, 6, 6], [6, 6, 6, 6, 6, 6], [6, 6, 6, 6, 6, 6], [6, 6, 6, 6, 6, 6], [6, 6, 6, 6, 6, 6], [6, 6, 6, 6, 6, 6]]) + } + } catch (e) { + return { + testName: "vision.ds.Array2D#to2DArray", + returned: e, + expected: [[6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6], + [6, 6, 6, 6, 6, 6]], + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/ArrayToolsTests.hx b/tests/generated/src/tests/ArrayToolsTests.hx new file mode 100644 index 00000000..7ac13548 --- /dev/null +++ b/tests/generated/src/tests/ArrayToolsTests.hx @@ -0,0 +1,311 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.tools.ArrayTools; +import haxe.Int64; +import haxe.extern.EitherType; +import haxe.ds.ArraySort; +import vision.algorithms.Radix; +import vision.tools.MathTools.*; + +@:access(vision.tools.ArrayTools) +class ArrayToolsTests { + public static function vision_tools_ArrayTools__flatten_Array_ArrayT__ShouldWork():TestResult { + try { + var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; + + var result = vision.tools.ArrayTools.flatten(array); + + return { + testName: "vision.tools.ArrayTools.flatten", + returned: result, + expected: [1, 2, 3, 4, 5, 6, 7, 8, 9], + status: TestStatus.of(result, [1, 2, 3, 4, 5, 6, 7, 8, 9]) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.flatten", + returned: e, + expected: [1, 2, 3, 4, 5, 6, 7, 8, 9], + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__raise_ArrayT_Int_ArrayArrayT__ShouldWork():TestResult { + try { + var array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + var delimiter = 4; + + var result = vision.tools.ArrayTools.raise(array, delimiter); + + return { + testName: "vision.tools.ArrayTools.raise", + returned: result, + expected: [[1, 2, 3, 4], [5, 6, 7, 8], [9]], + status: TestStatus.of(result, [[1, 2, 3, 4], [5, 6, 7, 8], [9]]) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.raise", + returned: e, + expected: [[1, 2, 3, 4], [5, 6, 7, 8], [9]], + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__raise_ArrayT_Bool_TBool_ArrayArrayT__ShouldWork():TestResult { + try { + var array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + var predicate = (number) -> number % 3 == 0; + + var result1 = vision.tools.ArrayTools.raise(array, false, predicate); + var result2 = vision.tools.ArrayTools.raise(array, true, predicate); + return { + testName: "vision.tools.ArrayTools.raise", + returned: '${result1}, then: ${result2}', + expected: '[[1, 2, 3], [4, 5, 6], [7, 8, 9]], then: [[1, 2], [3, 4, 5], [6, 7, 8], [9]]', + status: TestStatus.multiple( + TestStatus.of(result1, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]), + TestStatus.of(result2, [[1, 2], [3, 4, 5], [6, 7, 8], [9]]) + ) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.raise", + returned: e, + expected: '[[1, 2, 3], [4, 5, 6], [7, 8, 9]], then: [[1, 2], [3, 4, 5], [6, 7, 8], [9]]', + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__min_ArrayInt64_Int64__ShouldWork():TestResult { + try { + var values:Array = [Int64.make(123, 1231), Int64.make(953882, 93241), Int64.make(0, 1231), Int64.make(1, 9876812)]; + + var result = vision.tools.ArrayTools.min(values); + + return { + testName: "vision.tools.ArrayTools.min", + returned: result, + expected: Int64.make(0, 1231), + status: TestStatus.of(result == Int64.make(0, 1231)) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.min", + returned: e, + expected: Int64.make(0, 1231), + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__min_ArrayT_TFloat_T__ShouldWork():TestResult { + try { + var values = ["hey", "whats", "up", "fellas?"]; + var valueFunction = (string) -> string.length; + + var result = vision.tools.ArrayTools.min(values, valueFunction); + + return { + testName: "vision.tools.ArrayTools.min", + returned: result, + expected: "up", + status: TestStatus.of(result == "up") + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.min", + returned: e, + expected: "up", + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__max_ArrayInt64_Int64__ShouldWork():TestResult { + try { + var values = [Int64.make(123, 1231), Int64.make(953882, 93241), Int64.make(0, 1231), Int64.make(1, 9876812)]; + + var result = vision.tools.ArrayTools.max(values); + + return { + testName: "vision.tools.ArrayTools.max", + returned: result, + expected: Int64.make(953882, 93241), + status: TestStatus.of(result == Int64.make(953882, 93241)) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.max", + returned: e, + expected: Int64.make(953882, 93241), + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__max_ArrayT_TFloat_T__ShouldWork():TestResult { + try { + var values = ["hey", "whats", "up", "fellas?"]; + var valueFunction = (string) -> string.length; + + var result = vision.tools.ArrayTools.max(values, valueFunction); + + return { + testName: "vision.tools.ArrayTools.max", + returned: result, + expected: "fellas?", + status: TestStatus.of(result == "fellas?") + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.max", + returned: e, + expected: "fellas?", + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__average_ArrayInt64_Float__ShouldWork():TestResult { + try { + var values = [Int64.make(123, 1231), Int64.make(953882, 93241), Int64.make(0, 1231), Int64.make(1, 9876812)]; + + var result = vision.tools.ArrayTools.average(values); + + return { + testName: "vision.tools.ArrayTools.average", + returned: result, + expected: 238500, + status: TestStatus.of(result == 238500) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.average", + returned: e, + expected: 238500, + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__median_ArrayInt_Int__ShouldWork():TestResult { + try { + var values = [1, 1, 2, 2, 3, 3, 3, 3, 3]; + + var result = vision.tools.ArrayTools.median(values); + + return { + testName: "vision.tools.ArrayTools.median", + returned: result, + expected: 3, + status: TestStatus.of(result == 3) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.median", + returned: e, + expected: 3, + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__median_ArrayInt64_Int64__ShouldWork():TestResult { + try { + var values = [Int64.make(0, 1), Int64.make(0, 1), Int64.make(0, 2), Int64.make(0, 2), Int64.make(0, 3), Int64.make(0, 3), Int64.make(0, 3), Int64.make(0, 3), Int64.make(0, 3)]; + + var result = vision.tools.ArrayTools.median(values); + + return { + testName: "vision.tools.ArrayTools.median", + returned: result, + expected: Int64.make(0, 3), + status: TestStatus.of(result == Int64.make(0, 3)) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.median", + returned: e, + expected: Int64.make(0, 3), + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__median_ArrayFloat_Float__ShouldWork():TestResult { + try { + var values = [0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.3, 0.3, 0.3]; + + var result = vision.tools.ArrayTools.median(values); + + return { + testName: "vision.tools.ArrayTools.median", + returned: result, + expected: 0.3, + status: TestStatus.of(result == 0.3) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.median", + returned: e, + expected: 0.3, + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__distanceTo__ShouldWork():TestResult { + try { + var array = ["hey", "whats", "up", "fellas?"]; + var to = ["tung", "tung", "tung", "sahur"]; + var distanceFunction = (str1, str2) -> str2.length - str1.length; + + var result = vision.tools.ArrayTools.distanceTo(array, to, distanceFunction); + + return { + testName: "vision.tools.ArrayTools.distanceTo", + returned: result, + expected: 0, + status: TestStatus.of(result == 0) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.distanceTo", + returned: e, + expected: 0, + status: Failure + } + } + } + + public static function vision_tools_ArrayTools__distinct_ArrayT_ArrayT__ShouldWork():TestResult { + try { + var array = [0, 0, 0, 1, 1, 1, 2, 2, 2]; + + var result = vision.tools.ArrayTools.distinct(array); + + return { + testName: "vision.tools.ArrayTools.distinct", + returned: result, + expected: [0, 1, 2], + status: TestStatus.of(result, [0, 1, 2]) + } + } catch (e) { + return { + testName: "vision.tools.ArrayTools.distinct", + returned: e, + expected: [0, 1, 2], + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/BilateralFilterTests.hx b/tests/generated/src/tests/BilateralFilterTests.hx new file mode 100644 index 00000000..36e7f9aa --- /dev/null +++ b/tests/generated/src/tests/BilateralFilterTests.hx @@ -0,0 +1,39 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.BilateralFilter; +import haxe.ds.Vector; +import vision.ds.Color; +import vision.ds.Array2D; +import vision.ds.Image; + +@:access(vision.algorithms.BilateralFilter) +class BilateralFilterTests { + public static function vision_algorithms_BilateralFilter__filter_Image_Float_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var distanceSigma = 0.0; + var intensitySigma = 0.0; + + var result = vision.algorithms.BilateralFilter.filter(image, distanceSigma, intensitySigma); + + return { + testName: "vision.algorithms.BilateralFilter.filter", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.BilateralFilter.filter", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/BilinearInterpolationTests.hx b/tests/generated/src/tests/BilinearInterpolationTests.hx new file mode 100644 index 00000000..3c0d1124 --- /dev/null +++ b/tests/generated/src/tests/BilinearInterpolationTests.hx @@ -0,0 +1,64 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.BilinearInterpolation; +import vision.ds.Color; +import vision.ds.Image; +import vision.tools.MathTools.*; + +@:access(vision.algorithms.BilinearInterpolation) +class BilinearInterpolationTests { + public static function vision_algorithms_BilinearInterpolation__interpolate_Image_Int_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var width = 0; + var height = 0; + + var result = vision.algorithms.BilinearInterpolation.interpolate(image, width, height); + + return { + testName: "vision.algorithms.BilinearInterpolation.interpolate", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.BilinearInterpolation.interpolate", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_BilinearInterpolation__interpolateMissingPixels_Image_Int_Int_Int_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var kernelRadiusX = 0; + var kernelRadiusY = 0; + var minX = 0; + var minY = 0; + + var result = vision.algorithms.BilinearInterpolation.interpolateMissingPixels(image, kernelRadiusX, kernelRadiusY, minX, minY); + + return { + testName: "vision.algorithms.BilinearInterpolation.interpolateMissingPixels", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.BilinearInterpolation.interpolateMissingPixels", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/ByteArrayTests.hx b/tests/generated/src/tests/ByteArrayTests.hx new file mode 100644 index 00000000..ce3b0b14 --- /dev/null +++ b/tests/generated/src/tests/ByteArrayTests.hx @@ -0,0 +1,497 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.ByteArray; +import haxe.Int64; +import vision.tools.MathTools; +import haxe.Serializer; +import haxe.io.Bytes; + +@:access(vision.ds.ByteArray) +class ByteArrayTests { + public static function vision_ds_ByteArray__from_Int_ByteArray__ShouldWork():TestResult { + try { + var value = 0x00010000; + + var result = vision.ds.ByteArray.from(value); + + var expected = new ByteArray(4); + expected.write(2, 1); + return { + testName: "vision.ds.ByteArray.from", + returned: result, + expected: expected, + status: TestStatus.of(result, expected) + } + } catch (e) { + var expected = new ByteArray(4); + expected.write(2, 1); + return { + testName: "vision.ds.ByteArray.from", + returned: e, + expected: expected, + status: Failure + } + } + } + + public static function vision_ds_ByteArray__from_Int64_ByteArray__ShouldWork():TestResult { + try { + var value:Int64 = Int64.make(1, 1); + + var result = vision.ds.ByteArray.from(value); + + var expected = new ByteArray(8); + expected.write(0, 1); + expected.write(4, 1); + return { + testName: "vision.ds.ByteArray.from", + returned: result, + expected: expected, + status: TestStatus.of(result, expected) + } + } catch (e) { + var expected = new ByteArray(8); + expected.write(0, 1); + expected.write(4, 1); + return { + testName: "vision.ds.ByteArray.from", + returned: e, + expected: expected, + status: Failure + } + } + } + + public static function vision_ds_ByteArray__from_Float_ByteArray__ShouldWork():TestResult { + try { + var value = 1.1; + + var result = vision.ds.ByteArray.from(value); + + var expected = new ByteArray(8); + expected.setDouble(0, 1.1); + return { + testName: "vision.ds.ByteArray.from", + returned: result, + expected: expected, + status: TestStatus.of(result, expected) + } + } catch (e) { + var expected = new ByteArray(8); + expected.setDouble(0, 1.1); + return { + testName: "vision.ds.ByteArray.from", + returned: e, + expected: expected, + status: Failure + } + } + } + + public static function vision_ds_ByteArray__from_Bool_ByteArray__ShouldWork():TestResult { + try { + var value = false; + + var result = vision.ds.ByteArray.from(value); + + return { + testName: "vision.ds.ByteArray.from", + returned: result, + expected: new ByteArray(1, 0), + status: TestStatus.of(result, new ByteArray(1, 0)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray.from", + returned: e, + expected: new ByteArray(1, 0), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__from_String_haxeioEncoding_ByteArray__ShouldWork():TestResult { + try { + var value = "Hello There!"; + var encoding:haxe.io.Encoding = UTF8; + + var result = vision.ds.ByteArray.from(value, encoding); + + return { + testName: "vision.ds.ByteArray.from", + returned: result, + expected: Bytes.ofString("Hello There!", UTF8), + status: TestStatus.of(result, Bytes.ofString("Hello There!", UTF8)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray.from", + returned: e, + expected: Bytes.ofString("Hello There!", UTF8), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__from_Dynamic_ByteArray__ShouldWork():TestResult { + try { + var value:Dynamic = {hey: "There!"}; + + var result = vision.ds.ByteArray.from(value); + + var expected = Bytes.ofString(Serializer.run(value)); + return { + testName: "vision.ds.ByteArray.from", + returned: result, + expected: expected, + status: TestStatus.of(result, expected) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray.from", + returned: e, + expected: Bytes.ofString(Serializer.run({hey: "There!"})), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__setUInt8__ShouldWork():TestResult { + try { + var length = 1; + var fillWith = 0; + + var pos = 0; + var v = 65; + + var object = new vision.ds.ByteArray(length, fillWith); + object.setUInt8(pos, v); + + return { + testName: "vision.ds.ByteArray#setUInt8", + returned: object, + expected: ByteArray.from([65], 1), + status: TestStatus.of(object, ByteArray.from([65], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#setUInt8", + returned: e, + expected: ByteArray.from([65], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__getUInt8_Int_Int__ShouldWork():TestResult { + try { + var length = 1; + var fillWith = 34; + + var pos = 0; + + var object = new vision.ds.ByteArray(length, fillWith); + var result = object.getUInt8(pos); + + return { + testName: "vision.ds.ByteArray#getUInt8", + returned: result, + expected: 34, + status: TestStatus.of(result == 34) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#getUInt8", + returned: e, + expected: 34, + status: Failure + } + } + } + + public static function vision_ds_ByteArray__setUInt32__ShouldWork():TestResult { + try { + var length = 4; + var fillWith = 0; + + var pos = 0; + var value:UInt = 0xFF763400; + + var object = new vision.ds.ByteArray(length, fillWith); + object.setUInt32(pos, value); + + return { + testName: "vision.ds.ByteArray#setUInt32", + returned: object, + expected: ByteArray.from([0x00, 0x34, 0x76, 0xFF], 1), + status: TestStatus.of(object, ByteArray.from([0x00, 0x34, 0x76, 0xFF], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#setUInt32", + returned: e, + expected: ByteArray.from([0x00, 0x34, 0x76, 0xFF], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__getUInt32_Int_UInt__ShouldWork():TestResult { + try { + var length = 4; + var fillWith = 0; + + var pos = 0; + + var object = new vision.ds.ByteArray(length, fillWith); + object.setUInt32(pos, 0x0019F43E); + var result = object.getUInt32(pos); + + return { + testName: "vision.ds.ByteArray#getUInt32", + returned: result, + expected: 0x0019F43E, + status: TestStatus.of(result == 0x0019F43E) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#getUInt32", + returned: e, + expected: 0x0019F43E, + status: Failure + } + } + } + + public static function vision_ds_ByteArray__setInt8__ShouldWork():TestResult { + try { + var length = 1; + var fillWith = 0; + + var pos = 0; + var v = 99; + + var object = new vision.ds.ByteArray(length, fillWith); + object.setInt8(pos, v); + + return { + testName: "vision.ds.ByteArray#setInt8", + returned: object, + expected: ByteArray.from([99], 1), + status: TestStatus.of(object, ByteArray.from([99], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#setInt8", + returned: e, + expected: ByteArray.from([99], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__getInt8_Int_Int__ShouldWork():TestResult { + try { + var length = 1; + var fillWith = 193; + + var pos = 0; + + var object = new vision.ds.ByteArray(length, fillWith); + var result = object.getInt8(pos); + + return { + testName: "vision.ds.ByteArray#getInt8", + returned: result, + expected: -65, + status: TestStatus.of(result == -65) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#getInt8", + returned: e, + expected: -65, + status: Failure + } + } + } + + public static function vision_ds_ByteArray__setBytes__ShouldWork():TestResult { + try { + var length = 5; + var fillWith = 1; + + var pos = 1; + var array = vision.ds.ByteArray.from([2, 3, 4, 5], 1); + + var object = new vision.ds.ByteArray(length, fillWith); + object.setBytes(pos, array); + + return { + testName: "vision.ds.ByteArray#setBytes", + returned: object, + expected: ByteArray.from([1, 2, 3, 4, 5], 1), + status: TestStatus.of(object, ByteArray.from([1, 2, 3, 4, 5], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#setBytes", + returned: e, + expected: ByteArray.from([1, 2, 3, 4, 5], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__getBytes_Int_Int_ByteArray__ShouldWork():TestResult { + try { + var pos = 1; + var length = 3; + + var object = ByteArray.from([1, 2, 3, 4, 5], 1); + var result = object.getBytes(pos, length); + + return { + testName: "vision.ds.ByteArray#getBytes", + returned: result, + expected: ByteArray.from([2, 3, 4], 1), + status: TestStatus.of(result, ByteArray.from([2, 3, 4], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#getBytes", + returned: e, + expected: ByteArray.from([2, 3, 4], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__resize__ShouldWork():TestResult { + try { + var length = 4; + var fillWith = 2; + + var object = new vision.ds.ByteArray(length, fillWith); + object.resize(5); + + return { + testName: "vision.ds.ByteArray#resize", + returned: object, + expected: ByteArray.from([2, 2, 2, 2, 0], 1), + status: TestStatus.of(object, ByteArray.from([2, 2, 2, 2, 0], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#resize", + returned: e, + expected: ByteArray.from([2, 2, 2, 2, 0], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__concat_ByteArray_ByteArray__ShouldWork():TestResult { + try { + var length = 2; + var fillWith = 0xEE; + + var array = vision.ds.ByteArray.from(0xF1F2F3F4); + + var object = new vision.ds.ByteArray(length, fillWith); + var result = object.concat(array); + + return { + testName: "vision.ds.ByteArray#concat", + returned: result, + expected: ByteArray.from([0xEE, 0xEE, 0xF4, 0xF3, 0xF2, 0xF1], 1), + status: TestStatus.of(result, ByteArray.from([0xEE, 0xEE, 0xF4, 0xF3, 0xF2, 0xF1], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#concat", + returned: e, + expected: ByteArray.from([0xEE, 0xEE, 0xF4, 0xF3, 0xF2, 0xF1], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__isEmpty__Bool__ShouldWork():TestResult { + try { + var length = 0; + var fillWith = 0; + + + var object = new vision.ds.ByteArray(length, fillWith); + var result = object.isEmpty(); + + return { + testName: "vision.ds.ByteArray#isEmpty", + returned: result, + expected: true, + status: TestStatus.of(result == true) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#isEmpty", + returned: e, + expected: true, + status: Failure + } + } + } + + public static function vision_ds_ByteArray__toArray__ArrayInt__ShouldWork():TestResult { + try { + var object = ByteArray.from(0x34E1B2AA); + var result = object.toArray(); + + return { + testName: "vision.ds.ByteArray#toArray", + returned: result, + expected: ByteArray.from([0xAA, 0xB2, 0xE1, 0x34], 1), + status: TestStatus.of(result, ByteArray.from([0xAA, 0xB2, 0xE1, 0x34], 1)) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#toArray", + returned: e, + expected: ByteArray.from([0xAA, 0xB2, 0xE1, 0x34], 1), + status: Failure + } + } + } + + public static function vision_ds_ByteArray__fromArray__ByteArray__ShouldWork():TestResult { + var expected = Bytes.alloc(16); + expected.setInt32(0, 0x01); + expected.setInt32(4, 0xEE10); + expected.setInt32(8, 0xFF8709); + expected.setInt32(12, 0x12345678); + try { + var value = [0x01, 0xEE10, 0xFF8709, 0x12345678]; + + var result = ByteArray.from(value, 4); + + return { + testName: "vision.ds.ByteArray.from", + returned: result, + expected: expected, + status: TestStatus.of(result, expected) + } + } catch (e) { + return { + testName: "vision.ds.ByteArray#toArray", + returned: e, + expected: expected, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/CannyTests.hx b/tests/generated/src/tests/CannyTests.hx new file mode 100644 index 00000000..66bed2ba --- /dev/null +++ b/tests/generated/src/tests/CannyTests.hx @@ -0,0 +1,128 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.Canny; +import vision.ds.Color; +import vision.ds.Image; +import vision.ds.canny.CannyObject; + +@:access(vision.algorithms.Canny) +class CannyTests { + public static function vision_algorithms_Canny__grayscale_CannyObject_CannyObject__ShouldWork():TestResult { + try { + var image:CannyObject = null; + + var result = vision.algorithms.Canny.grayscale(image); + + return { + testName: "vision.algorithms.Canny.grayscale", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Canny.grayscale", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Canny__applyGaussian_CannyObject_Int_Float_CannyObject__ShouldWork():TestResult { + try { + var image:CannyObject = null; + var size = 0; + var sigma = 0.0; + + var result = vision.algorithms.Canny.applyGaussian(image, size, sigma); + + return { + testName: "vision.algorithms.Canny.applyGaussian", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Canny.applyGaussian", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Canny__applySobelFilters_CannyObject_CannyObject__ShouldWork():TestResult { + try { + var image:CannyObject = null; + + var result = vision.algorithms.Canny.applySobelFilters(image); + + return { + testName: "vision.algorithms.Canny.applySobelFilters", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Canny.applySobelFilters", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Canny__nonMaxSuppression_CannyObject_CannyObject__ShouldWork():TestResult { + try { + var image:CannyObject = null; + + var result = vision.algorithms.Canny.nonMaxSuppression(image); + + return { + testName: "vision.algorithms.Canny.nonMaxSuppression", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Canny.nonMaxSuppression", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Canny__applyHysteresis_CannyObject_Float_Float_CannyObject__ShouldWork():TestResult { + try { + var image:CannyObject = null; + var highThreshold = 0.0; + var lowThreshold = 0.0; + + var result = vision.algorithms.Canny.applyHysteresis(image, highThreshold, lowThreshold); + + return { + testName: "vision.algorithms.Canny.applyHysteresis", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Canny.applyHysteresis", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/ColorTests.hx b/tests/generated/src/tests/ColorTests.hx new file mode 100644 index 00000000..1517f8b7 --- /dev/null +++ b/tests/generated/src/tests/ColorTests.hx @@ -0,0 +1,1365 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Color; +import vision.tools.ArrayTools; +import vision.tools.MathTools; + +@:access(vision.ds.Color) +class ColorTests { + public static function vision_ds_Color__red__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.red; + + return { + testName: "vision.ds.Color#red", + returned: result, + expected: 0xFF, + status: TestStatus.of(result == 0xFF) + } + } catch (e) { + return { + testName: "vision.ds.Color#red", + returned: e, + expected: 0xFF, + status: Failure + } + } + } + + public static function vision_ds_Color__blue__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.blue; + + return { + testName: "vision.ds.Color#blue", + returned: result, + expected: 0x34, + status: TestStatus.of(result == 0x34) + } + } catch (e) { + return { + testName: "vision.ds.Color#blue", + returned: e, + expected: 0x34, + status: Failure + } + } + } + + public static function vision_ds_Color__green__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.green; + + return { + testName: "vision.ds.Color#green", + returned: result, + expected: 0x76, + status: TestStatus.of(result == 0x76) + } + } catch (e) { + return { + testName: "vision.ds.Color#green", + returned: e, + expected: 0x76, + status: Failure + } + } + } + + public static function vision_ds_Color__alpha__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.alpha; + + return { + testName: "vision.ds.Color#alpha", + returned: result, + expected: 0xFF, + status: TestStatus.of(result == 0xFF) + } + } catch (e) { + return { + testName: "vision.ds.Color#alpha", + returned: e, + expected: 0xFF, + status: Failure + } + } + } + + public static function vision_ds_Color__redFloat__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.redFloat; + + return { + testName: "vision.ds.Color#redFloat", + returned: result, + expected: 1.0, + status: TestStatus.of(result == 1.0) + } + } catch (e) { + return { + testName: "vision.ds.Color#redFloat", + returned: e, + expected: 1.0, + status: Failure + } + } + } + + public static function vision_ds_Color__blueFloat__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.blueFloat; + + return { + testName: "vision.ds.Color#blueFloat", + returned: result, + expected: 0x34 / 255.0, + status: TestStatus.of(result == 0x34 / 255.0) + } + } catch (e) { + return { + testName: "vision.ds.Color#blueFloat", + returned: e, + expected: 0x34 / 255.0, + status: Failure + } + } + } + + public static function vision_ds_Color__greenFloat__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.greenFloat; + + return { + testName: "vision.ds.Color#greenFloat", + returned: result, + expected: 0x76 / 255.0, + status: TestStatus.of(result == 0x76 / 255.0) + } + } catch (e) { + return { + testName: "vision.ds.Color#greenFloat", + returned: e, + expected: 0x76 / 255.0, + status: Failure + } + } + } + + public static function vision_ds_Color__alphaFloat__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.alphaFloat; + + return { + testName: "vision.ds.Color#alphaFloat", + returned: result, + expected: 1.0, + status: TestStatus.of(result == 1.0) + } + } catch (e) { + return { + testName: "vision.ds.Color#alphaFloat", + returned: e, + expected: 1.0, + status: Failure + } + } + } + + public static function vision_ds_Color__cyan__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.cyan; + + return { + testName: "vision.ds.Color#cyan", + returned: result, + expected: 0, + status: TestStatus.of(result == 0) + } + } catch (e) { + return { + testName: "vision.ds.Color#cyan", + returned: e, + expected: 0, + status: Failure + } + } + } + + public static function vision_ds_Color__magenta__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.magenta; + + return { + testName: "vision.ds.Color#magenta", + returned: result, + expected: 54, + status: TestStatus.of(result == 54) + } + } catch (e) { + return { + testName: "vision.ds.Color#magenta", + returned: e, + expected: 54, + status: Failure + } + } + } + + public static function vision_ds_Color__yellow__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.yellow; + + return { + testName: "vision.ds.Color#yellow", + returned: result, + expected: 80, + status: TestStatus.of(result == 80) + } + } catch (e) { + return { + testName: "vision.ds.Color#yellow", + returned: e, + expected: 80, + status: Failure + } + } + } + + public static function vision_ds_Color__black__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.black; + + return { + testName: "vision.ds.Color#black", + returned: result, + expected: 0, + status: TestStatus.of(result == 0) + } + } catch (e) { + return { + testName: "vision.ds.Color#black", + returned: e, + expected: 0, + status: Failure + } + } + } + + public static function vision_ds_Color__rgb__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.rgb; + + return { + testName: "vision.ds.Color#rgb", + returned: result, + expected: 0xFF7634, + status: TestStatus.of(result == 0xFF7634) + } + } catch (e) { + return { + testName: "vision.ds.Color#rgb", + returned: e, + expected: 0xFF7634, + status: Failure + } + } + } + + public static function vision_ds_Color__hue__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.hue; + + return { + testName: "vision.ds.Color#hue", + returned: result, + expected: 20.0, + status: TestStatus.of(result == 20.0) + } + } catch (e) { + return { + testName: "vision.ds.Color#hue", + returned: e, + expected: 20.0, + status: Failure + } + } + } + + public static function vision_ds_Color__saturation__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.saturation; + + return { + testName: "vision.ds.Color#saturation", + returned: result, + expected: 1.0, + status: TestStatus.of(result == 1.0) + } + } catch (e) { + return { + testName: "vision.ds.Color#saturation", + returned: e, + expected: 1.0, + status: Failure + } + } + } + + public static function vision_ds_Color__brightness__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.brightness; + + return { + testName: "vision.ds.Color#brightness", + returned: result, + expected: 1, + status: TestStatus.of(result == 1) + } + } catch (e) { + return { + testName: "vision.ds.Color#brightness", + returned: e, + expected: 1, + status: Failure + } + } + } + + public static function vision_ds_Color__lightness__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var object = new vision.ds.Color(value); + var result = object.lightness; + + return { + testName: "vision.ds.Color#lightness", + returned: result, + expected: 0.6, + status: TestStatus.of(result == 0.6) + } + } catch (e) { + return { + testName: "vision.ds.Color#lightness", + returned: e, + expected: 0.6, + status: Failure + } + } + } + + public static function vision_ds_Color__fromInt_Int_Color__ShouldWork():TestResult { + try { + var value = 0xFFFF7634; + + var result = vision.ds.Color.fromInt(value); + + return { + testName: "vision.ds.Color.fromInt", + returned: result, + expected: 0xFFFF7634, + status: TestStatus.of(result == 0xFFFF7634) + } + } catch (e) { + return { + testName: "vision.ds.Color.fromInt", + returned: e, + expected: 0xFFFF7634, + status: Failure + } + } + } + + public static function vision_ds_Color__fromRGBA_Int_Int_Int_Int_Color__ShouldWork():TestResult { + try { + var Red = 128; + var Green = 128; + var Blue = 34; + var Alpha = 44; + + var result = vision.ds.Color.fromRGBA(Red, Green, Blue, Alpha); + + return { + testName: "vision.ds.Color.fromRGBA", + returned: result, + expected: 0x2C808022, + status: TestStatus.of(result == 0x2C808022) + } + } catch (e) { + return { + testName: "vision.ds.Color.fromRGBA", + returned: e, + expected: 0x2C808022, + status: Failure + } + } + } + + public static function vision_ds_Color__from8Bit_Int_Color__ShouldWork():TestResult { + try { + var Value = 0x11; + + var result = vision.ds.Color.from8Bit(Value); + + return { + testName: "vision.ds.Color.from8Bit", + returned: result, + expected: 0xFF111111, + status: TestStatus.of(result == 0xFF111111) + } + } catch (e) { + return { + testName: "vision.ds.Color.from8Bit", + returned: e, + expected: 0xFF111111, + status: Failure + } + } + } + + public static function vision_ds_Color__fromFloat_Float_Color__ShouldWork():TestResult { + try { + var Value = 0.5; + + var result = vision.ds.Color.fromFloat(Value); + + return { + testName: "vision.ds.Color.fromFloat", + returned: result, + expected: 0xFF808080, + status: TestStatus.of(result == 0xFF808080) + } + } catch (e) { + return { + testName: "vision.ds.Color.fromFloat", + returned: e, + expected: 0xFF808080, + status: Failure + } + } + } + + public static function vision_ds_Color__fromRGBAFloat_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var Red = 0.5; + var Green = 0.5; + var Blue = 0.5; + var Alpha = 0.5; + + var result = vision.ds.Color.fromRGBAFloat(Red, Green, Blue, Alpha); + + return { + testName: "vision.ds.Color.fromRGBAFloat", + returned: result, + expected: 0x80808080, + status: TestStatus.of(result == 0x80808080) + } + } catch (e) { + return { + testName: "vision.ds.Color.fromRGBAFloat", + returned: e, + expected: 0x80808080, + status: Failure + } + } + } + + public static function vision_ds_Color__fromCMYK_Float_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var Cyan = 0.0; + var Magenta = 0.0; + var Yellow = 0.0; + var Black = 0.0; + var Alpha = 0.0; + + var result = vision.ds.Color.fromCMYK(Cyan, Magenta, Yellow, Black, Alpha); + + return { + testName: "vision.ds.Color.fromCMYK", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color.fromCMYK", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__fromHSB_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var Hue = 0.0; + var Saturation = 0.0; + var Brightness = 0.0; + var Alpha = 0.0; + + var result = vision.ds.Color.fromHSB(Hue, Saturation, Brightness, Alpha); + + return { + testName: "vision.ds.Color.fromHSB", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color.fromHSB", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__fromHSL_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var Hue = 0.0; + var Saturation = 0.0; + var Lightness = 0.0; + var Alpha = 0.0; + + var result = vision.ds.Color.fromHSL(Hue, Saturation, Lightness, Alpha); + + return { + testName: "vision.ds.Color.fromHSL", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color.fromHSL", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__fromString_String_NullColor__ShouldWork():TestResult { + try { + var str = ""; + var sets = ["0x00FF00" => 0xFF00FF00, + "0xAA4578C2" => 0xAA4578C2, + "#0000FF" => 0xFF0000FF, + "#3F000011" => 0x3F000011, + "GRAY" => 0xFF808080, + "blue" => 0xFF0000FF]; + var result = [for (key in sets.keys()) key].map(key -> Color.fromString(key)); + + return { + testName: "vision.ds.Color.fromString", + returned: result, + expected: [for (value in sets.iterator()) value], + status: TestStatus.of(result == [for (value in sets.iterator()) value]) + } + } catch (e) { + return { + testName: "vision.ds.Color.fromString", + returned: e, + expected: [0xFF00FF00, 0xAA4578C2, 0xFF0000FF, 0x3F000011, 0xFF808080, 0xFF0000FF], + status: Failure + } + } + } + + public static function vision_ds_Color__getHSBColorWheel_Int_ArrayColor__ShouldWork():TestResult { + try { + var Alpha = 0; + + var result = vision.ds.Color.getHSBColorWheel(Alpha); + + return { + testName: "vision.ds.Color.getHSBColorWheel", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color.getHSBColorWheel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__interpolate_Color_Color_Float_Color__ShouldWork():TestResult { + try { + var Color1:Color = 0xFF00FF00; + var Color2:Color = 0x00FF00FF; + var Factor = 0.5; + + var result = vision.ds.Color.interpolate(Color1, Color2, Factor); + + return { + testName: "vision.ds.Color.interpolate", + returned: result, + expected: 0x7F7F7F7F, + status: TestStatus.of(result == 0x7F7F7F7F) + } + } catch (e) { + return { + testName: "vision.ds.Color.interpolate", + returned: e, + expected: 0x7F7F7F7F, + status: Failure + } + } + } + + public static function vision_ds_Color__gradient_Color_Color_Int_FloatFloat_ArrayColor__ShouldWork():TestResult { + try { + var Color1:Color = null; + var Color2:Color = null; + var Steps = 0; + var Ease = (_) -> null; + + var result = vision.ds.Color.gradient(Color1, Color2, Steps, Ease); + + return { + testName: "vision.ds.Color.gradient", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color.gradient", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__makeRandom_Bool_Int_Color__ShouldWork():TestResult { + try { + var alphaValue = 0; + + var result = vision.ds.Color.makeRandom(alphaValue); + + return { + testName: "vision.ds.Color.makeRandom", + returned: result.alpha, + expected: 0, + status: TestStatus.of(result.alpha == 0) + } + } catch (e) { + return { + testName: "vision.ds.Color.makeRandom", + returned: e, + expected: 0, + status: Failure + } + } + } + + public static function vision_ds_Color__multiply_Color_Color_Color__ShouldWork():TestResult { + try { + var lhs:Color = 0x020202; + var rhs:Color = 0x030303; + + var result = vision.ds.Color.multiply(lhs, rhs); + + return { + testName: "vision.ds.Color.multiply", + returned: result, + expected: 0x060606, + status: TestStatus.of(result == 0x060606) + } + } catch (e) { + return { + testName: "vision.ds.Color.multiply", + returned: e, + expected: 0x060606, + status: Failure + } + } + } + + public static function vision_ds_Color__add_Color_Color_Color__ShouldWork():TestResult { + try { + var lhs:Color = 0x020202; + var rhs:Color = 0x030303; + + var result = vision.ds.Color.add(lhs, rhs); + + return { + testName: "vision.ds.Color.add", + returned: result, + expected: 0x050505, + status: TestStatus.of(result == 0x050505) + } + } catch (e) { + return { + testName: "vision.ds.Color.add", + returned: e, + expected: 0x050505, + status: Failure + } + } + } + + public static function vision_ds_Color__subtract_Color_Color_Color__ShouldWork():TestResult { + try { + var lhs:Color = 0x040404; + var rhs:Color = 0x030303; + + var result = vision.ds.Color.subtract(lhs, rhs); + + return { + testName: "vision.ds.Color.subtract", + returned: result, + expected: 0x010101, + status: TestStatus.of(result == 0x010101) + } + } catch (e) { + return { + testName: "vision.ds.Color.subtract", + returned: e, + expected: 0x010101, + status: Failure + } + } + } + + public static function vision_ds_Color__divide_Color_Color_Color__ShouldWork():TestResult { + try { + var lhs:Color = 0x060606; + var rhs:Color = 0x010101; + + var result = vision.ds.Color.divide(lhs, rhs); + + return { + testName: "vision.ds.Color.divide", + returned: result, + expected: 0x060606, + status: TestStatus.of(result == 0x060606) + } + } catch (e) { + return { + testName: "vision.ds.Color.divide", + returned: e, + expected: 0x060606, + status: Failure + } + } + } + + public static function vision_ds_Color__distanceBetween_Color_Color_Bool_Float__ShouldWork():TestResult { + try { + var lhs:Color = 0x020202; + var rhs:Color = 0x010101; + var considerTransparency = false; + + var result = vision.ds.Color.distanceBetween(lhs, rhs, considerTransparency); + + return { + testName: "vision.ds.Color.distanceBetween", + returned: result, + expected: MathTools.SQRT3, + status: TestStatus.of(result == MathTools.SQRT3) + } + } catch (e) { + return { + testName: "vision.ds.Color.distanceBetween", + returned: e, + expected: MathTools.SQRT3, + status: Failure + } + } + } + + public static function vision_ds_Color__differenceBetween_Color_Color_Bool_Float__ShouldWork():TestResult { + try { + var lhs:Color = Color.WHITE; + var rhs:Color = Color.BLACK; + var considerTransparency = false; + + var result = vision.ds.Color.differenceBetween(lhs, rhs, considerTransparency); + + return { + testName: "vision.ds.Color.differenceBetween", + returned: result, + expected: 1, + status: TestStatus.of(result == 1) + } + } catch (e) { + return { + testName: "vision.ds.Color.differenceBetween", + returned: e, + expected: 1, + status: Failure + } + } + } + + public static function vision_ds_Color__getAverage_ArrayColor_Bool_Color__ShouldWork():TestResult { + try { + var fromColors = [Color.RED, Color.GREEN, Color.BLUE]; + var considerTransparency = false; + + var result = vision.ds.Color.getAverage(fromColors, considerTransparency); + + return { + testName: "vision.ds.Color.getAverage", + returned: result, + expected: 0xFF555555, + status: TestStatus.of(result == 0xFF555555) + } + } catch (e) { + return { + testName: "vision.ds.Color.getAverage", + returned: e, + expected: 0xFF555555, + status: Failure + } + } + } + + public static function vision_ds_Color__getComplementHarmony__Color__ShouldWork():TestResult { + try { + var value = 0; + + + var object = new vision.ds.Color(value); + var result = object.getComplementHarmony(); + + return { + testName: "vision.ds.Color#getComplementHarmony", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color#getComplementHarmony", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__getAnalogousHarmony_Int_Harmony__ShouldWork():TestResult { + try { + var value = 0; + + var Threshold = 0; + + var object = new vision.ds.Color(value); + var result = object.getAnalogousHarmony(Threshold); + + return { + testName: "vision.ds.Color#getAnalogousHarmony", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color#getAnalogousHarmony", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__getSplitComplementHarmony_Int_Harmony__ShouldWork():TestResult { + try { + var value = 0; + + var Threshold = 0; + + var object = new vision.ds.Color(value); + var result = object.getSplitComplementHarmony(Threshold); + + return { + testName: "vision.ds.Color#getSplitComplementHarmony", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color#getSplitComplementHarmony", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__getTriadicHarmony__TriadicHarmony__ShouldWork():TestResult { + try { + var value = 0; + + + var object = new vision.ds.Color(value); + var result = object.getTriadicHarmony(); + + return { + testName: "vision.ds.Color#getTriadicHarmony", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color#getTriadicHarmony", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__to24Bit__Color__ShouldWork():TestResult { + try { + var value = 0x55555555; + + + var object = new vision.ds.Color(value); + var result = object.to24Bit(); + + return { + testName: "vision.ds.Color#to24Bit", + returned: result, + expected: 0x555555, + status: TestStatus.of(result == 0x555555) + } + } catch (e) { + return { + testName: "vision.ds.Color#to24Bit", + returned: e, + expected: 0x555555, + status: Failure + } + } + } + + public static function vision_ds_Color__toHexString_Bool_Bool_String__ShouldWork():TestResult { + try { + var value = Color.ROYAL_BLUE; + + var Alpha = true; + var Prefix = true; + + var object = new vision.ds.Color(value); + var result = object.toHexString(Alpha, Prefix); + + return { + testName: "vision.ds.Color#toHexString", + returned: result, + expected: "0xFF4169E1", + status: TestStatus.of(result == "0xFF4169E1") + } + } catch (e) { + return { + testName: "vision.ds.Color#toHexString", + returned: e, + expected: "0xFF4169E1", + status: Failure + } + } + } + + public static function vision_ds_Color__toWebString__String__ShouldWork():TestResult { + try { + var value = Color.ROYAL_BLUE; + + + var object = new vision.ds.Color(value); + var result = object.toWebString(); + + return { + testName: "vision.ds.Color#toWebString", + returned: result, + expected: "#4169E1", + status: TestStatus.of(result == "#4169E1") + } + } catch (e) { + return { + testName: "vision.ds.Color#toWebString", + returned: e, + expected: "#4169E1", + status: Failure + } + } + } + + public static function vision_ds_Color__darken_Float_Color__ShouldWork():TestResult { + try { + var value = Color.WHITE; + + var Factor = 0.5; + + var object = new vision.ds.Color(value); + var result = object.darken(Factor); + + return { + testName: "vision.ds.Color#darken", + returned: result, + expected: 0xFF7F7F7F, + status: TestStatus.of(result == 0xFF7F7F7F) + } + } catch (e) { + return { + testName: "vision.ds.Color#darken", + returned: e, + expected: 0xFF7F7F7F, + status: Failure + } + } + } + + public static function vision_ds_Color__lighten_Float_Color__ShouldWork():TestResult { + try { + var value = Color.BLACK; + + var Factor = 0.5; + + var object = new vision.ds.Color(value); + var result = object.lighten(Factor); + + return { + testName: "vision.ds.Color#lighten", + returned: result, + expected: 0xFF7F7F7F, + status: TestStatus.of(result == 0xFF7F7F7F) + } + } catch (e) { + return { + testName: "vision.ds.Color#lighten", + returned: e, + expected: 0xFF7F7F7F, + status: Failure + } + } + } + + public static function vision_ds_Color__invert__Color__ShouldWork():TestResult { + try { + var value = Color.AMETHYST; + + + var object = new vision.ds.Color(value); + var result = object.invert(); + return { + testName: "vision.ds.Color#invert", + returned: result, + expected: 0xFF669933, + status: TestStatus.of(result == 0xFF669933) + } + } catch (e) { + return { + testName: "vision.ds.Color#invert", + returned: e, + expected: 0xFF669933, + status: Failure + } + } + } + + public static function vision_ds_Color__setRGBA_Int_Int_Int_Int_Color__ShouldWork():TestResult { + try { + var value = 0; + + var Red = 10; + var Green = 20; + var Blue = 30; + var Alpha = 40; + + var object = new vision.ds.Color(value); + var result = object.setRGBA(Red, Green, Blue, Alpha); + + return { + testName: "vision.ds.Color#setRGBA", + returned: result, + expected: 0x281E140A, + status: TestStatus.of(result == 0x281E140A) + } + } catch (e) { + return { + testName: "vision.ds.Color#setRGBA", + returned: e, + expected: 0x281E140A, + status: Failure + } + } + } + + public static function vision_ds_Color__setRGBAFloat_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var value = 0; + + var Red = 0.5; + var Green = 0.5; + var Blue = 0.5; + var Alpha = 0.5; + + var object = new vision.ds.Color(value); + var result = object.setRGBAFloat(Red, Green, Blue, Alpha); + + return { + testName: "vision.ds.Color#setRGBAFloat", + returned: result, + expected: 0x7F7F7F7F, + status: TestStatus.of(result == 0x7F7F7F7F) + } + } catch (e) { + return { + testName: "vision.ds.Color#setRGBAFloat", + returned: e, + expected: 0x7F7F7F7F, + status: Failure + } + } + } + + public static function vision_ds_Color__setCMYK_Float_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var value = 0; + + var Cyan = 0.0; + var Magenta = 0.0; + var Yellow = 0.0; + var Black = 0.0; + var Alpha = 0.0; + + var object = new vision.ds.Color(value); + var result = object.setCMYK(Cyan, Magenta, Yellow, Black, Alpha); + + return { + testName: "vision.ds.Color#setCMYK", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color#setCMYK", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__setHSB_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var value = 0; + + var Hue = 0.0; + var Saturation = 0.0; + var Brightness = 0.0; + var Alpha = 0.0; + + var object = new vision.ds.Color(value); + var result = object.setHSB(Hue, Saturation, Brightness, Alpha); + + return { + testName: "vision.ds.Color#setHSB", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color#setHSB", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__setHSL_Float_Float_Float_Float_Color__ShouldWork():TestResult { + try { + var value = 0; + + var Hue = 0.0; + var Saturation = 0.0; + var Lightness = 0.0; + var Alpha = 0.0; + + var object = new vision.ds.Color(value); + var result = object.setHSL(Hue, Saturation, Lightness, Alpha); + + return { + testName: "vision.ds.Color#setHSL", + returned: result, + expected: null, + status: Skipped + } + } catch (e) { + return { + testName: "vision.ds.Color#setHSL", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Color__grayscale_Bool_Color__ShouldWork():TestResult { + try { + var object = Color.ALABASTER; + + var resultRegular = object.grayscale(false); + var resultSimple = object.grayscale(true); + + return { + testName: "vision.ds.Color#grayscale", + returned: '${resultRegular.toHexString()}, Then: ${resultSimple.toHexString()}', + expected: '${Color.from8Bit(Std.int(0.2126 * object.red + 0.7152 * object.green + 0.0722 * object.blue)).toHexString()}, Then: ${Color.from8Bit(Std.int((object.red + object.green + object.blue) / 3)).toHexString()}', + status: TestStatus.multiple( + TestStatus.of(resultRegular.red == Std.int(0.2126 * object.red + 0.7152 * object.green + 0.0722 * object.blue)), + TestStatus.of(resultSimple.red == Std.int((object.red + object.green + object.blue) / 3)) + ) + } + } catch (e) { + var object = Color.ALABASTER; + return { + testName: "vision.ds.Color#grayscale", + returned: e, + expected: '${Color.from8Bit(Std.int(0.2126 * object.red + 0.7152 * object.green + 0.0722 * object.blue)).toHexString()}, Then: ${Color.from8Bit(Std.int((object.red + object.green + object.blue) / 3)).toHexString()}', + status: Failure + } + } + } + + public static function vision_ds_Color__blackOrWhite_Int_Color__ShouldWork():TestResult { + try { + var value = 0xFF45E312; + + var threshold = 0; + + var object = new vision.ds.Color(value); + var result = object.blackOrWhite(threshold); + + return { + testName: "vision.ds.Color#blackOrWhite", + returned: result, + expected: 0xFFFFFFFF, + status: TestStatus.of(result == 0xFFFFFFFF) + } + } catch (e) { + return { + testName: "vision.ds.Color#blackOrWhite", + returned: e, + expected: 0xFFFFFFFF, + status: Failure + } + } + } + + public static function vision_ds_Color__toString__ShouldWork():TestResult { + try { + var value = Color.AZURE; + + + var object = new vision.ds.Color(value); + object.toString(); + + return { + testName: "vision.ds.Color#toString", + returned: #if console.hx ' ' #else object.toHexString(true, true) #end, + expected: #if console.hx ' ' #else "0xFF007FFF" #end, + status: TestStatus.of(object.toString() == #if console.hx ' ' #else "0xFF007FFF" #end) + } + } catch (e) { + return { + testName: "vision.ds.Color#toString", + returned: e, + expected: #if console.hx ' ' #else "0xFF007FFF" #end, + status: Failure + } + } + } + + public static function vision_ds_Color__toInt__Int__ShouldWork():TestResult { + try { + var value = 0; + + + var object = new vision.ds.Color(value); + var result = object.toInt(); + + return { + testName: "vision.ds.Color#toInt", + returned: result, + expected: 0, + status: TestStatus.of(result == 0) + } + } catch (e) { + return { + testName: "vision.ds.Color#toInt", + returned: e, + expected: 0, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/CramerTests.hx b/tests/generated/src/tests/CramerTests.hx new file mode 100644 index 00000000..6923e95f --- /dev/null +++ b/tests/generated/src/tests/CramerTests.hx @@ -0,0 +1,37 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.Cramer; +import vision.exceptions.InvalidCramerSetup; +import vision.exceptions.InvalidCramerCoefficientsMatrix; +import vision.ds.Matrix2D; + +@:access(vision.algorithms.Cramer) +class CramerTests { + public static function vision_algorithms_Cramer__solveVariablesFor_Matrix2D_ArrayFloat_ArrayFloat__ShouldWork():TestResult { + try { + var coefficients:Matrix2D = null; + var solutions = []; + + var result = vision.algorithms.Cramer.solveVariablesFor(coefficients, solutions); + + return { + testName: "vision.algorithms.Cramer.solveVariablesFor", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Cramer.solveVariablesFor", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/FormatImageExporterTests.hx b/tests/generated/src/tests/FormatImageExporterTests.hx new file mode 100644 index 00000000..d9e9cf28 --- /dev/null +++ b/tests/generated/src/tests/FormatImageExporterTests.hx @@ -0,0 +1,89 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.formats.__internal.FormatImageExporter; +import vision.ds.PixelFormat; +import vision.ds.ByteArray; +import haxe.io.BytesOutput; +import vision.ds.Image; +import vision.ds.ImageFormat; +import vision.exceptions.ImageSavingFailed; +import format.png.Writer; +import format.png.Tools; +import format.bmp.Writer; +import format.bmp.Tools; +import format.jpg.Writer; +import format.jpg.Data; + +@:access(vision.formats.__internal.FormatImageExporter) +class FormatImageExporterTests { + public static function vision_formats___internal_FormatImageExporter__png_Image_ByteArray__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.formats.__internal.FormatImageExporter.png(image); + + return { + testName: "vision.formats.__internal.FormatImageExporter.png", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.formats.__internal.FormatImageExporter.png", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_formats___internal_FormatImageExporter__bmp_Image_ByteArray__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.formats.__internal.FormatImageExporter.bmp(image); + + return { + testName: "vision.formats.__internal.FormatImageExporter.bmp", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.formats.__internal.FormatImageExporter.bmp", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_formats___internal_FormatImageExporter__jpeg_Image_ByteArray__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.formats.__internal.FormatImageExporter.jpeg(image); + + return { + testName: "vision.formats.__internal.FormatImageExporter.jpeg", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.formats.__internal.FormatImageExporter.jpeg", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/FormatImageLoaderTests.hx b/tests/generated/src/tests/FormatImageLoaderTests.hx new file mode 100644 index 00000000..6239dee5 --- /dev/null +++ b/tests/generated/src/tests/FormatImageLoaderTests.hx @@ -0,0 +1,63 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.formats.__internal.FormatImageLoader; +import haxe.io.BytesInput; +import vision.ds.Image; +import vision.exceptions.ImageLoadingFailed; +import vision.ds.ByteArray; +import format.png.Reader; +import format.png.Tools; +import format.bmp.Reader; +import format.bmp.Tools; + +@:access(vision.formats.__internal.FormatImageLoader) +class FormatImageLoaderTests { + public static function vision_formats___internal_FormatImageLoader__png_ByteArray_Image__ShouldWork():TestResult { + try { + var bytes = vision.ds.ByteArray.from(0); + + var result = vision.formats.__internal.FormatImageLoader.png(bytes); + + return { + testName: "vision.formats.__internal.FormatImageLoader.png", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.formats.__internal.FormatImageLoader.png", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_formats___internal_FormatImageLoader__bmp_ByteArray_Image__ShouldWork():TestResult { + try { + var bytes = vision.ds.ByteArray.from(0); + + var result = vision.formats.__internal.FormatImageLoader.bmp(bytes); + + return { + testName: "vision.formats.__internal.FormatImageLoader.bmp", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.formats.__internal.FormatImageLoader.bmp", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/GaussJordanTests.hx b/tests/generated/src/tests/GaussJordanTests.hx new file mode 100644 index 00000000..b003d074 --- /dev/null +++ b/tests/generated/src/tests/GaussJordanTests.hx @@ -0,0 +1,34 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.GaussJordan; +import vision.ds.Matrix2D; + +@:access(vision.algorithms.GaussJordan) +class GaussJordanTests { + public static function vision_algorithms_GaussJordan__invert_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var matrix:Matrix2D = null; + + var result = vision.algorithms.GaussJordan.invert(matrix); + + return { + testName: "vision.algorithms.GaussJordan.invert", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.GaussJordan.invert", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/GaussTests.hx b/tests/generated/src/tests/GaussTests.hx new file mode 100644 index 00000000..c1e7ef98 --- /dev/null +++ b/tests/generated/src/tests/GaussTests.hx @@ -0,0 +1,218 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.Gauss; +import vision.ds.Color; +import vision.ds.Image; +import vision.ds.Array2D; +import vision.exceptions.InvalidGaussianKernelSize; + +@:access(vision.algorithms.Gauss) +class GaussTests { + public static function vision_algorithms_Gauss__create1x1Kernel_Float_ArrayArrayFloat__ShouldWork():TestResult { + try { + var sigma = 0.0; + + var result = vision.algorithms.Gauss.create1x1Kernel(sigma); + + return { + testName: "vision.algorithms.Gauss.create1x1Kernel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.create1x1Kernel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__create3x3Kernel_Float_ArrayArrayFloat__ShouldWork():TestResult { + try { + var sigma = 0.0; + + var result = vision.algorithms.Gauss.create3x3Kernel(sigma); + + return { + testName: "vision.algorithms.Gauss.create3x3Kernel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.create3x3Kernel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__create5x5Kernel_Float_ArrayArrayFloat__ShouldWork():TestResult { + try { + var sigma = 0.0; + + var result = vision.algorithms.Gauss.create5x5Kernel(sigma); + + return { + testName: "vision.algorithms.Gauss.create5x5Kernel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.create5x5Kernel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__create7x7Kernel_Float_ArrayArrayFloat__ShouldWork():TestResult { + try { + var sigma = 0.0; + + var result = vision.algorithms.Gauss.create7x7Kernel(sigma); + + return { + testName: "vision.algorithms.Gauss.create7x7Kernel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.create7x7Kernel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__create9x9Kernel_Float_ArrayArrayFloat__ShouldWork():TestResult { + try { + var sigma = 0.0; + + var result = vision.algorithms.Gauss.create9x9Kernel(sigma); + + return { + testName: "vision.algorithms.Gauss.create9x9Kernel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.create9x9Kernel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__createKernelOfSize_Int_Int_Array2DFloat__ShouldWork():TestResult { + try { + var size = 0; + var sigma = 0; + + var result = vision.algorithms.Gauss.createKernelOfSize(size, sigma); + + return { + testName: "vision.algorithms.Gauss.createKernelOfSize", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.createKernelOfSize", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__create2DKernelOfSize_Int_Float_Array2DFloat__ShouldWork():TestResult { + try { + var size = 0; + var sigma = 0.0; + + var result = vision.algorithms.Gauss.create2DKernelOfSize(size, sigma); + + return { + testName: "vision.algorithms.Gauss.create2DKernelOfSize", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.create2DKernelOfSize", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__create1DKernelOfSize_Int_Float_ArrayFloat__ShouldWork():TestResult { + try { + var size = 0; + var sigma = 0.0; + + var result = vision.algorithms.Gauss.create1DKernelOfSize(size, sigma); + + return { + testName: "vision.algorithms.Gauss.create1DKernelOfSize", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.create1DKernelOfSize", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Gauss__fastBlur_Image_Int_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var size = 0; + var sigma = 0.0; + + var result = vision.algorithms.Gauss.fastBlur(image, size, sigma); + + return { + testName: "vision.algorithms.Gauss.fastBlur", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Gauss.fastBlur", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/HistogramTests.hx b/tests/generated/src/tests/HistogramTests.hx new file mode 100644 index 00000000..e9657798 --- /dev/null +++ b/tests/generated/src/tests/HistogramTests.hx @@ -0,0 +1,104 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Histogram; +import haxe.ds.IntMap; + +@:access(vision.ds.Histogram) +class HistogramTests { + public static function vision_ds_Histogram__length__ShouldWork():TestResult { + try { + + var object = new vision.ds.Histogram(); + var result = object.length; + + return { + testName: "vision.ds.Histogram#length", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Histogram#length", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Histogram__median__ShouldWork():TestResult { + try { + + var object = new vision.ds.Histogram(); + var result = object.median; + + return { + testName: "vision.ds.Histogram#median", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Histogram#median", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Histogram__increment_Int_Histogram__ShouldWork():TestResult { + try { + + var cell = 0; + + var object = new vision.ds.Histogram(); + var result = object.increment(cell); + + return { + testName: "vision.ds.Histogram#increment", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Histogram#increment", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Histogram__decrement_Int_Histogram__ShouldWork():TestResult { + try { + + var cell = 0; + + var object = new vision.ds.Histogram(); + var result = object.decrement(cell); + + return { + testName: "vision.ds.Histogram#decrement", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Histogram#decrement", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/ImageHashingTests.hx b/tests/generated/src/tests/ImageHashingTests.hx new file mode 100644 index 00000000..dd7a0f54 --- /dev/null +++ b/tests/generated/src/tests/ImageHashingTests.hx @@ -0,0 +1,60 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.ImageHashing; +import haxe.Int64; +import vision.ds.Matrix2D; +import vision.ds.ByteArray; +import vision.ds.Image; + +@:access(vision.algorithms.ImageHashing) +class ImageHashingTests { + public static function vision_algorithms_ImageHashing__ahash_Image_Int_ByteArray__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var hashByteSize = 0; + + var result = vision.algorithms.ImageHashing.ahash(image, hashByteSize); + + return { + testName: "vision.algorithms.ImageHashing.ahash", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.ImageHashing.ahash", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_ImageHashing__phash_Image_ByteArray__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.algorithms.ImageHashing.phash(image); + + return { + testName: "vision.algorithms.ImageHashing.phash", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.ImageHashing.phash", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/ImageTests.hx b/tests/generated/src/tests/ImageTests.hx new file mode 100644 index 00000000..2839e19c --- /dev/null +++ b/tests/generated/src/tests/ImageTests.hx @@ -0,0 +1,1578 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Image; +import vision.formats.ImageIO; +import vision.ds.ByteArray; +import vision.exceptions.Unimplemented; +import vision.algorithms.BilinearInterpolation; +import haxe.ds.List; +import haxe.Int64; +import vision.ds.Color; +import vision.ds.Rectangle; +import vision.ds.ImageView; +import vision.ds.ImageResizeAlgorithm; +import vision.exceptions.OutOfBounds; +import vision.tools.ImageTools; + +@:access(vision.ds.Image) +class ImageTests { + public static function vision_ds_Image__view__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + var result = object.view; + + return { + testName: "vision.ds.Image#view", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#view", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__from2DArray_Array_Image__ShouldWork():TestResult { + try { + var array = []; + + var result = vision.ds.Image.from2DArray(array); + + return { + testName: "vision.ds.Image.from2DArray", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image.from2DArray", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__getSafePixel_Int_Int_Color__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + + var object = new vision.ds.Image(width, height, color); + var result = object.getSafePixel(x, y); + + return { + testName: "vision.ds.Image#getSafePixel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#getSafePixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__getFloatingPixel_Float_Float_Color__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0.0; + var y = 0.0; + + var object = new vision.ds.Image(width, height, color); + var result = object.getFloatingPixel(x, y); + + return { + testName: "vision.ds.Image#getFloatingPixel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#getFloatingPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__setPixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.setPixel(x, y, color); + + return { + testName: "vision.ds.Image#setPixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#setPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__setSafePixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.setSafePixel(x, y, color); + + return { + testName: "vision.ds.Image#setSafePixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#setSafePixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__setFloatingPixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0.0; + var y = 0.0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.setFloatingPixel(x, y, color); + + return { + testName: "vision.ds.Image#setFloatingPixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#setFloatingPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__paintPixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.paintPixel(x, y, color); + + return { + testName: "vision.ds.Image#paintPixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#paintPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__paintFloatingPixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0.0; + var y = 0.0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.paintFloatingPixel(x, y, color); + + return { + testName: "vision.ds.Image#paintFloatingPixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#paintFloatingPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__paintSafePixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + var color = 0; + + var object = new vision.ds.Image(width, height, color); + object.paintSafePixel(x, y, color); + + return { + testName: "vision.ds.Image#paintSafePixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#paintSafePixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__hasPixel_Float_Float_Bool__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0.0; + var y = 0.0; + + var object = new vision.ds.Image(width, height, color); + var result = object.hasPixel(x, y); + + return { + testName: "vision.ds.Image#hasPixel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#hasPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__movePixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var fromX = 0; + var fromY = 0; + var toX = 0; + var toY = 0; + var oldPixelResetColor:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.movePixel(fromX, fromY, toX, toY, oldPixelResetColor); + + return { + testName: "vision.ds.Image#movePixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#movePixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__moveSafePixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var fromX = 0; + var fromY = 0; + var toX = 0; + var toY = 0; + var oldPixelResetColor:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.moveSafePixel(fromX, fromY, toX, toY, oldPixelResetColor); + + return { + testName: "vision.ds.Image#moveSafePixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#moveSafePixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__moveFloatingPixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var fromX = 0.0; + var fromY = 0.0; + var toX = 0.0; + var toY = 0.0; + var oldPixelResetColor:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.moveFloatingPixel(fromX, fromY, toX, toY, oldPixelResetColor); + + return { + testName: "vision.ds.Image#moveFloatingPixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#moveFloatingPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__moveUnsafePixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var fromX = 0; + var fromY = 0; + var toX = 0; + var toY = 0; + var oldPixelResetColor:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.moveUnsafePixel(fromX, fromY, toX, toY, oldPixelResetColor); + + return { + testName: "vision.ds.Image#moveUnsafePixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#moveUnsafePixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__copyPixelFrom_Image_Int_Int_Color__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var image = new vision.ds.Image(100, 100); + var x = 0; + var y = 0; + + var object = new vision.ds.Image(width, height, color); + var result = object.copyPixelFrom(image, x, y); + + return { + testName: "vision.ds.Image#copyPixelFrom", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#copyPixelFrom", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__copyPixelTo_Image_Int_Int_Color__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var image = new vision.ds.Image(100, 100); + var x = 0; + var y = 0; + + var object = new vision.ds.Image(width, height, color); + var result = object.copyPixelTo(image, x, y); + + return { + testName: "vision.ds.Image#copyPixelTo", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#copyPixelTo", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__copyImageFrom_Image_Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var image = new vision.ds.Image(100, 100); + + var object = new vision.ds.Image(width, height, color); + var result = object.copyImageFrom(image); + + return { + testName: "vision.ds.Image#copyImageFrom", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#copyImageFrom", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__getImagePortion_Rectangle_Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var rect:Rectangle = null; + + var object = new vision.ds.Image(width, height, color); + var result = object.getImagePortion(rect); + + return { + testName: "vision.ds.Image#getImagePortion", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#getImagePortion", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__setImagePortion__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var rect:Rectangle = null; + var image = new vision.ds.Image(100, 100); + + var object = new vision.ds.Image(width, height, color); + object.setImagePortion(rect, image); + + return { + testName: "vision.ds.Image#setImagePortion", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#setImagePortion", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawLine__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x1 = 0; + var y1 = 0; + var x2 = 0; + var y2 = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.drawLine(x1, y1, x2, y2, color); + + return { + testName: "vision.ds.Image#drawLine", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawLine", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawRay2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var line = new vision.ds.Ray2D({x: 0, y: 0}, 1); + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.drawRay2D(line, color); + + return { + testName: "vision.ds.Image#drawRay2D", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawRay2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawLine2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.drawLine2D(line, color); + + return { + testName: "vision.ds.Image#drawLine2D", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawLine2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__fillRect__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + var width = 0; + var height = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.fillRect(x, y, width, height, color); + + return { + testName: "vision.ds.Image#fillRect", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#fillRect", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawRect__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + var width = 0; + var height = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.drawRect(x, y, width, height, color); + + return { + testName: "vision.ds.Image#drawRect", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawRect", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawQuadraticBezier__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var control = new vision.ds.IntPoint2D(0, 0); + var color:Color = null; + var accuracy = 0.0; + + var object = new vision.ds.Image(width, height, color); + object.drawQuadraticBezier(line, control, color, accuracy); + + return { + testName: "vision.ds.Image#drawQuadraticBezier", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawQuadraticBezier", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawCubicBezier__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var control1 = new vision.ds.IntPoint2D(0, 0); + var control2 = new vision.ds.IntPoint2D(0, 0); + var color:Color = null; + var accuracy = 0.0; + + var object = new vision.ds.Image(width, height, color); + object.drawCubicBezier(line, control1, control2, color, accuracy); + + return { + testName: "vision.ds.Image#drawCubicBezier", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawCubicBezier", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__fillCircle__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var X = 0; + var Y = 0; + var r = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.fillCircle(X, Y, r, color); + + return { + testName: "vision.ds.Image#fillCircle", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#fillCircle", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawCircle__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var X = 0; + var Y = 0; + var r = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.drawCircle(X, Y, r, color); + + return { + testName: "vision.ds.Image#drawCircle", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawCircle", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__fillEllipse__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var centerX = 0; + var centerY = 0; + var radiusX = 0; + var radiusY = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.fillEllipse(centerX, centerY, radiusX, radiusY, color); + + return { + testName: "vision.ds.Image#fillEllipse", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#fillEllipse", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__drawEllipse__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var centerX = 0; + var centerY = 0; + var radiusX = 0; + var radiusY = 0; + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.drawEllipse(centerX, centerY, radiusX, radiusY, color); + + return { + testName: "vision.ds.Image#drawEllipse", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#drawEllipse", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__fillColorRecursive__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var position = new vision.ds.IntPoint2D(0, 0); + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.fillColorRecursive(position, color); + + return { + testName: "vision.ds.Image#fillColorRecursive", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#fillColorRecursive", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__fillColor__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var position = new vision.ds.IntPoint2D(0, 0); + var color:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.fillColor(position, color); + + return { + testName: "vision.ds.Image#fillColor", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#fillColor", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__fillUntilColor__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var position = new vision.ds.IntPoint2D(0, 0); + var color:Color = null; + var borderColor:Color = null; + + var object = new vision.ds.Image(width, height, color); + object.fillUntilColor(position, color, borderColor); + + return { + testName: "vision.ds.Image#fillUntilColor", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#fillUntilColor", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__clone__Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.clone(); + + return { + testName: "vision.ds.Image#clone", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#clone", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__mirror__Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.mirror(); + + return { + testName: "vision.ds.Image#mirror", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#mirror", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__flip__Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.flip(); + + return { + testName: "vision.ds.Image#flip", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#flip", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__stamp_Int_Int_Image_Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var X = 0; + var Y = 0; + var image = new vision.ds.Image(100, 100); + + var object = new vision.ds.Image(width, height, color); + var result = object.stamp(X, Y, image); + + return { + testName: "vision.ds.Image#stamp", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#stamp", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__resize_Int_Int_ImageResizeAlgorithm_Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var newWidth = 0; + var newHeight = 0; + var algorithm:ImageResizeAlgorithm = null; + + var object = new vision.ds.Image(width, height, color); + var result = object.resize(newWidth, newHeight, algorithm); + + return { + testName: "vision.ds.Image#resize", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#resize", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__rotate_Float_Bool_Bool_Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var angle = 0.0; + var degrees = false; + var expandImageBounds = false; + + var object = new vision.ds.Image(width, height, color); + var result = object.rotate(angle, degrees, expandImageBounds); + + return { + testName: "vision.ds.Image#rotate", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#rotate", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__toString_Bool_String__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var special = false; + + var object = new vision.ds.Image(width, height, color); + var result = object.toString(special); + + return { + testName: "vision.ds.Image#toString", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#toString", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__forEachPixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var callback = (_, _, _) -> null; + + var object = new vision.ds.Image(width, height, color); + object.forEachPixel(callback); + + return { + testName: "vision.ds.Image#forEachPixel", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#forEachPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__forEachPixelInView__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var callback = (_, _, _) -> null; + + var object = new vision.ds.Image(width, height, color); + object.forEachPixelInView(callback); + + return { + testName: "vision.ds.Image#forEachPixelInView", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#forEachPixelInView", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__iterator__IteratorPixel__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.iterator(); + + return { + testName: "vision.ds.Image#iterator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#iterator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__center__Point2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.center(); + + return { + testName: "vision.ds.Image#center", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#center", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__pixelToRelative_Point2D_Point2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var point = new vision.ds.Point2D(0, 0); + + var object = new vision.ds.Image(width, height, color); + var result = object.pixelToRelative(point); + + return { + testName: "vision.ds.Image#pixelToRelative", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#pixelToRelative", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__pixelToRelative_Float_Float_Point2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0.0; + var y = 0.0; + + var object = new vision.ds.Image(width, height, color); + var result = object.pixelToRelative(x, y); + + return { + testName: "vision.ds.Image#pixelToRelative", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#pixelToRelative", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__relativeToPixel_Point2D_Point2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var point = new vision.ds.Point2D(0, 0); + + var object = new vision.ds.Image(width, height, color); + var result = object.relativeToPixel(point); + + return { + testName: "vision.ds.Image#relativeToPixel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#relativeToPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__relativeToPixel_Float_Float_Point2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0.0; + var y = 0.0; + + var object = new vision.ds.Image(width, height, color); + var result = object.relativeToPixel(x, y); + + return { + testName: "vision.ds.Image#relativeToPixel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#relativeToPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__hasView__Bool__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.hasView(); + + return { + testName: "vision.ds.Image#hasView", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#hasView", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__setView_ImageView_Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var view:ImageView = null; + + var object = new vision.ds.Image(width, height, color); + var result = object.setView(view); + + return { + testName: "vision.ds.Image#setView", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#setView", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__getView__ImageView__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.getView(); + + return { + testName: "vision.ds.Image#getView", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#getView", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__removeView__Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + + var object = new vision.ds.Image(width, height, color); + var result = object.removeView(); + + return { + testName: "vision.ds.Image#removeView", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#removeView", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__copyViewFrom_Image_Image__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var from = new vision.ds.Image(100, 100); + + var object = new vision.ds.Image(width, height, color); + var result = object.copyViewFrom(from); + + return { + testName: "vision.ds.Image#copyViewFrom", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#copyViewFrom", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Image__hasPixelInView_Int_Int_ImageView_Bool__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + var color:Color = null; + + var x = 0; + var y = 0; + var v:ImageView = null; + + var object = new vision.ds.Image(width, height, color); + var result = object.hasPixelInView(x, y, v); + + return { + testName: "vision.ds.Image#hasPixelInView", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Image#hasPixelInView", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/ImageToolsTests.hx b/tests/generated/src/tests/ImageToolsTests.hx new file mode 100644 index 00000000..105db84e --- /dev/null +++ b/tests/generated/src/tests/ImageToolsTests.hx @@ -0,0 +1,267 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.tools.ImageTools; +import haxe.Http; +import vision.formats.ImageIO; +import haxe.io.Path; +import haxe.crypto.Base64; +import haxe.io.BytesOutput; +import vision.ds.ByteArray; +import vision.exceptions.ImageLoadingFailed; +import vision.exceptions.ImageSavingFailed; +import vision.exceptions.LibraryRequired; +import vision.ds.ImageFormat; +import vision.ds.Array2D; +import vision.exceptions.Unimplemented; +import vision.exceptions.WebResponseError; +import vision.ds.ImageResizeAlgorithm; +import haxe.ds.Vector; +import vision.ds.IntPoint2D; +import vision.ds.Point2D; +import vision.ds.Color; +import vision.ds.Image; + +@:access(vision.tools.ImageTools) +class ImageToolsTests { + public static function vision_tools_ImageTools__loadFromFile__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var path = ""; + var onComplete = (_) -> null; + + vision.tools.ImageTools.loadFromFile(image, path, onComplete); + + return { + testName: "vision.tools.ImageTools.loadFromFile", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.loadFromFile", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__saveToFile__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var pathWithFileName = ""; + var saveFormat:ImageFormat = null; + + vision.tools.ImageTools.saveToFile(image, pathWithFileName, saveFormat); + + return { + testName: "vision.tools.ImageTools.saveToFile", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.saveToFile", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__loadFromBytes_Image_ByteArray_ImageFormat_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var bytes = vision.ds.ByteArray.from(0); + var fileFormat:ImageFormat = null; + + var result = vision.tools.ImageTools.loadFromBytes(image, bytes, fileFormat); + + return { + testName: "vision.tools.ImageTools.loadFromBytes", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.loadFromBytes", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__loadFromFile_Image_String_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var path = ""; + + var result = vision.tools.ImageTools.loadFromFile(image, path); + + return { + testName: "vision.tools.ImageTools.loadFromFile", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.loadFromFile", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__loadFromURL_Image_String_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var url = ""; + + var result = vision.tools.ImageTools.loadFromURL(image, url); + + return { + testName: "vision.tools.ImageTools.loadFromURL", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.loadFromURL", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__exportToBytes_Image_ImageFormat_ByteArray__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var format:ImageFormat = null; + + var result = vision.tools.ImageTools.exportToBytes(image, format); + + return { + testName: "vision.tools.ImageTools.exportToBytes", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.exportToBytes", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__exportToFile__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var pathWithFileName = ""; + var format:ImageFormat = null; + + vision.tools.ImageTools.exportToFile(image, pathWithFileName, format); + + return { + testName: "vision.tools.ImageTools.exportToFile", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.exportToFile", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__addToScreen_Image_Int_Int_xUnitsStringyUnitsStringzIndexString_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var x = 0; + var y = 0; + var units:{?xUnits:String, ?yUnits:String, ?zIndex:String} = null; + + var result = vision.tools.ImageTools.addToScreen(image, x, y, units); + + return { + testName: "vision.tools.ImageTools.addToScreen", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.addToScreen", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__getNeighborsOfPixel_Image_Int_Int_Int_Array2DColor__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var x = 0; + var y = 0; + var kernelSize = 0; + + var result = vision.tools.ImageTools.getNeighborsOfPixel(image, x, y, kernelSize); + + return { + testName: "vision.tools.ImageTools.getNeighborsOfPixel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.getNeighborsOfPixel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_ImageTools__grayscalePixel_Color_Color__ShouldWork():TestResult { + try { + var pixel:Color = null; + + var result = vision.tools.ImageTools.grayscalePixel(pixel); + + return { + testName: "vision.tools.ImageTools.grayscalePixel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.ImageTools.grayscalePixel", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/ImageViewTests.hx b/tests/generated/src/tests/ImageViewTests.hx new file mode 100644 index 00000000..ad5ce948 --- /dev/null +++ b/tests/generated/src/tests/ImageViewTests.hx @@ -0,0 +1,35 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.ImageView; +import vision.ds.ImageViewShape; + +@:access(vision.ds.ImageView) +class ImageViewTests { + public static function vision_ds_ImageView__toString__String__ShouldWork():TestResult { + try { + + + var object = ({} : ImageView); + var result = object.toString(); + + return { + testName: "vision.ds.ImageView#toString", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.ImageView#toString", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/Int16Point2DTests.hx b/tests/generated/src/tests/Int16Point2DTests.hx new file mode 100644 index 00000000..efc3511a --- /dev/null +++ b/tests/generated/src/tests/Int16Point2DTests.hx @@ -0,0 +1,160 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Int16Point2D; +import vision.tools.MathTools; + +@:access(vision.ds.Int16Point2D) +class Int16Point2DTests { + public static function vision_ds_Int16Point2D__x__ShouldWork():TestResult { + try { + var X = 0; + var Y = 0; + + var object = new vision.ds.Int16Point2D(X, Y); + var result = object.x; + + return { + testName: "vision.ds.Int16Point2D#x", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Int16Point2D#x", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Int16Point2D__y__ShouldWork():TestResult { + try { + var X = 0; + var Y = 0; + + var object = new vision.ds.Int16Point2D(X, Y); + var result = object.y; + + return { + testName: "vision.ds.Int16Point2D#y", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Int16Point2D#y", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Int16Point2D__toString__String__ShouldWork():TestResult { + try { + var X = 0; + var Y = 0; + + + var object = new vision.ds.Int16Point2D(X, Y); + var result = object.toString(); + + return { + testName: "vision.ds.Int16Point2D#toString", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Int16Point2D#toString", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Int16Point2D__toPoint2D__Point2D__ShouldWork():TestResult { + try { + var X = 0; + var Y = 0; + + + var object = new vision.ds.Int16Point2D(X, Y); + var result = object.toPoint2D(); + + return { + testName: "vision.ds.Int16Point2D#toPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Int16Point2D#toPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Int16Point2D__toIntPoint2D__Point2D__ShouldWork():TestResult { + try { + var X = 0; + var Y = 0; + + + var object = new vision.ds.Int16Point2D(X, Y); + var result = object.toIntPoint2D(); + + return { + testName: "vision.ds.Int16Point2D#toIntPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Int16Point2D#toIntPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Int16Point2D__toInt__Int__ShouldWork():TestResult { + try { + var X = 0; + var Y = 0; + + + var object = new vision.ds.Int16Point2D(X, Y); + var result = object.toInt(); + + return { + testName: "vision.ds.Int16Point2D#toInt", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Int16Point2D#toInt", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/IntPoint2DTests.hx b/tests/generated/src/tests/IntPoint2DTests.hx new file mode 100644 index 00000000..95d5f2b0 --- /dev/null +++ b/tests/generated/src/tests/IntPoint2DTests.hx @@ -0,0 +1,237 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.IntPoint2D; +import vision.tools.MathTools; +import vision.ds.Point2D; +import haxe.Int64; + +@:access(vision.ds.IntPoint2D) +class IntPoint2DTests { + public static function vision_ds_IntPoint2D__x__ShouldWork():TestResult { + try { + var x = 15; + var y = 12; + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.x; + + return { + testName: "vision.ds.IntPoint2D#x", + returned: result, + expected: 15, + status: TestStatus.of(result == 15) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#x", + returned: e, + expected: 15, + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__y__ShouldWork():TestResult { + try { + var x = 0; + var y = 1000; + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.y; + + return { + testName: "vision.ds.IntPoint2D#y", + returned: result, + expected: 1000, + status: TestStatus.of(result == 1000) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#y", + returned: e, + expected: 1000, + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__fromPoint2D_Point2D_IntPoint2D__ShouldWork():TestResult { + try { + var p = new vision.ds.Point2D(0, 0); + + var result = vision.ds.IntPoint2D.fromPoint2D(p); + + return { + testName: "vision.ds.IntPoint2D.fromPoint2D", + returned: result, + expected: new IntPoint2D(0, 0), + status: TestStatus.of([result.x, result.y], [0, 0]) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D.fromPoint2D", + returned: e, + expected: new IntPoint2D(0, 0), + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__toPoint2D__Point2D__ShouldWork():TestResult { + try { + var x = 0; + var y = 0; + + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.toPoint2D(); + + return { + testName: "vision.ds.IntPoint2D#toPoint2D", + returned: result, + expected: new Point2D(0, 0), + status: TestStatus.of([result.x, result.y], [0, 0]) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#toPoint2D", + returned: e, + expected: new Point2D(0, 0), + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__toString__String__ShouldWork():TestResult { + try { + var x = 4; + var y = 5; + + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.toString(); + + return { + testName: "vision.ds.IntPoint2D#toString", + returned: result, + expected: "(4, 5)", + status: TestStatus.of(result == "(4, 5)") + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#toString", + returned: e, + expected: "(4, 5)", + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__copy__IntPoint2D__ShouldWork():TestResult { + try { + var x = 505; + var y = 17; + + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.copy(); + + return { + testName: "vision.ds.IntPoint2D#copy", + returned: result, + expected: new IntPoint2D(505, 17), + status: TestStatus.of([result.x, result.y], [505, 17]) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#copy", + returned: e, + expected: new IntPoint2D(505, 17), + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__distanceTo_IntPoint2D_Float__ShouldWork():TestResult { + try { + var x = 0; + var y = 0; + + var point = new vision.ds.IntPoint2D(1, 1); + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.distanceTo(point); + + return { + testName: "vision.ds.IntPoint2D#distanceTo", + returned: result, + expected: MathTools.SQRT2, + status: TestStatus.of(result == MathTools.SQRT2) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#distanceTo", + returned: e, + expected: MathTools.SQRT2, + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__degreesTo_Point2D_Float__ShouldWork():TestResult { + try { + var x = 0; + var y = 0; + + var point = new vision.ds.Point2D(1, 2); + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.degreesTo(point); + + return { + testName: "vision.ds.IntPoint2D#degreesTo", + returned: result, + expected: 60, + status: TestStatus.of(result == 60) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#degreesTo", + returned: e, + expected: 60, + status: Failure + } + } + } + + public static function vision_ds_IntPoint2D__radiansTo_Point2D_Float__ShouldWork():TestResult { + try { + var x = 0; + var y = 0; + + var point = new vision.ds.Point2D(1, 2); + + var object = new vision.ds.IntPoint2D(x, y); + var result = object.radiansTo(point); + + return { + testName: "vision.ds.IntPoint2D#radiansTo", + returned: result, + expected: 60 * MathTools.PI / 180, + status: TestStatus.of(result == 60 * MathTools.PI / 180) + } + } catch (e) { + return { + testName: "vision.ds.IntPoint2D#radiansTo", + returned: e, + expected: 60 * MathTools.PI / 180, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/KMeansTests.hx b/tests/generated/src/tests/KMeansTests.hx new file mode 100644 index 00000000..d0aceea2 --- /dev/null +++ b/tests/generated/src/tests/KMeansTests.hx @@ -0,0 +1,87 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.KMeans; +import vision.ds.Color; +import vision.ds.Image; +import vision.ds.kmeans.ColorCluster; +import vision.exceptions.Unimplemented; + +@:access(vision.algorithms.KMeans) +class KMeansTests { + public static function vision_algorithms_KMeans__generateClustersUsingConvergence_ArrayT_Int_TTFloat_ArrayTT_ArrayArrayT__ShouldWork():TestResult { + try { + var values = []; + var clusterAmount = 0; + var distanceFunction = (_, _) -> null; + var averageFunction = (_) -> null; + + var result = vision.algorithms.KMeans.generateClustersUsingConvergence(values, clusterAmount, distanceFunction, averageFunction); + + return { + testName: "vision.algorithms.KMeans.generateClustersUsingConvergence", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.KMeans.generateClustersUsingConvergence", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_KMeans__getImageColorClusters_Image_Int_ArrayColorCluster__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var clusterAmount = 0; + + var result = vision.algorithms.KMeans.getImageColorClusters(image, clusterAmount); + + return { + testName: "vision.algorithms.KMeans.getImageColorClusters", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.KMeans.getImageColorClusters", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_KMeans__pickElementsAtRandom_ArrayT_Int_Bool_ArrayT__ShouldWork():TestResult { + try { + var values = []; + var amount = 0; + var distinct = false; + + var result = vision.algorithms.KMeans.pickElementsAtRandom(values, amount, distinct); + + return { + testName: "vision.algorithms.KMeans.pickElementsAtRandom", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.KMeans.pickElementsAtRandom", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/LaplaceTests.hx b/tests/generated/src/tests/LaplaceTests.hx new file mode 100644 index 00000000..333a990d --- /dev/null +++ b/tests/generated/src/tests/LaplaceTests.hx @@ -0,0 +1,64 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.Laplace; +import vision.ds.gaussian.GaussianKernelSize; +import vision.ds.Color; +import vision.tools.ImageTools; +import vision.ds.Image; + +@:access(vision.algorithms.Laplace) +class LaplaceTests { + public static function vision_algorithms_Laplace__convolveWithLaplacianOperator_Image_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var positive = false; + + var result = vision.algorithms.Laplace.convolveWithLaplacianOperator(image, positive); + + return { + testName: "vision.algorithms.Laplace.convolveWithLaplacianOperator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Laplace.convolveWithLaplacianOperator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Laplace__laplacianOfGaussian_Image_GaussianKernelSize_Float_Float_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var kernelSize:GaussianKernelSize = null; + var sigma = 0.0; + var threshold = 0.0; + var positive = false; + + var result = vision.algorithms.Laplace.laplacianOfGaussian(image, kernelSize, sigma, threshold, positive); + + return { + testName: "vision.algorithms.Laplace.laplacianOfGaussian", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Laplace.laplacianOfGaussian", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/Line2DTests.hx b/tests/generated/src/tests/Line2DTests.hx new file mode 100644 index 00000000..c47a2cbb --- /dev/null +++ b/tests/generated/src/tests/Line2DTests.hx @@ -0,0 +1,184 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Line2D; +import vision.tools.MathTools; + +@:access(vision.ds.Line2D) +class Line2DTests { + public static function vision_ds_Line2D__length__ShouldWork():TestResult { + try { + var start = new vision.ds.Point2D(0, 0); + var end = new vision.ds.Point2D(0, 0); + + var object = new vision.ds.Line2D(start, end); + var result = object.length; + + return { + testName: "vision.ds.Line2D#length", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Line2D#length", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Line2D__middle__ShouldWork():TestResult { + try { + var start = new vision.ds.Point2D(0, 0); + var end = new vision.ds.Point2D(0, 0); + + var object = new vision.ds.Line2D(start, end); + var result = object.middle; + + return { + testName: "vision.ds.Line2D#middle", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Line2D#middle", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Line2D__fromRay2D_Ray2D_Line2D__ShouldWork():TestResult { + try { + var ray = new vision.ds.Ray2D({x: 0, y: 0}, 1); + + var result = vision.ds.Line2D.fromRay2D(ray); + + return { + testName: "vision.ds.Line2D.fromRay2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Line2D.fromRay2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Line2D__intersect_Line2D_Point2D__ShouldWork():TestResult { + try { + var start = new vision.ds.Point2D(0, 0); + var end = new vision.ds.Point2D(0, 0); + + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var object = new vision.ds.Line2D(start, end); + var result = object.intersect(line); + + return { + testName: "vision.ds.Line2D#intersect", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Line2D#intersect", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Line2D__distanceTo_Line2D_Float__ShouldWork():TestResult { + try { + var start = new vision.ds.Point2D(0, 0); + var end = new vision.ds.Point2D(0, 0); + + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var object = new vision.ds.Line2D(start, end); + var result = object.distanceTo(line); + + return { + testName: "vision.ds.Line2D#distanceTo", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Line2D#distanceTo", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Line2D__toString__String__ShouldWork():TestResult { + try { + var start = new vision.ds.Point2D(0, 0); + var end = new vision.ds.Point2D(0, 0); + + + var object = new vision.ds.Line2D(start, end); + var result = object.toString(); + + return { + testName: "vision.ds.Line2D#toString", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Line2D#toString", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Line2D__toRay2D__Ray2D__ShouldWork():TestResult { + try { + var start = new vision.ds.Point2D(0, 0); + var end = new vision.ds.Point2D(0, 0); + + + var object = new vision.ds.Line2D(start, end); + var result = object.toRay2D(); + + return { + testName: "vision.ds.Line2D#toRay2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Line2D#toRay2D", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/MathToolsTests.hx b/tests/generated/src/tests/MathToolsTests.hx new file mode 100644 index 00000000..d3d7eed4 --- /dev/null +++ b/tests/generated/src/tests/MathToolsTests.hx @@ -0,0 +1,1664 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.tools.MathTools; +import vision.ds.Point3D; +import vision.ds.IntPoint2D; +import haxe.Int64; +import vision.ds.Rectangle; +import vision.ds.Ray2D; +import vision.ds.Line2D; +import vision.ds.Point2D; + +@:access(vision.tools.MathTools) +class MathToolsTests { + public static function vision_tools_MathTools__PI__ShouldWork():TestResult { + try { + var result = vision.tools.MathTools.PI; + + return { + testName: "vision.tools.MathTools.PI", + returned: result, + expected: Math.PI, + status: TestStatus.of(result == Math.PI) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.PI", + returned: e, + expected: Math.PI, + status: Failure + } + } + } + + public static function vision_tools_MathTools__PI_OVER_2__ShouldWork():TestResult { + try { + var result = vision.tools.MathTools.PI_OVER_2; + + return { + testName: "vision.tools.MathTools.PI_OVER_2", + returned: result, + expected: Math.PI / 2, + status: TestStatus.of(result == Math.PI / 2) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.PI_OVER_2", + returned: e, + expected: Math.PI / 2, + status: Failure + } + } + } + + public static function vision_tools_MathTools__NEGATIVE_INFINITY__ShouldWork():TestResult { + try { + var result = vision.tools.MathTools.NEGATIVE_INFINITY; + + return { + testName: "vision.tools.MathTools.NEGATIVE_INFINITY", + returned: result, + expected: Math.NEGATIVE_INFINITY, + status: TestStatus.of(result == Math.NEGATIVE_INFINITY) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.NEGATIVE_INFINITY", + returned: e, + expected: Math.NEGATIVE_INFINITY, + status: Failure + } + } + } + + public static function vision_tools_MathTools__POSITIVE_INFINITY__ShouldWork():TestResult { + try { + var result = vision.tools.MathTools.POSITIVE_INFINITY; + + return { + testName: "vision.tools.MathTools.POSITIVE_INFINITY", + returned: result, + expected: Math.POSITIVE_INFINITY, + status: TestStatus.of(result == Math.POSITIVE_INFINITY) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.POSITIVE_INFINITY", + returned: e, + expected: Math.POSITIVE_INFINITY, + status: Failure + } + } + } + + public static function vision_tools_MathTools__NaN__ShouldWork():TestResult { + try { + var result = vision.tools.MathTools.NaN; + + return { + testName: "vision.tools.MathTools.NaN", + returned: result, + expected: Math.NaN, + status: TestStatus.of(Math.isNaN(result)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.NaN", + returned: e, + expected: Math.NaN, + status: Failure + } + } + } + + public static function vision_tools_MathTools__SQRT2__ShouldWork():TestResult { + try { + var result = vision.tools.MathTools.SQRT2; + + return { + testName: "vision.tools.MathTools.SQRT2", + returned: result, + expected: Math.sqrt(2), + status: TestStatus.of(result == Math.sqrt(2)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.SQRT2", + returned: e, + expected: Math.sqrt(2), + status: Failure + } + } + } + + public static function vision_tools_MathTools__SQRT3__ShouldWork():TestResult { + try { + var result = vision.tools.MathTools.SQRT3; + + return { + testName: "vision.tools.MathTools.SQRT3", + returned: result, + expected: Math.sqrt(3), + status: TestStatus.of(result == Math.sqrt(3)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.SQRT3", + returned: e, + expected: Math.sqrt(3), + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceFromRayToPoint2D_Ray2D_Point2D_Float__ShouldWork():TestResult { + try { + var ray = new vision.ds.Ray2D({x: 0, y: 5}, 2); + var point = new vision.ds.Point2D(5, 6); + + var result = vision.tools.MathTools.distanceFromRayToPoint2D(ray, point); + + return { + testName: "vision.tools.MathTools.distanceFromRayToPoint2D", + returned: result, + expected: 4.0249223594996213, + status: TestStatus.of(result == 4.0249223594996213) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceFromRayToPoint2D", + returned: e, + expected: 4.0249223594996213, + status: Failure + } + } + } + + public static function vision_tools_MathTools__intersectionBetweenRay2Ds_Ray2D_Ray2D_Point2D__ShouldWork():TestResult { + try { + var ray = new vision.ds.Ray2D({x: 0, y: 5}, 2); + var ray2 = new vision.ds.Ray2D({x: 0, y: -6}, 1); + + var result = vision.tools.MathTools.intersectionBetweenRay2Ds(ray, ray2); + + return { + testName: "vision.tools.MathTools.intersectionBetweenRay2Ds", + returned: result, + expected: new Point2D(-11, -17), + status: TestStatus.of([result.x, result.y] == [-11, -17]) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.intersectionBetweenRay2Ds", + returned: e, + expected: new Point2D(-11, -17), + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceBetweenRays2D_Ray2D_Ray2D_Float__ShouldWork():TestResult { + try { + var ray = new vision.ds.Ray2D({x: 0, y: 5}, 2); + var ray2 = new vision.ds.Ray2D({x: 0, y: 10}, 2); + + var result = vision.tools.MathTools.distanceBetweenRays2D(ray, ray2); + + return { + testName: "vision.tools.MathTools.distanceBetweenRays2D", + returned: result, + expected: Math.sqrt(5), + status: TestStatus.of(result == Math.sqrt(5)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceBetweenRays2D", + returned: e, + expected: Math.sqrt(5), + status: Failure + } + } + } + + public static function vision_tools_MathTools__findPointAtDistanceUsingX_Ray2D_Float_Float_Bool_Point2D__ShouldWork():TestResult { + try { + var ray = new vision.ds.Ray2D({x: 0, y: 12}, 0.5); + var startXPos = 6; + var distance = 10; + + var result1 = vision.tools.MathTools.findPointAtDistanceUsingX(ray, startXPos, distance, true); + var result2 = vision.tools.MathTools.findPointAtDistanceUsingX(ray, startXPos, distance, false); + return { + testName: "vision.tools.MathTools.findPointAtDistanceUsingX", + returned: '${result1}, then: ${result2}', + expected: '${new Point2D(6 + 4 * Math.sqrt(5), 15 + 2 * Math.sqrt(5))}, then: ${new Point2D(6 - 4 * Math.sqrt(5), 15 - 2 * Math.sqrt(5))}', + status: Skipped + } + } catch (e) { + return { + testName: "vision.tools.MathTools.findPointAtDistanceUsingX", + returned: e, + expected: '${new Point2D(6 + 4 * Math.sqrt(5), 15 + 2 * Math.sqrt(5))}, then: ${new Point2D(6 - 4 * Math.sqrt(5), 15 - 2 * Math.sqrt(5))}', + status: Failure + } + } + } + + public static function vision_tools_MathTools__findPointAtDistanceUsingY_Ray2D_Float_Float_Bool_Point2D__ShouldWork():TestResult { + try { + var ray = new vision.ds.Ray2D({x: 0, y: 12}, 0.5); + var startYPos = 15; + var distance = 10; + + var result1 = vision.tools.MathTools.findPointAtDistanceUsingY(ray, startYPos, distance, true); + var result2 = vision.tools.MathTools.findPointAtDistanceUsingY(ray, startYPos, distance, false); + + return { + testName: "vision.tools.MathTools.findPointAtDistanceUsingY", + returned: '${result1}, then: ${result2}', + expected: '${new Point2D(6 + 4 * Math.sqrt(5), 15 + 2 * Math.sqrt(5))}, then: ${new Point2D(6 - 4 * Math.sqrt(5), 15 - 2 * Math.sqrt(5))}', + status: Skipped + } + } catch (e) { + return { + testName: "vision.tools.MathTools.findPointAtDistanceUsingY", + returned: e, + expected: '${new Point2D(6 + 4 * Math.sqrt(5), 15 + 2 * Math.sqrt(5))}, then: ${new Point2D(6 - 4 * Math.sqrt(5), 15 - 2 * Math.sqrt(5))}', + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceFromLineToPoint2D_Line2D_Point2D_Float__ShouldWork():TestResult { + try { + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var point = new vision.ds.Point2D(40, 20); + + var result = vision.tools.MathTools.distanceFromLineToPoint2D(line, point); + + return { + testName: "vision.tools.MathTools.distanceFromLineToPoint2D", + returned: result, + expected: 31.622776601684, + status: TestStatus.of(result == 31.622776601684) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceFromLineToPoint2D", + returned: e, + expected: 31.622776601684, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceBetweenLines2D_Line2D_Line2D_Float__ShouldWork():TestResult { + try { + var line1 = new vision.ds.Line2D({x: 11, y: 11}, {x: 20, y: 20}); + var line2 = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var result = vision.tools.MathTools.distanceBetweenLines2D(line1, line2); + + return { + testName: "vision.tools.MathTools.distanceBetweenLines2D", + returned: result, + expected: Math.sqrt(2), + status: TestStatus.of(result == Math.sqrt(2)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceBetweenLines2D", + returned: e, + expected: Math.sqrt(2), + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansFromLineToPoint2D_Line2D_Point2D_Float__ShouldWork():TestResult { + try { + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var point = new vision.ds.Point2D(40, 20); + + var result = vision.tools.MathTools.radiansFromLineToPoint2D(line, point); + + return { + testName: "vision.tools.MathTools.radiansFromLineToPoint2D", + returned: result, + expected: Math.atan2(10, 30), + status: TestStatus.of(result == Math.atan2(10, 30)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansFromLineToPoint2D", + returned: e, + expected: Math.atan2(10, 30), + status: Failure + } + } + } + + public static function vision_tools_MathTools__intersectionBetweenLine2Ds_Line2D_Line2D_Point2D__ShouldWork():TestResult { + try { + var line1 = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var line2 = new vision.ds.Line2D({x: 0, y: 10}, {x: 10, y: 0}); + + var result = vision.tools.MathTools.intersectionBetweenLine2Ds(line1, line2); + + return { + testName: "vision.tools.MathTools.intersectionBetweenLine2Ds", + returned: result, + expected: new Point2D(5, 5), + status: TestStatus.of([result.x, result.y], [5, 5]) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.intersectionBetweenLine2Ds", + returned: e, + expected: new Point2D(5, 5), + status: Failure + } + } + } + + public static function vision_tools_MathTools__mirrorInsideRectangle_Line2D_Rectangle_Line2D__ShouldWork():TestResult { + try { + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var rect:Rectangle = {x: 0, y: 0, width: 10, height: 10}; + + var result = vision.tools.MathTools.mirrorInsideRectangle(line, rect); + + return { + testName: "vision.tools.MathTools.mirrorInsideRectangle", + returned: result, + expected: new Line2D({x: 0, y: 10}, {x: 10, y: 0}), + status: TestStatus.of(result, new Line2D({x: 0, y: 10}, {x: 10, y: 0})) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.mirrorInsideRectangle", + returned: e, + expected: new Line2D({x: 0, y: 10}, {x: 10, y: 0}), + status: Failure + } + } + } + + public static function vision_tools_MathTools__flipInsideRectangle_Line2D_Rectangle_Line2D__ShouldWork():TestResult { + try { + var line = new vision.ds.Line2D({x: 2, y: 1}, {x: 8, y: 1}); + var rect:Rectangle = {x: 0, y: 0, width: 10, height: 10}; + + var result = vision.tools.MathTools.flipInsideRectangle(line, rect); + + return { + testName: "vision.tools.MathTools.flipInsideRectangle", + returned: result, + expected: new Line2D({x: 2, y: 9}, {x: 8, y: 9}), + status: TestStatus.of(result, new Line2D({x: 2, y: 9}, {x: 8, y: 9})) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.flipInsideRectangle", + returned: e, + expected: new Line2D({x: 2, y: 9}, {x: 8, y: 9}), + status: Failure + } + } + } + + public static function vision_tools_MathTools__invertInsideRectangle_Line2D_Rectangle_Line2D__ShouldWork():TestResult { + try { + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + var rect:Rectangle = {x: 0, y: 0, width: 20, height: 20}; + + var result = vision.tools.MathTools.invertInsideRectangle(line, rect); + + return { + testName: "vision.tools.MathTools.invertInsideRectangle", + returned: result, + expected: new Line2D({x: 10, y: 10}, {x: 20, y: 20}), + status: TestStatus.of(result, new Line2D({x: 10, y: 10}, {x: 20, y: 20})) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.invertInsideRectangle", + returned: e, + expected: new Line2D({x: 10, y: 10}, {x: 20, y: 20}), + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceFromPointToRay2D_Point2D_Ray2D_Float__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(Math.sqrt(2), 0); + var ray = new vision.ds.Ray2D({x: 0, y: 0}, 1); + + var result = vision.tools.MathTools.distanceFromPointToRay2D(point, ray); + + return { + testName: "vision.tools.MathTools.distanceFromPointToRay2D", + returned: result, + expected: 1, + status: TestStatus.of(result, 1) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceFromPointToRay2D", + returned: e, + expected: 1, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceFromPointToLine2D_Point2D_Line2D_Float__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(40, 20); + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var result = vision.tools.MathTools.distanceFromPointToLine2D(point, line); + + return { + testName: "vision.tools.MathTools.distanceFromLineToPoint2D", + returned: result, + expected: 31.622776601684, + status: TestStatus.of(result == 31.622776601684) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceFromPointToLine2D", + returned: e, + expected: 31.622776601684, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansFromPointToLine2D_Point2D_Line2D_Float__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var result = vision.tools.MathTools.radiansFromPointToLine2D(point, line); + + return { + testName: "vision.tools.MathTools.radiansFromPointToLine2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansFromPointToLine2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansFromPointToPoint2D_Point2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.radiansFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__degreesFromPointToPoint2D_Point2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.degreesFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__slopeFromPointToPoint2D_Point2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.slopeFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceBetweenPoints_Point2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.distanceBetweenPoints(point1, point2); + + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansFromPointToPoint2D_Point2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.radiansFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__degreesFromPointToPoint2D_Point2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.degreesFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__slopeFromPointToPoint2D_Point2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.slopeFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceBetweenPoints_Point2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.distanceBetweenPoints(point1, point2); + + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__getClosestPointOnRay2D_Point2D_Ray2D_Point2D__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var ray = new vision.ds.Ray2D({x: 0, y: 0}, 1); + + var result = vision.tools.MathTools.getClosestPointOnRay2D(point, ray); + + return { + testName: "vision.tools.MathTools.getClosestPointOnRay2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.getClosestPointOnRay2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceFromPointToRay2D_IntPoint2D_Ray2D_Float__ShouldWork():TestResult { + try { + var point = new vision.ds.IntPoint2D(0, 0); + var ray = new vision.ds.Ray2D({x: 0, y: 0}, 1); + + var result = vision.tools.MathTools.distanceFromPointToRay2D(point, ray); + + return { + testName: "vision.tools.MathTools.distanceFromPointToRay2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceFromPointToRay2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceFromPointToLine2D_IntPoint2D_Line2D_Float__ShouldWork():TestResult { + try { + var point = new vision.ds.IntPoint2D(0, 0); + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var result = vision.tools.MathTools.distanceFromPointToLine2D(point, line); + + return { + testName: "vision.tools.MathTools.distanceFromPointToLine2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceFromPointToLine2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansFromPointToLine2D_IntPoint2D_Line2D_Float__ShouldWork():TestResult { + try { + var point = new vision.ds.IntPoint2D(0, 0); + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var result = vision.tools.MathTools.radiansFromPointToLine2D(point, line); + + return { + testName: "vision.tools.MathTools.radiansFromPointToLine2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansFromPointToLine2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansFromPointToPoint2D_IntPoint2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.radiansFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__degreesFromPointToPoint2D_IntPoint2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.degreesFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__slopeFromPointToPoint2D_IntPoint2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.slopeFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceBetweenPoints_IntPoint2D_IntPoint2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.IntPoint2D(0, 0); + + var result = vision.tools.MathTools.distanceBetweenPoints(point1, point2); + + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansFromPointToPoint2D_IntPoint2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.radiansFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__degreesFromPointToPoint2D_IntPoint2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.degreesFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.degreesFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__slopeFromPointToPoint2D_IntPoint2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.slopeFromPointToPoint2D(point1, point2); + + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.slopeFromPointToPoint2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceBetweenPoints_IntPoint2D_Point2D_Float__ShouldWork():TestResult { + try { + var point1 = new vision.ds.IntPoint2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.tools.MathTools.distanceBetweenPoints(point1, point2); + + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__getClosestPointOnRay2D_IntPoint2D_Ray2D_Point2D__ShouldWork():TestResult { + try { + var point = new vision.ds.IntPoint2D(0, 0); + var ray = new vision.ds.Ray2D({x: 0, y: 0}, 1); + + var result = vision.tools.MathTools.getClosestPointOnRay2D(point, ray); + + return { + testName: "vision.tools.MathTools.getClosestPointOnRay2D", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.getClosestPointOnRay2D", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__distanceBetweenPoints_Point3D_Point3D_Float__ShouldWork():TestResult { + try { + var point1:Point3D = null; + var point2:Point3D = null; + + var result = vision.tools.MathTools.distanceBetweenPoints(point1, point2); + + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.distanceBetweenPoints", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__clamp_Int_Int_Int_Int__ShouldWork():TestResult { + try { + var value = 0; + var mi = 0; + var ma = 0; + + var result = vision.tools.MathTools.clamp(value, mi, ma); + + return { + testName: "vision.tools.MathTools.clamp", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.clamp", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__isBetweenRanges_Float_startFloatendFloat_Bool__ShouldWork():TestResult { + try { + var value = 0.0; + var ranges:{start:Float, end:Float} = null; + + var result = vision.tools.MathTools.isBetweenRanges(value, ranges); + + return { + testName: "vision.tools.MathTools.isBetweenRanges", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.isBetweenRanges", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__isBetweenRange_Float_Float_Float_Bool__ShouldWork():TestResult { + try { + var value = 0.0; + var min = 0.0; + var max = 0.0; + + var result = vision.tools.MathTools.isBetweenRange(value, min, max); + + return { + testName: "vision.tools.MathTools.isBetweenRange", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.isBetweenRange", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__wrapInt_Int_Int_Int_Int__ShouldWork():TestResult { + try { + var value = 0; + var min = 0; + var max = 0; + + var result = vision.tools.MathTools.wrapInt(value, min, max); + + return { + testName: "vision.tools.MathTools.wrapInt", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.wrapInt", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__wrapFloat_Float_Float_Float_Float__ShouldWork():TestResult { + try { + var value = 0.0; + var min = 0.0; + var max = 0.0; + + var result = vision.tools.MathTools.wrapFloat(value, min, max); + + return { + testName: "vision.tools.MathTools.wrapFloat", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.wrapFloat", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__boundInt_Int_Int_Int_Int__ShouldWork():TestResult { + try { + var value = 0; + var min = 0; + var max = 0; + + var result = vision.tools.MathTools.boundInt(value, min, max); + + return { + testName: "vision.tools.MathTools.boundInt", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.boundInt", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__boundFloat_Float_Float_Float_Float__ShouldWork():TestResult { + try { + var value = 0.0; + var min = 0.0; + var max = 0.0; + + var result = vision.tools.MathTools.boundFloat(value, min, max); + + return { + testName: "vision.tools.MathTools.boundFloat", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.boundFloat", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__gamma_Float_Float__ShouldWork():TestResult { + try { + var x = 0.0; + + var result = vision.tools.MathTools.gamma(x); + + return { + testName: "vision.tools.MathTools.gamma", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.gamma", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__factorial_Float_Float__ShouldWork():TestResult { + try { + var value = 0.0; + + var result = vision.tools.MathTools.factorial(value); + + return { + testName: "vision.tools.MathTools.factorial", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.factorial", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__slopeToDegrees_Float_Float__ShouldWork():TestResult { + try { + var slope = 0.0; + + var result = vision.tools.MathTools.slopeToDegrees(slope); + + return { + testName: "vision.tools.MathTools.slopeToDegrees", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.slopeToDegrees", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__slopeToRadians_Float_Float__ShouldWork():TestResult { + try { + var slope = 0.0; + + var result = vision.tools.MathTools.slopeToRadians(slope); + + return { + testName: "vision.tools.MathTools.slopeToRadians", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.slopeToRadians", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__degreesToSlope_Float_Float__ShouldWork():TestResult { + try { + var degrees = 0.0; + + var result = vision.tools.MathTools.degreesToSlope(degrees); + + return { + testName: "vision.tools.MathTools.degreesToSlope", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.degreesToSlope", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__degreesToRadians_Float_Float__ShouldWork():TestResult { + try { + var degrees = 0.0; + + var result = vision.tools.MathTools.degreesToRadians(degrees); + + return { + testName: "vision.tools.MathTools.degreesToRadians", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.degreesToRadians", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansToDegrees_Float_Float__ShouldWork():TestResult { + try { + var radians = 0.0; + + var result = vision.tools.MathTools.radiansToDegrees(radians); + + return { + testName: "vision.tools.MathTools.radiansToDegrees", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansToDegrees", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__radiansToSlope_Float_Float__ShouldWork():TestResult { + try { + var radians = 0.0; + + var result = vision.tools.MathTools.radiansToSlope(radians); + + return { + testName: "vision.tools.MathTools.radiansToSlope", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.radiansToSlope", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__cotan_Float_Float__ShouldWork():TestResult { + try { + var radians = 6; + + var result = vision.tools.MathTools.cotan(radians); + + return { + testName: "vision.tools.MathTools.cotan", + returned: result, + expected: Math.cos(6) / Math.sin(6), + status: TestStatus.of(result == Math.cos(6) / Math.sin(6)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.cotan", + returned: e, + expected: Math.cos(6) / Math.sin(6), + status: Failure + } + } + } + + public static function vision_tools_MathTools__cosec_Float_Float__ShouldWork():TestResult { + try { + var radians = 5; + + var result = vision.tools.MathTools.cosec(radians); + + return { + testName: "vision.tools.MathTools.cosec", + returned: result, + expected: 1 / Math.sin(5), + status: TestStatus.of(result == 1 / Math.sin(5)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.cosec", + returned: e, + expected: 1 / Math.sin(5), + status: Failure + } + } + } + + public static function vision_tools_MathTools__sec_Float_Float__ShouldWork():TestResult { + try { + var radians = 5; + + var result = vision.tools.MathTools.sec(radians); + + return { + testName: "vision.tools.MathTools.sec", + returned: result, + expected: 1 / Math.cos(5), + status: TestStatus.of(result == 1 / Math.cos(5)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.sec", + returned: e, + expected: 1 / Math.cos(5), + status: Failure + } + } + } + + public static function vision_tools_MathTools__sind_Float_Float__ShouldWork():TestResult { + try { + var degrees = 30; + + var result = vision.tools.MathTools.sind(degrees); + + return { + testName: "vision.tools.MathTools.sind", + returned: result, + expected: Math.sin(30 * Math.PI / 180), + status: TestStatus.of(result == Math.sin(30 * Math.PI / 180)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.sind", + returned: e, + expected: Math.sin(30 * Math.PI / 180), + status: Failure + } + } + } + + public static function vision_tools_MathTools__cosd_Float_Float__ShouldWork():TestResult { + try { + var degrees = 30; + + var result = vision.tools.MathTools.cosd(degrees); + + return { + testName: "vision.tools.MathTools.cosd", + returned: result, + expected: Math.cos(30 * Math.PI / 180), + status: TestStatus.of(result == Math.cos(30 * Math.PI / 180)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.cosd", + returned: e, + expected: Math.cos(30 * Math.PI / 180), + status: Failure + } + } + } + + public static function vision_tools_MathTools__tand_Float_Float__ShouldWork():TestResult { + try { + var degrees = 6; + + var result = vision.tools.MathTools.tand(degrees); + + return { + testName: "vision.tools.MathTools.tand", + returned: result, + expected: Math.tan(6 * Math.PI / 180), + status: TestStatus.of(result == Math.tan(6 * Math.PI / 180)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.tand", + returned: e, + expected: Math.tan(6 * Math.PI / 180), + status: Failure + } + } + } + + public static function vision_tools_MathTools__cotand_Float_Float__ShouldWork():TestResult { + try { + var degrees = 4; + + var result = vision.tools.MathTools.cotand(degrees); + + return { + testName: "vision.tools.MathTools.cotand", + returned: result, + expected: Math.cos(4 * Math.PI / 180) / Math.sin(4 * Math.PI / 180), + status: TestStatus.of(result == Math.cos(4 * Math.PI / 180) / Math.sin(4 * Math.PI / 180)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.cotand", + returned: e, + expected: Math.cos(4 * Math.PI / 180) / Math.sin(4 * Math.PI / 180), + status: Failure + } + } + } + + public static function vision_tools_MathTools__cosecd_Float_Float__ShouldWork():TestResult { + try { + var degrees = 40; + + var result = vision.tools.MathTools.cosecd(degrees); + + return { + testName: "vision.tools.MathTools.cosecd", + returned: result, + expected: 1 / Math.sin(40 * Math.PI / 180), + status: TestStatus.of(result == 1 / Math.sin(40 * Math.PI / 180)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.cosecd", + returned: e, + expected: 1 / Math.sin(40 * Math.PI / 180), + status: Failure + } + } + } + + public static function vision_tools_MathTools__secd_Float_Float__ShouldWork():TestResult { + try { + var degrees = 40; + + var result = vision.tools.MathTools.secd(degrees); + + return { + testName: "vision.tools.MathTools.secd", + returned: result, + expected: 1 / Math.cos(40 * Math.PI / 180), + status: TestStatus.of(result == 1 / Math.cos(40 * Math.PI / 180)) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.secd", + returned: e, + expected: 1 / Math.cos(40 * Math.PI / 180), + status: Failure + } + } + } + + public static function vision_tools_MathTools__truncate_Float_Int_Float__ShouldWork():TestResult { + try { + var num = 3.141592653589793; + var numbersAfterDecimal = 2; + + var result = vision.tools.MathTools.truncate(num, numbersAfterDecimal); + + return { + testName: "vision.tools.MathTools.truncate", + returned: result, + expected: 3.14, + status: TestStatus.of(result == 3.14) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.truncate", + returned: e, + expected: 3.14, + status: Failure + } + } + } + + public static function vision_tools_MathTools__cropDecimal_Float_Int__ShouldWork():TestResult { + try { + var number = 3.141592653589793; + + var result = vision.tools.MathTools.cropDecimal(number); + + return { + testName: "vision.tools.MathTools.cropDecimal", + returned: result, + expected: 3, + status: TestStatus.of(result == 3) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.cropDecimal", + returned: e, + expected: 3, + status: Failure + } + } + } + + public static function vision_tools_MathTools__isInt_Float_Bool__ShouldWork():TestResult { + try { + var v = 0.1; + + var result = vision.tools.MathTools.isInt(v); + + return { + testName: "vision.tools.MathTools.isInt", + returned: result, + expected: false, + status: TestStatus.of(result == false) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.isInt", + returned: e, + expected: false, + status: Failure + } + } + } + + public static function vision_tools_MathTools__toFloat_Int64_Float__ShouldWork():TestResult { + try { + var value:Int64 = null; + + var result = vision.tools.MathTools.toFloat(value); + + return { + testName: "vision.tools.MathTools.toFloat", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.tools.MathTools.toFloat", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_tools_MathTools__parseBool_String_Bool__ShouldWork():TestResult { + try { + var s = "true"; + + var result = vision.tools.MathTools.parseBool(s); + + return { + testName: "vision.tools.MathTools.parseBool", + returned: result, + expected: true, + status: TestStatus.of(result == true) + } + } catch (e) { + return { + testName: "vision.tools.MathTools.parseBool", + returned: e, + expected: true, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/Matrix2DTests.hx b/tests/generated/src/tests/Matrix2DTests.hx new file mode 100644 index 00000000..d024d2f7 --- /dev/null +++ b/tests/generated/src/tests/Matrix2DTests.hx @@ -0,0 +1,959 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Matrix2D; +import vision.algorithms.PerspectiveWarp; +import vision.ds.specifics.PointTransformationPair; +import vision.exceptions.MatrixOperationError; +import vision.algorithms.GaussJordan; +import vision.ds.Array2D; +import vision.tools.MathTools.*; + +@:access(vision.ds.Matrix2D) +class Matrix2DTests { + public static function vision_ds_Matrix2D__underlying__ShouldWork():TestResult { + try { + var width = 2; + var height = 2; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.underlying; + + return { + testName: "vision.ds.Matrix2D#underlying", + returned: result, + expected: new Array2D(width, height, 2), + status: TestStatus.of(result, new Array2D(width, height, 0)) + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#underlying", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__rows__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.rows; + + return { + testName: "vision.ds.Matrix2D#rows", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#rows", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__columns__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.columns; + + return { + testName: "vision.ds.Matrix2D#columns", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#columns", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__IDENTITY__TransformationMatrix2D__ShouldWork():TestResult { + try { + + var result = vision.ds.Matrix2D.IDENTITY(); + + return { + testName: "vision.ds.Matrix2D.IDENTITY", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.IDENTITY", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__ROTATION_Float_Bool_Point2D_TransformationMatrix2D__ShouldWork():TestResult { + try { + var angle = 0.0; + var degrees = false; + var origin = new vision.ds.Point2D(0, 0); + + var result = vision.ds.Matrix2D.ROTATION(angle, degrees, origin); + + return { + testName: "vision.ds.Matrix2D.ROTATION", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.ROTATION", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__TRANSLATION_Float_Float_TransformationMatrix2D__ShouldWork():TestResult { + try { + var x = 0.0; + var y = 0.0; + + var result = vision.ds.Matrix2D.TRANSLATION(x, y); + + return { + testName: "vision.ds.Matrix2D.TRANSLATION", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.TRANSLATION", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__SCALE_Float_Float_TransformationMatrix2D__ShouldWork():TestResult { + try { + var scaleX = 0.0; + var scaleY = 0.0; + + var result = vision.ds.Matrix2D.SCALE(scaleX, scaleY); + + return { + testName: "vision.ds.Matrix2D.SCALE", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.SCALE", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__SHEAR_Float_Float_TransformationMatrix2D__ShouldWork():TestResult { + try { + var shearX = 0.0; + var shearY = 0.0; + + var result = vision.ds.Matrix2D.SHEAR(shearX, shearY); + + return { + testName: "vision.ds.Matrix2D.SHEAR", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.SHEAR", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__REFLECTION_Float_Bool_Point2D_TransformationMatrix2D__ShouldWork():TestResult { + try { + var angle = 0.0; + var degrees = false; + var origin = new vision.ds.Point2D(0, 0); + + var result = vision.ds.Matrix2D.REFLECTION(angle, degrees, origin); + + return { + testName: "vision.ds.Matrix2D.REFLECTION", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.REFLECTION", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__PERSPECTIVE_ArrayPointTransformationPair_TransformationMatrix2D__ShouldWork():TestResult { + try { + var pointPairs = []; + + var result = vision.ds.Matrix2D.PERSPECTIVE(pointPairs); + + return { + testName: "vision.ds.Matrix2D.PERSPECTIVE", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.PERSPECTIVE", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__DEPTH_Float_Point2D_TransformationMatrix2D__ShouldWork():TestResult { + try { + var z = 0.0; + var towards = new vision.ds.Point2D(0, 0); + + var result = vision.ds.Matrix2D.DEPTH(z, towards); + + return { + testName: "vision.ds.Matrix2D.DEPTH", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.DEPTH", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__createFilled_ArrayFloat_Matrix2D__ShouldWork():TestResult { + try { + var rows = []; + + var result = vision.ds.Matrix2D.createFilled(rows); + + return { + testName: "vision.ds.Matrix2D.createFilled", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.createFilled", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__createTransformation_ArrayFloat_ArrayFloat_ArrayFloat_Matrix2D__ShouldWork():TestResult { + try { + var xRow = []; + var yRow = []; + var homogeneousRow = []; + + var result = vision.ds.Matrix2D.createTransformation(xRow, yRow, homogeneousRow); + + return { + testName: "vision.ds.Matrix2D.createTransformation", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.createTransformation", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__multiplyMatrices_Matrix2D_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var a:Matrix2D = null; + var b:Matrix2D = null; + + var result = vision.ds.Matrix2D.multiplyMatrices(a, b); + + return { + testName: "vision.ds.Matrix2D.multiplyMatrices", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.multiplyMatrices", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__addMatrices_Matrix2D_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var a:Matrix2D = null; + var b:Matrix2D = null; + + var result = vision.ds.Matrix2D.addMatrices(a, b); + + return { + testName: "vision.ds.Matrix2D.addMatrices", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.addMatrices", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__subtractMatrices_Matrix2D_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var a:Matrix2D = null; + var b:Matrix2D = null; + + var result = vision.ds.Matrix2D.subtractMatrices(a, b); + + return { + testName: "vision.ds.Matrix2D.subtractMatrices", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.subtractMatrices", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__divideMatrices_Matrix2D_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var a:Matrix2D = null; + var b:Matrix2D = null; + + var result = vision.ds.Matrix2D.divideMatrices(a, b); + + return { + testName: "vision.ds.Matrix2D.divideMatrices", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D.divideMatrices", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__invert__Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + + var object = new vision.ds.Matrix2D(width, height); + var result = object.invert(); + + return { + testName: "vision.ds.Matrix2D#invert", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#invert", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__getDeterminant__Float__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + + var object = new vision.ds.Matrix2D(width, height); + var result = object.getDeterminant(); + + return { + testName: "vision.ds.Matrix2D#getDeterminant", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#getDeterminant", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__getTrace__Float__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + + var object = new vision.ds.Matrix2D(width, height); + var result = object.getTrace(); + + return { + testName: "vision.ds.Matrix2D#getTrace", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#getTrace", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__getAverage__Float__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + + var object = new vision.ds.Matrix2D(width, height); + var result = object.getAverage(); + + return { + testName: "vision.ds.Matrix2D#getAverage", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#getAverage", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__multiplyWithScalar_Float_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var scalar = 0.0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.multiplyWithScalar(scalar); + + return { + testName: "vision.ds.Matrix2D#multiplyWithScalar", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#multiplyWithScalar", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__clone__Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + + var object = new vision.ds.Matrix2D(width, height); + var result = object.clone(); + + return { + testName: "vision.ds.Matrix2D#clone", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#clone", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__map_FloatFloat_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var mappingFunction = (_) -> null; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.map(mappingFunction); + + return { + testName: "vision.ds.Matrix2D#map", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#map", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__getSubMatrix_Int_Int_Int_Int_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var fromX = 0; + var fromY = 0; + var toX = 0; + var toY = 0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.getSubMatrix(fromX, fromY, toX, toY); + + return { + testName: "vision.ds.Matrix2D#getSubMatrix", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#getSubMatrix", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__getColumn_Int_ArrayFloat__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var x = 0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.getColumn(x); + + return { + testName: "vision.ds.Matrix2D#getColumn", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#getColumn", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__getRow_Int_ArrayFloat__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var y = 0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.getRow(y); + + return { + testName: "vision.ds.Matrix2D#getRow", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#getRow", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__setColumn__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var x = 0; + var arr = []; + + var object = new vision.ds.Matrix2D(width, height); + object.setColumn(x, arr); + + return { + testName: "vision.ds.Matrix2D#setColumn", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#setColumn", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__setRow__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var y = 0; + var arr = []; + + var object = new vision.ds.Matrix2D(width, height); + object.setRow(y, arr); + + return { + testName: "vision.ds.Matrix2D#setRow", + returned: null, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#setRow", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__insertColumn_Int_ArrayFloat_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var x = 0; + var arr = []; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.insertColumn(x, arr); + + return { + testName: "vision.ds.Matrix2D#insertColumn", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#insertColumn", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__insertRow_Int_ArrayFloat_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var y = 0; + var arr = []; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.insertRow(y, arr); + + return { + testName: "vision.ds.Matrix2D#insertRow", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#insertRow", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__removeColumn_Int_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var x = 0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.removeColumn(x); + + return { + testName: "vision.ds.Matrix2D#removeColumn", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#removeColumn", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__removeRow_Int_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var y = 0; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.removeRow(y); + + return { + testName: "vision.ds.Matrix2D#removeRow", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#removeRow", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__toString_Int_Bool_String__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var precision = 0; + var pretty = false; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.toString(precision, pretty); + + return { + testName: "vision.ds.Matrix2D#toString", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#toString", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__multiply_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var b:Matrix2D = null; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.multiply(b); + + return { + testName: "vision.ds.Matrix2D#multiply", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#multiply", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__add_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var b:Matrix2D = null; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.add(b); + + return { + testName: "vision.ds.Matrix2D#add", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#add", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__subtract_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var b:Matrix2D = null; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.subtract(b); + + return { + testName: "vision.ds.Matrix2D#subtract", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#subtract", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Matrix2D__divide_Matrix2D_Matrix2D__ShouldWork():TestResult { + try { + var width = 0; + var height = 0; + + var b:Matrix2D = null; + + var object = new vision.ds.Matrix2D(width, height); + var result = object.divide(b); + + return { + testName: "vision.ds.Matrix2D#divide", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Matrix2D#divide", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/PerspectiveWarpTests.hx b/tests/generated/src/tests/PerspectiveWarpTests.hx new file mode 100644 index 00000000..8c4c3ffa --- /dev/null +++ b/tests/generated/src/tests/PerspectiveWarpTests.hx @@ -0,0 +1,36 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.PerspectiveWarp; +import vision.ds.Matrix2D; +import vision.ds.Point2D; + +@:access(vision.algorithms.PerspectiveWarp) +class PerspectiveWarpTests { + public static function vision_algorithms_PerspectiveWarp__generateMatrix_ArrayPoint2D_ArrayPoint2D_Matrix2D__ShouldWork():TestResult { + try { + var destinationPoints = []; + var sourcePoints = []; + + var result = vision.algorithms.PerspectiveWarp.generateMatrix(destinationPoints, sourcePoints); + + return { + testName: "vision.algorithms.PerspectiveWarp.generateMatrix", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.PerspectiveWarp.generateMatrix", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/PerwittTests.hx b/tests/generated/src/tests/PerwittTests.hx new file mode 100644 index 00000000..96a64b2e --- /dev/null +++ b/tests/generated/src/tests/PerwittTests.hx @@ -0,0 +1,59 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.Perwitt; +import vision.ds.Color; +import vision.tools.ImageTools; +import vision.ds.Image; + +@:access(vision.algorithms.Perwitt) +class PerwittTests { + public static function vision_algorithms_Perwitt__convolveWithPerwittOperator_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.algorithms.Perwitt.convolveWithPerwittOperator(image); + + return { + testName: "vision.algorithms.Perwitt.convolveWithPerwittOperator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Perwitt.convolveWithPerwittOperator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Perwitt__detectEdges_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var threshold = 0.0; + + var result = vision.algorithms.Perwitt.detectEdges(image, threshold); + + return { + testName: "vision.algorithms.Perwitt.detectEdges", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Perwitt.detectEdges", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/Point2DTests.hx b/tests/generated/src/tests/Point2DTests.hx new file mode 100644 index 00000000..8ca8c2c0 --- /dev/null +++ b/tests/generated/src/tests/Point2DTests.hx @@ -0,0 +1,140 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Point2D; +import vision.tools.MathTools; + +@:access(vision.ds.Point2D) +class Point2DTests { + public static function vision_ds_Point2D__toString__String__ShouldWork():TestResult { + try { + var x = 0.1; + var y = 0.2; + + + var object = new vision.ds.Point2D(x, y); + var result = object.toString(); + + return { + testName: "vision.ds.Point2D#toString", + returned: result, + expected: "(0.1, 0.2)", + status: TestStatus.of(result == "(0.1, 0.2)") + } + } catch (e) { + return { + testName: "vision.ds.Point2D#toString", + returned: e, + expected: "(0.1, 0.2)", + status: Failure + } + } + } + + public static function vision_ds_Point2D__copy__Point2D__ShouldWork():TestResult { + try { + var x = 1.0; + var y = 0.1; + + + var object = new vision.ds.Point2D(x, y); + var result = object.copy(); + + return { + testName: "vision.ds.Point2D#copy", + returned: result, + expected: new Point2D(1, 0.1), + status: TestStatus.of([result.x, result.y], [1, 0.1]) + } + } catch (e) { + return { + testName: "vision.ds.Point2D#copy", + returned: e, + expected: new Point2D(1, 0.1), + status: Failure + } + } + } + + public static function vision_ds_Point2D__distanceTo_Point2D_Float__ShouldWork():TestResult { + try { + var x = 0.0; + var y = 0.0; + + var point = new vision.ds.Point2D(1, 1); + + var object = new vision.ds.Point2D(x, y); + var result = object.distanceTo(point); + + return { + testName: "vision.ds.Point2D#distanceTo", + returned: result, + expected: MathTools.SQRT2, + status: TestStatus.of(result == MathTools.SQRT2) + } + } catch (e) { + return { + testName: "vision.ds.Point2D#distanceTo", + returned: e, + expected: MathTools.SQRT2, + status: Failure + } + } + } + + public static function vision_ds_Point2D__degreesTo_Point2D_Float__ShouldWork():TestResult { + try { + var x = 0.0; + var y = 0.0; + + var point = new vision.ds.Point2D(2, 1); + + var object = new vision.ds.Point2D(x, y); + var result = object.degreesTo(point); + + return { + testName: "vision.ds.Point2D#degreesTo", + returned: result, + expected: 30, + status: TestStatus.of(result == 30) + } + } catch (e) { + return { + testName: "vision.ds.Point2D#degreesTo", + returned: e, + expected: 30, + status: Failure + } + } + } + + public static function vision_ds_Point2D__radiansTo_Point2D_Float__ShouldWork():TestResult { + try { + var x = 0.0; + var y = 0.0; + + var point = new vision.ds.Point2D(2, 1); + + var object = new vision.ds.Point2D(x, y); + var result = object.radiansTo(point); + + return { + testName: "vision.ds.Point2D#radiansTo", + returned: result, + expected: 30 * MathTools.PI / 180, + status: TestStatus.of(result == 30 * MathTools.PI / 180) + } + } catch (e) { + return { + testName: "vision.ds.Point2D#radiansTo", + returned: e, + expected: 30 * MathTools.PI / 180, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/Point3DTests.hx b/tests/generated/src/tests/Point3DTests.hx new file mode 100644 index 00000000..69a6e07c --- /dev/null +++ b/tests/generated/src/tests/Point3DTests.hx @@ -0,0 +1,89 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Point3D; +import vision.tools.MathTools; + +@:access(vision.ds.Point3D) +class Point3DTests { + public static function vision_ds_Point3D__distanceTo_Point3D_Float__ShouldWork():TestResult { + try { + var x = 0.0; + var y = 0.0; + var z = 0.0; + + var point = new Point3D(1, 1, 1); + + var object = new vision.ds.Point3D(x, y, z); + var result = object.distanceTo(point); + + return { + testName: "vision.ds.Point3D#distanceTo", + returned: result, + expected: MathTools.SQRT3, + status: TestStatus.of(result == MathTools.SQRT3) + } + } catch (e) { + return { + testName: "vision.ds.Point3D#distanceTo", + returned: e, + expected: MathTools.SQRT3, + status: Failure + } + } + } + + public static function vision_ds_Point3D__copy__Point3D__ShouldWork():TestResult { + try { + var x = 0.1; + var y = 0.2; + var z = 0.3; + + + var object = new vision.ds.Point3D(x, y, z); + var result = object.copy(); + + return { + testName: "vision.ds.Point3D#copy", + returned: result, + expected: new Point3D(0.1, 0.2, 0.3), + status: TestStatus.of([result.x, result.y, result.z], [0.1, 0.2, 0.3]) + } + } catch (e) { + return { + testName: "vision.ds.Point3D#copy", + returned: e, + expected: new Point3D(0.1, 0.2, 0.3), + status: Failure + } + } + } + + public static function vision_ds_Point3D__toString__String__ShouldWork():TestResult { + try { + var x = 0.1; + var y = 0.2; + var z = 0.3; + + + var object = new vision.ds.Point3D(x, y, z); + var result = object.toString(); + + return { + testName: "vision.ds.Point3D#toString", + returned: result, + expected: "(0.1, 0.2, 0.3)", + status: TestStatus.of(result == "(0.1, 0.2, 0.3)") + } + } catch (e) { + return { + testName: "vision.ds.Point3D#toString", + returned: e, + expected: "(0.1, 0.2, 0.3)", + status: Failure + } + } + } +} \ No newline at end of file diff --git a/tests/generated/src/tests/QueueCellTests.hx b/tests/generated/src/tests/QueueCellTests.hx new file mode 100644 index 00000000..afcd33e1 --- /dev/null +++ b/tests/generated/src/tests/QueueCellTests.hx @@ -0,0 +1,38 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.QueueCell; + + +@:access(vision.ds.QueueCell) +class QueueCellTests { + public static function vision_ds_QueueCell__getValue__T__ShouldWork():TestResult { + try { + var value = 0; + var next = new vision.ds.QueueCell(0, null, null); + var previous = new vision.ds.QueueCell(0, null, null); + + + var object = new vision.ds.QueueCell(value, next, previous); + var result = object.getValue(); + + return { + testName: "vision.ds.QueueCell#getValue", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.QueueCell#getValue", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/QueueTests.hx b/tests/generated/src/tests/QueueTests.hx new file mode 100644 index 00000000..0fb698b6 --- /dev/null +++ b/tests/generated/src/tests/QueueTests.hx @@ -0,0 +1,151 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Queue; + + +@:access(vision.ds.Queue) +class QueueTests { + public static function vision_ds_Queue__last__ShouldWork():TestResult { + try { + + var object = new vision.ds.Queue(); + var result = object.last; + + return { + testName: "vision.ds.Queue#last", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Queue#last", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Queue__iterator__IteratorT__ShouldWork():TestResult { + try { + + + var object = new vision.ds.Queue(); + var result = object.iterator(); + + return { + testName: "vision.ds.Queue#iterator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Queue#iterator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Queue__dequeue__T__ShouldWork():TestResult { + try { + + + var object = new vision.ds.Queue(); + var result = object.dequeue(); + + return { + testName: "vision.ds.Queue#dequeue", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Queue#dequeue", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Queue__enqueue_T_T__ShouldWork():TestResult { + try { + + var value = 0; + + var object = new vision.ds.Queue(); + var result = object.enqueue(value); + + return { + testName: "vision.ds.Queue#enqueue", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Queue#enqueue", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Queue__has_T_Bool__ShouldWork():TestResult { + try { + + var value = 0; + + var object = new vision.ds.Queue(); + var result = object.has(value); + + return { + testName: "vision.ds.Queue#has", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Queue#has", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Queue__toString__String__ShouldWork():TestResult { + try { + + + var object = new vision.ds.Queue(); + var result = object.toString(); + + return { + testName: "vision.ds.Queue#toString", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Queue#toString", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/RadixTests.hx b/tests/generated/src/tests/RadixTests.hx new file mode 100644 index 00000000..fc5c431f --- /dev/null +++ b/tests/generated/src/tests/RadixTests.hx @@ -0,0 +1,80 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.Radix; +import vision.tools.ArrayTools; +import haxe.extern.EitherType; +import haxe.Int64; + +@:access(vision.algorithms.Radix) +class RadixTests { + public static function vision_algorithms_Radix__sort_ArrayInt_ArrayInt__ShouldWork():TestResult { + try { + var main = [-23, 32, 0, 2341, -55, 324350135, -2349512]; + + var result = vision.algorithms.Radix.sort(main); + + return { + testName: "vision.algorithms.Radix.sort", + returned: result, + expected: [-2349512, -55, -23, 0, 32, 2341, 324350135], + status: TestStatus.of(result, [-2349512, -55, -23, 0, 32, 2341, 324350135]) + } + } catch (e) { + return { + testName: "vision.algorithms.Radix.sort", + returned: e, + expected: [-2349512, -55, -23, 0, 32, 2341, 324350135], + status: Failure + } + } + } + + public static function vision_algorithms_Radix__sort_ArrayUInt_ArrayUInt__ShouldWork():TestResult { + try { + var main:Array = [0, 123, 5, 432, 7, 9, 1234]; + + var result = vision.algorithms.Radix.sort(main); + + return { + testName: "vision.algorithms.Radix.sort", + returned: result, + expected: [0, 5, 7, 9, 123, 1234, 432], + status: TestStatus.of(result, [0, 5, 7, 9, 123, 1234, 432]) + } + } catch (e) { + return { + testName: "vision.algorithms.Radix.sort", + returned: e, + expected: [0, 5, 7, 9, 123, 1234, 432], + status: Failure + } + } + } + + public static function vision_algorithms_Radix__sort_ArrayInt64_ArrayInt64__ShouldWork():TestResult { + try { + var main:Array = [0, 32403258122i64, -532874197498234i64, 235981, -352, -4, 214]; + + var result = vision.algorithms.Radix.sort(main); + + return { + testName: "vision.algorithms.Radix.sort", + returned: result, + expected: [-532874197498234i64, -352, -4, 0, 214, 235981, 32403258122i64], + status: TestStatus.of(result, [-532874197498234i64, -352, -4, 0, 214, 235981, 32403258122i64]) + } + } catch (e) { + return { + testName: "vision.algorithms.Radix.sort", + returned: e, + expected: [-532874197498234i64, -352, -4, 0, 214, 235981, 32403258122i64], + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/Ray2DTests.hx b/tests/generated/src/tests/Ray2DTests.hx new file mode 100644 index 00000000..54f298dc --- /dev/null +++ b/tests/generated/src/tests/Ray2DTests.hx @@ -0,0 +1,199 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.Ray2D; +import vision.tools.MathTools; + +@:access(vision.ds.Ray2D) +class Ray2DTests { + public static function vision_ds_Ray2D__yIntercept__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var m = 0.0; + var degrees = 0.0; + var radians = 0.0; + + var object = new vision.ds.Ray2D(point, m, degrees, radians); + var result = object.yIntercept; + + return { + testName: "vision.ds.Ray2D#yIntercept", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Ray2D#yIntercept", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Ray2D__xIntercept__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var m = 0.0; + var degrees = 0.0; + var radians = 0.0; + + var object = new vision.ds.Ray2D(point, m, degrees, radians); + var result = object.xIntercept; + + return { + testName: "vision.ds.Ray2D#xIntercept", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Ray2D#xIntercept", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Ray2D__from2Points_Point2D_Point2D_Ray2D__ShouldWork():TestResult { + try { + var point1 = new vision.ds.Point2D(0, 0); + var point2 = new vision.ds.Point2D(0, 0); + + var result = vision.ds.Ray2D.from2Points(point1, point2); + + return { + testName: "vision.ds.Ray2D.from2Points", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Ray2D.from2Points", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Ray2D__getPointAtX_Float_Point2D__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var m = 0.0; + var degrees = 0.0; + var radians = 0.0; + + var x = 0.0; + + var object = new vision.ds.Ray2D(point, m, degrees, radians); + var result = object.getPointAtX(x); + + return { + testName: "vision.ds.Ray2D#getPointAtX", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Ray2D#getPointAtX", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Ray2D__getPointAtY_Float_Point2D__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var m = 0.0; + var degrees = 0.0; + var radians = 0.0; + + var y = 0.0; + + var object = new vision.ds.Ray2D(point, m, degrees, radians); + var result = object.getPointAtY(y); + + return { + testName: "vision.ds.Ray2D#getPointAtY", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Ray2D#getPointAtY", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Ray2D__intersect_Ray2D_Point2D__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var m = 0.0; + var degrees = 0.0; + var radians = 0.0; + + var ray = new vision.ds.Ray2D({x: 0, y: 0}, 1); + + var object = new vision.ds.Ray2D(point, m, degrees, radians); + var result = object.intersect(ray); + + return { + testName: "vision.ds.Ray2D#intersect", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Ray2D#intersect", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_Ray2D__distanceTo_Ray2D_Float__ShouldWork():TestResult { + try { + var point = new vision.ds.Point2D(0, 0); + var m = 0.0; + var degrees = 0.0; + var radians = 0.0; + + var ray = new vision.ds.Ray2D({x: 0, y: 0}, 1); + + var object = new vision.ds.Ray2D(point, m, degrees, radians); + var result = object.distanceTo(ray); + + return { + testName: "vision.ds.Ray2D#distanceTo", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.Ray2D#distanceTo", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/RobertsCrossTests.hx b/tests/generated/src/tests/RobertsCrossTests.hx new file mode 100644 index 00000000..ac26b168 --- /dev/null +++ b/tests/generated/src/tests/RobertsCrossTests.hx @@ -0,0 +1,35 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.RobertsCross; +import vision.tools.ImageTools; +import vision.ds.Image; + +@:access(vision.algorithms.RobertsCross) +class RobertsCrossTests { + public static function vision_algorithms_RobertsCross__convolveWithRobertsCross_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.algorithms.RobertsCross.convolveWithRobertsCross(image); + + return { + testName: "vision.algorithms.RobertsCross.convolveWithRobertsCross", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.RobertsCross.convolveWithRobertsCross", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/SimpleHoughTests.hx b/tests/generated/src/tests/SimpleHoughTests.hx new file mode 100644 index 00000000..2a25887c --- /dev/null +++ b/tests/generated/src/tests/SimpleHoughTests.hx @@ -0,0 +1,60 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.SimpleHough; +import vision.ds.Color; +import vision.ds.Ray2D; +import vision.ds.Image; + +@:access(vision.algorithms.SimpleHough) +class SimpleHoughTests { + public static function vision_algorithms_SimpleHough__detectLines_Image_Int_ArrayRay2D__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var threshold = 0; + + var result = vision.algorithms.SimpleHough.detectLines(image, threshold); + + return { + testName: "vision.algorithms.SimpleHough.detectLines", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.SimpleHough.detectLines", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_SimpleHough__mapLines_Image_ArrayRay2D_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var rays = []; + + var result = vision.algorithms.SimpleHough.mapLines(image, rays); + + return { + testName: "vision.algorithms.SimpleHough.mapLines", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.SimpleHough.mapLines", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/SimpleLineDetectorTests.hx b/tests/generated/src/tests/SimpleLineDetectorTests.hx new file mode 100644 index 00000000..4ed05fbf --- /dev/null +++ b/tests/generated/src/tests/SimpleLineDetectorTests.hx @@ -0,0 +1,89 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.SimpleLineDetector; +import vision.tools.MathTools; +import vision.ds.Int16Point2D; +import vision.ds.Line2D; +import vision.ds.Image; +import vision.ds.IntPoint2D; + +@:access(vision.algorithms.SimpleLineDetector) +class SimpleLineDetectorTests { + public static function vision_algorithms_SimpleLineDetector__findLineFromPoint_Image_Int16Point2D_Float_Bool_Bool_Line2D__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var point = new vision.ds.Int16Point2D(0, 0); + var minLineLength = 0.0; + var preferTTB = false; + var preferRTL = false; + + var result = vision.algorithms.SimpleLineDetector.findLineFromPoint(image, point, minLineLength, preferTTB, preferRTL); + + return { + testName: "vision.algorithms.SimpleLineDetector.findLineFromPoint", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.SimpleLineDetector.findLineFromPoint", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_SimpleLineDetector__lineCoveragePercentage_Image_Line2D_Float__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var line = new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10}); + + var result = vision.algorithms.SimpleLineDetector.lineCoveragePercentage(image, line); + + return { + testName: "vision.algorithms.SimpleLineDetector.lineCoveragePercentage", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.SimpleLineDetector.lineCoveragePercentage", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_SimpleLineDetector__correctLines_ArrayLine2D_Float_Float_ArrayLine2D__ShouldWork():TestResult { + try { + var lines = []; + var distanceThreshold = 0.0; + var degError = 0.0; + + var result = vision.algorithms.SimpleLineDetector.correctLines(lines, distanceThreshold, degError); + + return { + testName: "vision.algorithms.SimpleLineDetector.correctLines", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.SimpleLineDetector.correctLines", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/SobelTests.hx b/tests/generated/src/tests/SobelTests.hx new file mode 100644 index 00000000..fe053e69 --- /dev/null +++ b/tests/generated/src/tests/SobelTests.hx @@ -0,0 +1,59 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.algorithms.Sobel; +import vision.ds.Color; +import vision.tools.ImageTools; +import vision.ds.Image; + +@:access(vision.algorithms.Sobel) +class SobelTests { + public static function vision_algorithms_Sobel__convolveWithSobelOperator_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.algorithms.Sobel.convolveWithSobelOperator(image); + + return { + testName: "vision.algorithms.Sobel.convolveWithSobelOperator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Sobel.convolveWithSobelOperator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_algorithms_Sobel__detectEdges_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var threshold = 0.0; + + var result = vision.algorithms.Sobel.detectEdges(image, threshold); + + return { + testName: "vision.algorithms.Sobel.detectEdges", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.algorithms.Sobel.detectEdges", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/TransformationMatrix2DTests.hx b/tests/generated/src/tests/TransformationMatrix2DTests.hx new file mode 100644 index 00000000..fb5f9937 --- /dev/null +++ b/tests/generated/src/tests/TransformationMatrix2DTests.hx @@ -0,0 +1,270 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.ds.TransformationMatrix2D; +import vision.ds.Matrix2D; +import vision.ds.Point3D; + +@:access(vision.ds.TransformationMatrix2D) +class TransformationMatrix2DTests { + public static function vision_ds_TransformationMatrix2D__underlying__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.underlying; + + return { + testName: "vision.ds.TransformationMatrix2D#underlying", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#underlying", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__a__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.a; + + return { + testName: "vision.ds.TransformationMatrix2D#a", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#a", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__b__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.b; + + return { + testName: "vision.ds.TransformationMatrix2D#b", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#b", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__c__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.c; + + return { + testName: "vision.ds.TransformationMatrix2D#c", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#c", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__d__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.d; + + return { + testName: "vision.ds.TransformationMatrix2D#d", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#d", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__e__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.e; + + return { + testName: "vision.ds.TransformationMatrix2D#e", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#e", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__f__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.f; + + return { + testName: "vision.ds.TransformationMatrix2D#f", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#f", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__tx__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.tx; + + return { + testName: "vision.ds.TransformationMatrix2D#tx", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#tx", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__ty__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.ty; + + return { + testName: "vision.ds.TransformationMatrix2D#ty", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#ty", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__transformPoint_Point3D_Point3D__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var point:Point3D = null; + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.transformPoint(point); + + return { + testName: "vision.ds.TransformationMatrix2D#transformPoint", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#transformPoint", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_ds_TransformationMatrix2D__transformPoint_Point2D_Point2D__ShouldWork():TestResult { + try { + var m:Matrix2D = null; + + var point = new vision.ds.Point2D(0, 0); + + var object = new vision.ds.TransformationMatrix2D(m); + var result = object.transformPoint(point); + + return { + testName: "vision.ds.TransformationMatrix2D#transformPoint", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.ds.TransformationMatrix2D#transformPoint", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/UInt16Point2DTests.hx b/tests/generated/src/tests/UInt16Point2DTests.hx new file mode 100644 index 00000000..8365c7a7 --- /dev/null +++ b/tests/generated/src/tests/UInt16Point2DTests.hx @@ -0,0 +1,162 @@ +package tests; + +import vision.ds.IntPoint2D; +import vision.ds.Point2D; +import TestResult; +import TestStatus; + +import vision.ds.UInt16Point2D; + + +@:access(vision.ds.UInt16Point2D) +class UInt16Point2DTests { + public static function vision_ds_UInt16Point2D__x__ShouldWork():TestResult { + try { + var X = 15; + var Y = 0; + + var object = new vision.ds.UInt16Point2D(X, Y); + var result = object.x; + + return { + testName: "vision.ds.UInt16Point2D#x", + returned: result, + expected: 15, + status: TestStatus.of(result == 15) + } + } catch (e) { + return { + testName: "vision.ds.UInt16Point2D#x", + returned: e, + expected: 15, + status: Failure + } + } + } + + public static function vision_ds_UInt16Point2D__y__ShouldWork():TestResult { + try { + var X = 0; + var Y = 87; + + var object = new vision.ds.UInt16Point2D(X, Y); + var result = object.y; + + return { + testName: "vision.ds.UInt16Point2D#y", + returned: result, + expected: 87, + status: TestStatus.of(result == 87) + } + } catch (e) { + return { + testName: "vision.ds.UInt16Point2D#y", + returned: e, + expected: 87, + status: Failure + } + } + } + + public static function vision_ds_UInt16Point2D__toString__String__ShouldWork():TestResult { + try { + var X = 12; + var Y = -1; + + + var object = new vision.ds.UInt16Point2D(X, Y); + var result = object.toString(); + + return { + testName: "vision.ds.UInt16Point2D#toString", + returned: result, + expected: "(12, 65535)", + status: TestStatus.of(result == "(12, 65535)") + } + } catch (e) { + return { + testName: "vision.ds.UInt16Point2D#toString", + returned: e, + expected: "(12, 65535)", + status: Failure + } + } + } + + public static function vision_ds_UInt16Point2D__toPoint2D__Point2D__ShouldWork():TestResult { + try { + var X = 5; + var Y = 7; + + + var object = new vision.ds.UInt16Point2D(X, Y); + var result = object.toPoint2D(); + + return { + testName: "vision.ds.UInt16Point2D#toPoint2D", + returned: result, + expected: new Point2D(5, 7), + status: TestStatus.of([result.x, result.y], [5, 7]) + } + } catch (e) { + return { + testName: "vision.ds.UInt16Point2D#toPoint2D", + returned: e, + expected: new Point2D(5, 7), + status: Failure + } + } + } + + public static function vision_ds_UInt16Point2D__toIntPoint2D__Point2D__ShouldWork():TestResult { + try { + var X = 6; + var Y = 6; + + + var object = new vision.ds.UInt16Point2D(X, Y); + var result = object.toIntPoint2D(); + + return { + testName: "vision.ds.UInt16Point2D#toIntPoint2D", + returned: result, + expected: new IntPoint2D(6, 6), + status: TestStatus.of([result.x, result.y], [6, 6]) + } + } catch (e) { + return { + testName: "vision.ds.UInt16Point2D#toIntPoint2D", + returned: e, + expected: new IntPoint2D(6, 6), + status: Failure + } + } + } + + public static function vision_ds_UInt16Point2D__toInt__Int__ShouldWork():TestResult { + try { + var X = 1; + var Y = 1; + + + var object = new vision.ds.UInt16Point2D(X, Y); + var result = object.toInt(); + + return { + testName: "vision.ds.UInt16Point2D#toInt", + returned: result, + expected: 0x00010001, + status: TestStatus.of(result == 0x00010001) + } + } catch (e) { + return { + testName: "vision.ds.UInt16Point2D#toInt", + returned: e, + expected: 0x00010001, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/VisionTests.hx b/tests/generated/src/tests/VisionTests.hx new file mode 100644 index 00000000..b08b63a5 --- /dev/null +++ b/tests/generated/src/tests/VisionTests.hx @@ -0,0 +1,1146 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.Vision; +import vision.algorithms.ImageHashing; +import vision.ds.ByteArray; +import vision.ds.kmeans.ColorCluster; +import haxe.io.Bytes; +import haxe.crypto.Sha256; +import vision.exceptions.Unimplemented; +import vision.ds.specifics.SimilarityScoringMechanism; +import vision.algorithms.KMeans; +import vision.ds.specifics.ColorChannel; +import vision.ds.TransformationMatrix2D; +import vision.ds.specifics.TransformationMatrixOrigination; +import vision.ds.Point3D; +import vision.ds.specifics.ImageExpansionMode; +import vision.algorithms.PerspectiveWarp; +import vision.ds.specifics.PointTransformationPair; +import vision.algorithms.BilinearInterpolation; +import vision.ds.Matrix2D; +import vision.ds.Int16Point2D; +import haxe.ds.Vector; +import vision.ds.specifics.WhiteNoiseRange; +import vision.algorithms.Laplace; +import vision.ds.specifics.ColorImportanceOrder; +import vision.algorithms.BilateralFilter; +import vision.algorithms.RobertsCross; +import vision.ds.IntPoint2D; +import haxe.extern.EitherType; +import vision.algorithms.Radix; +import haxe.ds.ArraySort; +import vision.ds.Histogram; +import vision.ds.specifics.AlgorithmSettings; +import vision.algorithms.Perwitt; +import vision.algorithms.Sobel; +import vision.ds.Kernel2D; +import vision.ds.canny.CannyObject; +import vision.algorithms.SimpleLineDetector; +import vision.ds.gaussian.GaussianKernelSize; +import vision.ds.Ray2D; +import vision.algorithms.Gauss; +import vision.ds.Point2D; +import vision.ds.Line2D; +import vision.ds.Color; +import vision.ds.Image; +import vision.tools.MathTools; +import vision.tools.MathTools.*; + +@:access(vision.Vision) +class VisionTests { + public static function vision_Vision__combine_Image_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var with = new vision.ds.Image(100, 100); + var percentage = 0.0; + + var result = vision.Vision.combine(image, with, percentage); + + return { + testName: "vision.Vision.combine", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.combine", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__tint_Image_Color_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var withColor:Color = null; + var percentage = 0.0; + + var result = vision.Vision.tint(image, withColor, percentage); + + return { + testName: "vision.Vision.tint", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.tint", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__grayscale_Image_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var simpleGrayscale = false; + + var result = vision.Vision.grayscale(image, simpleGrayscale); + + return { + testName: "vision.Vision.grayscale", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.grayscale", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__invert_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.Vision.invert(image); + + return { + testName: "vision.Vision.invert", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.invert", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__sepia_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var strength = 0.0; + + var result = vision.Vision.sepia(image, strength); + + return { + testName: "vision.Vision.sepia", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.sepia", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__blackAndWhite_Image_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var threshold = 0; + + var result = vision.Vision.blackAndWhite(image, threshold); + + return { + testName: "vision.Vision.blackAndWhite", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.blackAndWhite", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__contrast_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.Vision.contrast(image); + + return { + testName: "vision.Vision.contrast", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.contrast", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__smooth_Image_Float_Bool_Int_Bool_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var strength = 0.0; + var affectAlpha = false; + var kernelRadius = 0; + var circularKernel = false; + var iterations = 0; + + var result = vision.Vision.smooth(image, strength, affectAlpha, kernelRadius, circularKernel, iterations); + + return { + testName: "vision.Vision.smooth", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.smooth", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__pixelate_Image_Bool_Int_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var averagePixels = false; + var pixelSize = 0; + var affectAlpha = false; + + var result = vision.Vision.pixelate(image, averagePixels, pixelSize, affectAlpha); + + return { + testName: "vision.Vision.pixelate", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.pixelate", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__posterize_Image_Int_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var bitsPerChannel = 0; + var affectAlpha = false; + + var result = vision.Vision.posterize(image, bitsPerChannel, affectAlpha); + + return { + testName: "vision.Vision.posterize", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.posterize", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__sharpen_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.Vision.sharpen(image); + + return { + testName: "vision.Vision.sharpen", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.sharpen", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__deepfry_Image_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var iterations = 0; + + var result = vision.Vision.deepfry(image, iterations); + + return { + testName: "vision.Vision.deepfry", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.deepfry", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__vignette_Image_Float_Float_Bool_Color_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var strength = 0.0; + var intensity = 0.0; + var ratioDependent = false; + var color:Color = null; + + var result = vision.Vision.vignette(image, strength, intensity, ratioDependent, color); + + return { + testName: "vision.Vision.vignette", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.vignette", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__fisheyeDistortion_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var strength = 0.0; + + var result = vision.Vision.fisheyeDistortion(image, strength); + + return { + testName: "vision.Vision.fisheyeDistortion", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.fisheyeDistortion", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__barrelDistortion_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var strength = 0.0; + + var result = vision.Vision.barrelDistortion(image, strength); + + return { + testName: "vision.Vision.barrelDistortion", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.barrelDistortion", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__pincushionDistortion_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var strength = 0.0; + + var result = vision.Vision.pincushionDistortion(image, strength); + + return { + testName: "vision.Vision.pincushionDistortion", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.pincushionDistortion", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__mustacheDistortion_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var amplitude = 0.0; + + var result = vision.Vision.mustacheDistortion(image, amplitude); + + return { + testName: "vision.Vision.mustacheDistortion", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.mustacheDistortion", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__dilate_Image_Int_ColorImportanceOrder_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var dilationRadius = 0; + var colorImportanceOrder:ColorImportanceOrder = null; + var circularKernel = false; + + var result = vision.Vision.dilate(image, dilationRadius, colorImportanceOrder, circularKernel); + + return { + testName: "vision.Vision.dilate", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.dilate", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__erode_Image_Int_ColorImportanceOrder_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var erosionRadius = 0; + var colorImportanceOrder:ColorImportanceOrder = null; + var circularKernel = false; + + var result = vision.Vision.erode(image, erosionRadius, colorImportanceOrder, circularKernel); + + return { + testName: "vision.Vision.erode", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.erode", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__saltAndPepperNoise_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var percentage = 0.0; + + var result = vision.Vision.saltAndPepperNoise(image, percentage); + + return { + testName: "vision.Vision.saltAndPepperNoise", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.saltAndPepperNoise", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__dropOutNoise_Image_Float_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var percentage = 0.0; + var threshold = 0; + + var result = vision.Vision.dropOutNoise(image, percentage, threshold); + + return { + testName: "vision.Vision.dropOutNoise", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.dropOutNoise", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__whiteNoise_Image_Float_WhiteNoiseRange_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var percentage = 0.0; + var whiteNoiseRange:WhiteNoiseRange = null; + + var result = vision.Vision.whiteNoise(image, percentage, whiteNoiseRange); + + return { + testName: "vision.Vision.whiteNoise", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.whiteNoise", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__normalize_Image_Color_Color_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var rangeStart:Color = null; + var rangeEnd:Color = null; + + var result = vision.Vision.normalize(image, rangeStart, rangeEnd); + + return { + testName: "vision.Vision.normalize", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.normalize", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__limitColorRanges_Image_Color_Color_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var rangeStart:Color = null; + var rangeEnd:Color = null; + + var result = vision.Vision.limitColorRanges(image, rangeStart, rangeEnd); + + return { + testName: "vision.Vision.limitColorRanges", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.limitColorRanges", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__replaceColorRanges_Image_ArrayrangeStartColorrangeEndColorreplacementColor_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var ranges = []; + + var result = vision.Vision.replaceColorRanges(image, ranges); + + return { + testName: "vision.Vision.replaceColorRanges", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.replaceColorRanges", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__filterForColorChannel_Image_ColorChannel_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var channel:ColorChannel = null; + + var result = vision.Vision.filterForColorChannel(image, channel); + + return { + testName: "vision.Vision.filterForColorChannel", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.filterForColorChannel", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__convolve_Image_EitherTypeKernel2DArrayArrayFloat_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var kernel:EitherType>> = null; + + var result = vision.Vision.convolve(image, kernel); + + return { + testName: "vision.Vision.convolve", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.convolve", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__affineTransform_Image_TransformationMatrix2D_ImageExpansionMode_Point2D_TransformationMatrixOrigination_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var matrix:TransformationMatrix2D = null; + var expansionMode:ImageExpansionMode = null; + var originPoint = new vision.ds.Point2D(0, 0); + var originMode:TransformationMatrixOrigination = null; + + var result = vision.Vision.affineTransform(image, matrix, expansionMode, originPoint, originMode); + + return { + testName: "vision.Vision.affineTransform", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.affineTransform", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__projectiveTransform_Image_TransformationMatrix2D_ImageExpansionMode_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var matrix:TransformationMatrix2D = null; + var expansionMode:ImageExpansionMode = null; + + var result = vision.Vision.projectiveTransform(image, matrix, expansionMode); + + return { + testName: "vision.Vision.projectiveTransform", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.projectiveTransform", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__nearestNeighborBlur_Image_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var iterations = 0; + + var result = vision.Vision.nearestNeighborBlur(image, iterations); + + return { + testName: "vision.Vision.nearestNeighborBlur", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.nearestNeighborBlur", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__gaussianBlur_Image_Float_GaussianKernelSize_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var sigma = 0.0; + var kernelSize:GaussianKernelSize = null; + var fast = false; + + var result = vision.Vision.gaussianBlur(image, sigma, kernelSize, fast); + + return { + testName: "vision.Vision.gaussianBlur", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.gaussianBlur", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__medianBlur_Image_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var kernelSize = 0; + + var result = vision.Vision.medianBlur(image, kernelSize); + + return { + testName: "vision.Vision.medianBlur", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.medianBlur", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__simpleLine2DDetection_Image_Float_Float_AlgorithmSettings_ArrayLine2D__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var accuracy = 0.0; + var minLineLength = 0.0; + var speedToAccuracyRatio:AlgorithmSettings = null; + + var result = vision.Vision.simpleLine2DDetection(image, accuracy, minLineLength, speedToAccuracyRatio); + + return { + testName: "vision.Vision.simpleLine2DDetection", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.simpleLine2DDetection", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__sobelEdgeDiffOperator_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.Vision.sobelEdgeDiffOperator(image); + + return { + testName: "vision.Vision.sobelEdgeDiffOperator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.sobelEdgeDiffOperator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__perwittEdgeDiffOperator_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.Vision.perwittEdgeDiffOperator(image); + + return { + testName: "vision.Vision.perwittEdgeDiffOperator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.perwittEdgeDiffOperator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__robertEdgeDiffOperator_Image_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + + var result = vision.Vision.robertEdgeDiffOperator(image); + + return { + testName: "vision.Vision.robertEdgeDiffOperator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.robertEdgeDiffOperator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__laplacianEdgeDiffOperator_Image_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var filterPositive = false; + + var result = vision.Vision.laplacianEdgeDiffOperator(image, filterPositive); + + return { + testName: "vision.Vision.laplacianEdgeDiffOperator", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.laplacianEdgeDiffOperator", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__cannyEdgeDetection_Image_Float_GaussianKernelSize_Float_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var sigma = 0.0; + var kernelSize:GaussianKernelSize = null; + var lowThreshold = 0.0; + var highThreshold = 0.0; + + var result = vision.Vision.cannyEdgeDetection(image, sigma, kernelSize, lowThreshold, highThreshold); + + return { + testName: "vision.Vision.cannyEdgeDetection", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.cannyEdgeDetection", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__sobelEdgeDetection_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var threshold = 0.0; + + var result = vision.Vision.sobelEdgeDetection(image, threshold); + + return { + testName: "vision.Vision.sobelEdgeDetection", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.sobelEdgeDetection", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__perwittEdgeDetection_Image_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var threshold = 0.0; + + var result = vision.Vision.perwittEdgeDetection(image, threshold); + + return { + testName: "vision.Vision.perwittEdgeDetection", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.perwittEdgeDetection", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__laplacianOfGaussianEdgeDetection_Image_Int_Bool_Float_GaussianKernelSize_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var threshold = 0; + var filterPositive = false; + var sigma = 0.0; + var kernelSize:GaussianKernelSize = null; + + var result = vision.Vision.laplacianOfGaussianEdgeDetection(image, threshold, filterPositive, sigma, kernelSize); + + return { + testName: "vision.Vision.laplacianOfGaussianEdgeDetection", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.laplacianOfGaussianEdgeDetection", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__convolutionRidgeDetection_Image_Color_Color_Bool_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var normalizationRangeStart:Color = null; + var normalizationRangeEnd:Color = null; + var refine = false; + + var result = vision.Vision.convolutionRidgeDetection(image, normalizationRangeStart, normalizationRangeEnd, refine); + + return { + testName: "vision.Vision.convolutionRidgeDetection", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.convolutionRidgeDetection", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__bilateralDenoise_Image_Float_Float_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var gaussianSigma = 0.0; + var intensitySigma = 0.0; + + var result = vision.Vision.bilateralDenoise(image, gaussianSigma, intensitySigma); + + return { + testName: "vision.Vision.bilateralDenoise", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.bilateralDenoise", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__simpleImageSimilarity_Image_Image_SimilarityScoringMechanism_Float__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var compared = new vision.ds.Image(100, 100); + var scoringMechanism:SimilarityScoringMechanism = null; + + var result = vision.Vision.simpleImageSimilarity(image, compared, scoringMechanism); + + return { + testName: "vision.Vision.simpleImageSimilarity", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.simpleImageSimilarity", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__kmeansPosterize_Image_Int_Image__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var maxColorCount = 0; + + var result = vision.Vision.kmeansPosterize(image, maxColorCount); + + return { + testName: "vision.Vision.kmeansPosterize", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.kmeansPosterize", + returned: e, + expected: null, + status: Failure + } + } + } + + public static function vision_Vision__kmeansGroupImageColors_Image_Int_Bool_ArrayColorCluster__ShouldWork():TestResult { + try { + var image = new vision.ds.Image(100, 100); + var groupCount = 0; + var considerTransparency = false; + + var result = vision.Vision.kmeansGroupImageColors(image, groupCount, considerTransparency); + + return { + testName: "vision.Vision.kmeansGroupImageColors", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.Vision.kmeansGroupImageColors", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generated/src/tests/VisionThreadTests.hx b/tests/generated/src/tests/VisionThreadTests.hx new file mode 100644 index 00000000..f322901e --- /dev/null +++ b/tests/generated/src/tests/VisionThreadTests.hx @@ -0,0 +1,35 @@ +package tests; + +import TestResult; +import TestStatus; + +import vision.helpers.VisionThread; +import vision.exceptions.MultithreadFailure; +import haxe.Exception; + +@:access(vision.helpers.VisionThread) +class VisionThreadTests { + public static function vision_helpers_VisionThread__create_VoidVoid_VisionThread__ShouldWork():TestResult { + try { + var job = () -> return; + + var result = vision.helpers.VisionThread.create(job); + + return { + testName: "vision.helpers.VisionThread.create", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "vision.helpers.VisionThread.create", + returned: e, + expected: null, + status: Failure + } + } + } + + +} \ No newline at end of file diff --git a/tests/generator/Config.hx b/tests/generator/Config.hx new file mode 100644 index 00000000..686601bd --- /dev/null +++ b/tests/generator/Config.hx @@ -0,0 +1,14 @@ +package; + +class Config { + macro public static function load(path:String) { + // Register a dependency to the external file so the Haxe compilation cache is invalidated if the file changes. + haxe.macro.Context.registerModuleDependency(haxe.macro.Context.getLocalModule(), path); + return try { + var json = haxe.Json.parse(sys.io.File.getContent(path)); + macro $v{json}; + } catch (e) { + haxe.macro.Context.error('Failed to load json: $e', haxe.macro.Context.currentPos()); + } + } +} diff --git a/tests/generator/Detector.hx b/tests/generator/Detector.hx new file mode 100644 index 00000000..1b762981 --- /dev/null +++ b/tests/generator/Detector.hx @@ -0,0 +1,136 @@ +package; + +import sys.io.File; +import sys.FileSystem; + +using StringTools; + +class Detector { + static var packageFinder = ~/^package ([\w.]+)/m; + static var importFinder = ~/^import ([\w.*]+)/m; + static var classNameFinder = ~/^(?:class|abstract) (\w+)/m; + static var staticFunctionFinder = ~/public static (?:inline )?function (\w+)(?:)?\((.*)\)(:.+\s*|\s*)\{/m; + static var staticFieldFinder = ~/public static (?:inline )?(?:var|final) (\w+)\(get, \w+\)/m; + static var instanceFieldFinder = ~/public (?:inline )?(?:var|final) (\w+)\(get, \w+\)/m; + static var instanceFunctionFinder = ~/public (?:inline )?function (\w+)(?:)?\((.*)\)(:.+\s*|\s*)\{/m; + static var constructorFinder = ~/function new\s*\((.*)\)/; + static var targetSpecificZoneFinder = ~/\t?#if .+?\n.+?\t?#end/gs; + static var endOfMainClassFinder = ~/\n}/; + static var commentFinder = ~/\/\/.+/g; + + public static function detectOnFile(pathToHaxeFile:String):TestDetections { + var pathToHaxeFile = FileSystem.absolutePath(pathToHaxeFile); + var fileContent = File.getContent(pathToHaxeFile), + originalFileContent = fileContent; + + packageFinder.match(fileContent); + var packageName = packageFinder.matched(1); + fileContent = packageFinder.matchedRight(); + + fileContent = targetSpecificZoneFinder.replace(fileContent, ""); + fileContent = commentFinder.replace(fileContent, ""); + + var imports = []; + while (importFinder.match(fileContent)) { + var classPath = importFinder.matched(1); + fileContent = importFinder.matchedRight(); + imports.push(classPath); + } + + if (!classNameFinder.match(fileContent)) { + return null; + } + + + var className = classNameFinder.matched(1); + fileContent = classNameFinder.matchedRight(); + + if (endOfMainClassFinder.match(fileContent)) { + fileContent = endOfMainClassFinder.matchedLeft(); + } + + originalFileContent = fileContent; + + var staticFunctions = new Map<{name:String, type:String}, String>(); + while (staticFunctionFinder.match(fileContent)) { + var functionName = staticFunctionFinder.matched(1); + var functionParameters = staticFunctionFinder.matched(2); + var functionReturnType = staticFunctionFinder.matched(3).trim(); + if (functionReturnType == "") functionReturnType = "Void"; + + fileContent = staticFunctionFinder.matchedRight(); + + staticFunctions.set({name: functionName, type: functionReturnType}, functionParameters); + } + + fileContent = originalFileContent; + + var staticFields = []; + while (staticFieldFinder.match(fileContent)) { + var fieldName = staticFieldFinder.matched(1); + fileContent = staticFieldFinder.matchedRight(); + + staticFields.push(fieldName); + } + + fileContent = originalFileContent; + + var instanceFunctions = new Map<{name:String, type:String}, String>(); + + while (instanceFunctionFinder.match(fileContent)) { + var functionName = instanceFunctionFinder.matched(1); + var functionParameters = instanceFunctionFinder.matched(2); + var functionReturnType = instanceFunctionFinder.matched(3).trim(); + if (functionReturnType == "") functionReturnType = "Void"; + + fileContent = instanceFunctionFinder.matchedRight(); + + if (functionName == "new") { + continue; + } + + instanceFunctions.set({name: functionName, type: functionReturnType}, functionParameters); + } + + fileContent = originalFileContent; + + var instanceFields = []; + while (instanceFieldFinder.match(fileContent)) { + var fieldName = instanceFieldFinder.matched(1); + fileContent = instanceFieldFinder.matchedRight(); + + instanceFields.push(fieldName); + } + + fileContent = originalFileContent; + + var constructorParameters = []; + while (constructorFinder.match(fileContent)) { + var parameters = constructorFinder.matched(1); + fileContent = constructorFinder.matchedRight(); + constructorParameters.push(parameters); + } + + return { + packageName: packageName, + imports: imports, + className: className, + staticFunctions: staticFunctions, + staticFields: staticFields, + instanceFunctions: instanceFunctions, + instanceFields: instanceFields, + constructorParameters: constructorParameters + } + } +} + +typedef TestDetections = { + packageName:String, + imports:Array, + className:String, + constructorParameters:Array, + staticFunctions:Map<{name:String, type:String}, String>, + staticFields:Array, + instanceFunctions:Map<{name:String, type:String}, String>, + instanceFields:Array +} diff --git a/tests/generator/Generator.hx b/tests/generator/Generator.hx new file mode 100644 index 00000000..45618bbf --- /dev/null +++ b/tests/generator/Generator.hx @@ -0,0 +1,214 @@ +package; + +import vision.tools.ArrayTools; +import Detector.TestDetections; +import sys.FileSystem; +import sys.io.File; + +using StringTools; + +class Generator { + + + public static var instanceFunctionTemplate = File.getContent(FileSystem.absolutePath("generator/templates/InstanceFunctionTestTemplate.hx")); + public static var instanceFieldTemplate = File.getContent(FileSystem.absolutePath("generator/templates/InstanceFieldTestTemplate.hx")); + + public static var staticFunctionTemplate = File.getContent(FileSystem.absolutePath("generator/templates/StaticFunctionTestTemplate.hx")); + public static var staticFieldTemplate = File.getContent(FileSystem.absolutePath("generator/templates/StaticFieldTestTemplate.hx")); + + public static var testClassActuatorTemplate = File.getContent(FileSystem.absolutePath("generator/templates/TestClassActuator.hx")); + public static var testClassHeaderTemplate = File.getContent(FileSystem.absolutePath("generator/templates/TestClassHeader.hx")); + + public static function generateFromFile(pathToHaxeFile:String, pathToOutputFile:String):Bool { + var detections = Detector.detectOnFile(pathToHaxeFile); + if (detections == null) { + Sys.println('INFO: No tests could be generated for $pathToHaxeFile'); + return false; + } + var file = File.write(FileSystem.absolutePath(pathToOutputFile)); + + file.writeString(generateFileHeader(detections.packageName, detections.className, detections.imports)); + + for (field in detections.staticFields) { + file.writeString(generateTest(staticFieldTemplate, { + packageName: detections.packageName, + className: detections.className, + fieldName: field, + fieldType: "", + testGoal: "ShouldWork", + parameters: extractParameters(""), + constructorParameters: extractParameters(""), + + })); + } + + for (field in detections.instanceFields) { + file.writeString(generateTest(instanceFieldTemplate, { + packageName: detections.packageName, + className: detections.className, + fieldName: field, + fieldType: "", + testGoal: "ShouldWork", + parameters: extractParameters(""), + constructorParameters: extractParameters(detections.constructorParameters[0] ?? "") + })); + } + + for (method => parameters in detections.staticFunctions) { + file.writeString(generateTest(staticFunctionTemplate, { + packageName: detections.packageName, + className: detections.className, + fieldName: method.name, + fieldType: method.type, + testGoal: "ShouldWork", + parameters: extractParameters(parameters), + constructorParameters: extractParameters("") + })); + } + + for (method => parameters in detections.instanceFunctions) { + file.writeString(generateTest(instanceFunctionTemplate, { + packageName: detections.packageName, + className: detections.className, + fieldName: method.name, + fieldType: method.type, + testGoal: "ShouldWork", + parameters: extractParameters(parameters), + constructorParameters: extractParameters(detections.constructorParameters[0] ?? "") + })); + } + + // file.writeString(generateConstructor(detections)); + + file.writeString(generateFileFooter()); + + file.close(); + + return true; + } + + static function generateFileHeader(packageName:String, className:String, imports:Array):String { + return testClassHeaderTemplate + .replace("CLASS_NAME", className) + .replace("PACKAGE_NAME", packageName) + .replace("ADDITIONAL_IMPORTS", imports.map(classPath -> 'import $classPath;').join("\n")); + } + + static function generateFileFooter() { + return '\n}'; + } + + static function generateTest(template:String, testBase:TestBase):String { + var cleanPackage = testBase.packageName.replace(".", "_") + '_${testBase.className}'; + if (testBase.fieldType == "Void") { + template = template.replace("var result = ", "").replace("returned: result", "returned: null"); + } else if (testBase.fieldType != "") { + template = template.replace("X2__", 'X2_${~/[^a-zA-Z0-9_]/g.replace('${testBase.parameters.types}_${testBase.fieldType}', "")}__'); + } + if (hasSpecialConstructor(testBase.className)) { + template = template.replace("new X4(X6)", generateSpecialConstructorFor(testBase.className, testBase.parameters.injection)); + } + return template + .replace("X1", cleanPackage) + .replace("X2", testBase.fieldName) + .replace("X3", testBase.testGoal) + .replace("X4", '${testBase.packageName}.${testBase.className}') + .replace("X5", testBase.parameters.injection) + .replace("X6", testBase.constructorParameters.injection) + .replace("X7", testBase.parameters.declarations) + .replace("X8", testBase.constructorParameters.declarations) + "\n\n"; + + } + + static function generateConstructor(detections:TestDetections) { + var cleanPackage = detections.packageName.replace(".", "_") + '_${detections.className}'; + var functionNames = []; + for (method in detections.staticFunctions.keys()) { + functionNames.push('${cleanPackage}__${method}__ShouldWork'); + } + for (method in detections.instanceFunctions.keys()) { + functionNames.push('${cleanPackage}__${method}__ShouldWork'); + } + for (field in detections.staticFields) { + functionNames.push('${cleanPackage}__${field}__ShouldWork'); + } + for (field in detections.instanceFields) { + functionNames.push('${cleanPackage}__${field}__ShouldWork'); + } + + functionNames = functionNames.map(x -> '\n\t\t$x'); + + return testClassActuatorTemplate.replace("TEST_ARRAY", functionNames.join(", ")); + } + + + static function extractParameters(parameters:String):{declarations:String, injection:String, types:String} { + if (parameters.contains("average")) { + trace(parameters); + } + var regex = ~/(\w+):((?:\(.+?\)\s*->\s*\w+)|(?:\w+(?:<\w+>)?\s*->\s*\w+)|(?:(?:EitherType|Map)<.+, .+>)|(?:\w+(?:<\{.+\}>|<\w+>))|(?:\w|\.)+|\{.+\}),?/; + var output = {declarations: "", injection: [], types: []} + while (regex.match(parameters)) { + var name = regex.matched(1); + var type = regex.matched(2); + parameters = regex.matchedRight(); + output.declarations += 'var $name${getDefaultValueOf(type) == "null" ? ':$type' : ""} = ${getDefaultValueOf(type)};\n\t\t\t'; + output.injection.push(name); + output.types.push(type); + } + + return { + declarations: output.declarations, + injection: output.injection.join(", "), + types: output.types.join("_") + }; + } + + static function getDefaultValueOf(valueType:String):String { + return switch valueType { + case "String": '""'; + case "Int": "0"; + case "Float": "0.0"; + case "Bool": "false"; + case "() -> Void" | "Void->Void": "() -> return"; + case "Array->T": "(_) -> null"; + case (_.contains("->") => true): + var commas = valueType.split("->")[0].split(",").length; + '(${[for (i in 0...commas) "_"].join(", ")}) -> null'; + case (_.startsWith("Array") || _.startsWith("Map") => true): "[]"; + case "Point2D" | "IntPoint2D" | "Int16Point2D" | "UInt16Point2D": 'new vision.ds.$valueType(0, 0)'; + case "Line2D": 'new vision.ds.Line2D({x: 0, y: 0}, {x: 10, y: 10})'; + case "Ray2D": 'new vision.ds.Ray2D({x: 0, y: 0}, 1)'; + case "ByteArray": 'vision.ds.ByteArray.from(0)'; + case "Image": 'new vision.ds.Image(100, 100)'; + case "T": "0"; // A little insane but should work in most cases so idk + case (_.startsWith("T") && _.contains("->") => true): "(_) -> null"; + case "QueueCell": "new vision.ds.QueueCell(0, null, null)"; + default: "null"; + } + } + + static function hasSpecialConstructor(className:String):Bool { + return switch className { + case "ImageView": true; + default: false; + } + } + + static function generateSpecialConstructorFor(className:String, parameterInjection:String):String { + return switch className { + case "ImageView": '({} : ImageView)'; + default: "new X4(X6)"; + } + } +} + +typedef TestBase = { + packageName:String, + className:String, + fieldName:String, + testGoal:String, + ?parameters:{declarations:String, injection:String, types:String}, + ?constructorParameters:{declarations:String, injection:String, types:String}, + fieldType:String +} \ No newline at end of file diff --git a/tests/generator/Main.hx b/tests/generator/Main.hx new file mode 100644 index 00000000..f6561c96 --- /dev/null +++ b/tests/generator/Main.hx @@ -0,0 +1,77 @@ +package; + +import vision.ds.IntPoint2D; +import vision.ds.Array2D; +import vision.tools.ImageTools; +import sys.io.File; +import sys.FileSystem; + +using StringTools; + +class Main { + + static function main() { + var config = Config.load("config.json"); + var files = []; + if (config.regenerateAll) { + files = readFileStructure(FileSystem.absolutePath(config.source)); + } + + var source = FileSystem.absolutePath(config.source); + var destination = FileSystem.absolutePath(config.destination); + + var resultingClassArray = []; + + for (file in files) { + if (file.endsWith(".js.hx")) { + Sys.println('Skipping: $file: $file is a js interface file'); + continue; + } + var shouldSkip = false; + for (exclude in config.exclude) { + trace(file, exclude); + if (file.contains(exclude)) { + Sys.println('Skipping: $file: $file contains `$exclude`'); + shouldSkip = true; + break; + } + } + if (shouldSkip) { + continue; + } + + var outputFile = destination + "/" + file.split("/").pop().replace(".hx", "Tests.hx"); + if (!config.overwrite && FileSystem.exists(outputFile)) { + Sys.println('Skipping: $file: $outputFile already exists'); + } else { + Sys.println('Generating: $file -> $outputFile'); + if (!Generator.generateFromFile(file, outputFile)) { + continue; + } + } + + resultingClassArray.push(outputFile.split("/").pop().replace(".hx", "")); + } + + Sys.println("Job Done! Use this array to test the classes:"); + Sys.println(' [${resultingClassArray.join(", ")}]'); + if (config.testsToRunFile.length > 0) { + Sys.println("Found tests-to-run file! writing test cases there as well..."); + File.saveContent(FileSystem.absolutePath(config.testsToRunFile), 'package;\n\nimport tests.*;\n\nfinal tests:Array> = [\n\t${resultingClassArray.join(", \n\t")}\n];'); + } + } + + static function readFileStructure(from:String):Array { + var files = FileSystem.readDirectory(from); + var result = []; + for (file in files) { + var path = from + "/" + file; + if (FileSystem.isDirectory(path)) { + result = result.concat(readFileStructure(path)); + } else { + result.push(path); + } + } + return result; + } +} \ No newline at end of file diff --git a/tests/generator/templates/InstanceFieldTestTemplate.hx b/tests/generator/templates/InstanceFieldTestTemplate.hx new file mode 100644 index 00000000..b077f6a9 --- /dev/null +++ b/tests/generator/templates/InstanceFieldTestTemplate.hx @@ -0,0 +1,21 @@ + public static function X1__X2__X3():TestResult { + try { + X8 + var object = new X4(X6); + var result = object.X2; + + return { + testName: "X4#X2", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "X4#X2", + returned: e, + expected: null, + status: Failure + } + } + } \ No newline at end of file diff --git a/tests/generator/templates/InstanceFunctionTestTemplate.hx b/tests/generator/templates/InstanceFunctionTestTemplate.hx new file mode 100644 index 00000000..b786867f --- /dev/null +++ b/tests/generator/templates/InstanceFunctionTestTemplate.hx @@ -0,0 +1,22 @@ + public static function X1__X2__X3():TestResult { + try { + X8 + X7 + var object = new X4(X6); + var result = object.X2(X5); + + return { + testName: "X4#X2", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "X4#X2", + returned: e, + expected: null, + status: Failure + } + } + } \ No newline at end of file diff --git a/tests/generator/templates/StaticFieldTestTemplate.hx b/tests/generator/templates/StaticFieldTestTemplate.hx new file mode 100644 index 00000000..21cbb6d8 --- /dev/null +++ b/tests/generator/templates/StaticFieldTestTemplate.hx @@ -0,0 +1,19 @@ + public static function X1__X2__X3():TestResult { + try { + var result = X4.X2; + + return { + testName: "X4.X2", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "X4.X2", + returned: e, + expected: null, + status: Failure + } + } + } \ No newline at end of file diff --git a/tests/generator/templates/StaticFunctionTestTemplate.hx b/tests/generator/templates/StaticFunctionTestTemplate.hx new file mode 100644 index 00000000..e4b5298d --- /dev/null +++ b/tests/generator/templates/StaticFunctionTestTemplate.hx @@ -0,0 +1,20 @@ + public static function X1__X2__X3():TestResult { + try { + X7 + var result = X4.X2(X5); + + return { + testName: "X4.X2", + returned: result, + expected: null, + status: Unimplemented + } + } catch (e) { + return { + testName: "X4.X2", + returned: e, + expected: null, + status: Failure + } + } + } \ No newline at end of file diff --git a/tests/generator/templates/TestClassActuator.hx b/tests/generator/templates/TestClassActuator.hx new file mode 100644 index 00000000..5d9e77f4 --- /dev/null +++ b/tests/generator/templates/TestClassActuator.hx @@ -0,0 +1 @@ + public static var tests = [TEST_ARRAY]; \ No newline at end of file diff --git a/tests/generator/templates/TestClassHeader.hx b/tests/generator/templates/TestClassHeader.hx new file mode 100644 index 00000000..3c645029 --- /dev/null +++ b/tests/generator/templates/TestClassHeader.hx @@ -0,0 +1,10 @@ +package tests; + +import TestResult; +import TestStatus; + +import PACKAGE_NAME.CLASS_NAME; +ADDITIONAL_IMPORTS + +@:access(PACKAGE_NAME.CLASS_NAME) +class CLASS_NAMETests { diff --git a/tests/generator/templates/doc.hx b/tests/generator/templates/doc.hx new file mode 100644 index 00000000..7efbd7df --- /dev/null +++ b/tests/generator/templates/doc.hx @@ -0,0 +1,13 @@ +package templates; + +/** + `X1` - package name + class name, with underscores instead of `.` + `X2` - field name to test + `X3` - test goal. Usually starts with "ShouldBe" or "ShouldEqual". + `X4` - class name, including full package, for example: `my.example.ClassInstance` + `X5` - optional - parameter list for when we test a function + `X6` - optional - parameter list for when we test a constructor + `X7` - optional - when providing `X5`, an instantiation of said params + `X8` - optional - when providing `X6`, an instantiation of said params +**/ +public var doc:String; diff --git a/tests/generator/testing/TestResult.hx b/tests/generator/testing/TestResult.hx new file mode 100644 index 00000000..777e4668 --- /dev/null +++ b/tests/generator/testing/TestResult.hx @@ -0,0 +1,8 @@ +package testing; + +typedef TestResult = { + testName:String, + result: Dynamic, + expected: Dynamic, + success:Bool +} \ No newline at end of file diff --git a/tests/tests.hxml b/tests/tests.hxml new file mode 100644 index 00000000..dbe3da2b --- /dev/null +++ b/tests/tests.hxml @@ -0,0 +1,9 @@ +--cwd generated +--class-path src +--main Main +--library vision +--library format + +-w -WDeprecated + +--interp \ No newline at end of file