001    /*
002     * DiamondSpotFunction
003     * 
004     * Copyright (c) 2002, 2003 Marco Schmidt.
005     * All rights reserved.
006     */
007    
008    package net.sourceforge.jiu.color.dithering;
009    
010    import net.sourceforge.jiu.color.dithering.SpotFunction;
011    
012    /**
013     * A diamond spot function.
014     * @author Marco Schmidt
015     * @since 0.9.0
016     * @see ClusteredDotDither
017     */
018    public class DiamondSpotFunction implements SpotFunction
019    {
020            public double compute(double x, double y)
021            {
022                    double xy = Math.abs(x) + Math.abs(y);
023                    if (xy <= 1)
024                    {
025                            return 0.5 * xy * xy;
026                    }
027                    else
028                    {
029                            double xy1 = xy - 1;
030                            return (2 * xy * xy - 4 * xy1 * xy1) / 4;
031                    }
032            }
033    
034            public boolean isBalanced()
035            {
036                    return false;
037            }
038    }