'Returns an XYPoint object containing the closest available CIE 1931 coordinates
based on the RGB input values.'

def getXYPointFromRGB(self, red, green, blue):

    r = ((((red + 0.055) / (1.0 + 0.055)) ** 2.4) if (red > 0.04045) else (red / 12.92))
    g = ((((green + 0.055) / (1.0 + 0.055)) ** 2.4) if (green > 0.04045) else (green / 12.92))
    b = ((((blue + 0.055) / (1.0 + 0.055)) ** 2.4) if (blue > 0.04045) else (blue / 12.92))
    X = (((r * 0.4360747) + (g * 0.3850649)) + (b * 0.0930804))
    Y = (((r * 0.2225045) + (g * 0.7168786)) + (b * 0.0406169))
    Z = (((r * 0.0139322) + (g * 0.0971045)) + (b * 0.7141733))
    cx = (X / ((X + Y) + Z))
    cy = (Y / ((X + Y) + Z))
    xyPoint = XYPoint(cx, cy)
    inReachOfLamps = self.checkPointInLampsReach(xyPoint)
    if (not inReachOfLamps):
        pAB = self.getClosestPointToPoint(self.Red, self.Lime, xyPoint)
        pAC = self.getClosestPointToPoint(self.Blue, self.Red, xyPoint)
        pBC = self.getClosestPointToPoint(self.Lime, self.Blue, xyPoint)
        dAB = self.getDistanceBetweenTwoPoints(xyPoint, pAB)
        dAC = self.getDistanceBetweenTwoPoints(xyPoint, pAC)
        dBC = self.getDistanceBetweenTwoPoints(xyPoint, pBC)
        lowest = dAB
        closestPoint = pAB
        if (dAC < lowest):
            lowest = dAC
            closestPoint = pAC
        if (dBC < lowest):
            lowest = dBC
            closestPoint = pBC
        cx = closestPoint.x
        cy = closestPoint.y
    return XYPoint(cx, cy)
